47 lines
1.4 KiB
C#
47 lines
1.4 KiB
C#
using System;
|
|
using Drab.LocalDb;
|
|
using Drab.LocalDb.Entities;
|
|
using Drab.Logic.Dtos;
|
|
using Drab.Logic.Interfaces;
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
using NLog;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace Drab.Logic.Services;
|
|
|
|
public class LocalOrderStore : ILocalOrderStore
|
|
{
|
|
|
|
private readonly ILogger _logger;
|
|
private readonly IServiceScopeFactory _serviceScopeFactory;
|
|
|
|
public LocalOrderStore(IServiceScopeFactory serviceScopeFactory)
|
|
{
|
|
_logger = LogManager.GetCurrentClassLogger();
|
|
_serviceScopeFactory = serviceScopeFactory;
|
|
}
|
|
|
|
public async Task<List<OrderDb>> GetAll()
|
|
{
|
|
using var scope = _serviceScopeFactory.CreateScope();
|
|
await using var dbContext = scope.ServiceProvider.GetService<LocalDbContext>();
|
|
var fromDate = DateTime.UtcNow.AddDays(-30);
|
|
|
|
var orders = dbContext.Orders
|
|
.Where(x => x.Created >= fromDate)
|
|
.OrderByDescending(x => x.Created)
|
|
.ToList();
|
|
return orders;
|
|
}
|
|
|
|
public async Task<DokDto> GetOrderById(long dokId)
|
|
{
|
|
using var scope = _serviceScopeFactory.CreateScope();
|
|
await using var dbContext = scope.ServiceProvider.GetService<LocalDbContext>();
|
|
var order = dbContext.Orders.FirstOrDefault(x => x.DokId == dokId);
|
|
|
|
return new DokDto();
|
|
}
|
|
} |