This commit is contained in:
frog24 2024-05-18 17:52:49 +04:00
parent 487be858e0
commit b43179d022

View File

@ -12,7 +12,7 @@ using System.Threading.Tasks;
namespace ComputersShopDatabaseImplements.Implements
{
public class OrderStorage: IOrderStorage
public class OrderStorage : IOrderStorage
{
public OrderViewModel? GetElement(OrderSearchModel model)
{
@ -21,12 +21,20 @@ namespace ComputersShopDatabaseImplements.Implements
return null;
}
using var context = new ComputersShopDatabase();
return context.Orders.Include(x => x.Computer).Include(x => x.Client).Include(x => x.Implementer).FirstOrDefault(x => (model.Id.HasValue && x.Id == model.Id))?.GetViewModel;
return context.Orders
.Include(x => x.Computer)
.Include(x => x.Client)
.Include(x => x.Implementer)
.FirstOrDefault(x =>
(model.Status == null || model.Status != null && model.Status.Equals(x.Status)) &&
(model.ImplementerId.HasValue && x.ImplementerId == model.ImplementerId) ||
(model.Id.HasValue && x.Id == model.Id))?
.GetViewModel;
}
public List<OrderViewModel> GetFiltredList(OrderSearchModel model)
{
if (!model.DateFrom.HasValue && !model.ClientId.HasValue && !model.Id.HasValue && !model.Status.HasValue)
{
if (!model.DateFrom.HasValue && !model.ClientId.HasValue && !model.Id.HasValue && !model.Status.HasValue)
{
return new();
}
using var context = new ComputersShopDatabase();
@ -34,15 +42,15 @@ namespace ComputersShopDatabaseImplements.Implements
{
return context.Orders.Include(x => x.Computer).Include(x => x.Client).Include(x => x.Implementer).Where(x => x.DateCreate >= model.DateFrom && x.DateCreate <= model.DateTo).Select(x => x.GetViewModel).ToList();
}
if (model.ClientId.HasValue)
{
return context.Orders.Include(x => x.Computer).Include(x => x.Client).Include(x => x.Implementer).Where(x => x.ClientId == model.ClientId).Select(x => x.GetViewModel).ToList();
}
if (model.Status.HasValue)
if (model.ClientId.HasValue)
{
return context.Orders.Include(x => x.Computer).Include(x => x.Client).Include(x => x.Implementer).Where(x => x.ClientId == model.ClientId).Select(x => x.GetViewModel).ToList();
}
if (model.Status.HasValue)
{
return context.Orders.Include(x => x.Computer).Include(x => x.Client).Include(x => x.Implementer).Where(x => x.Status.Equals(model.Status)).Select(x => x.GetViewModel).ToList();
}
return context.Orders.Where(x => x.Id == model.Id).Include(x => x.Computer).Include(x => x.Client).Include(x => x.Implementer).Select(x => x.GetViewModel).ToList();
}
return context.Orders.Where(x => x.Id == model.Id).Include(x => x.Computer).Include(x => x.Client).Include(x => x.Implementer).Select(x => x.GetViewModel).ToList();
}
public List<OrderViewModel> GetFullList()
{
@ -86,4 +94,4 @@ namespace ComputersShopDatabaseImplements.Implements
return null;
}
}
}
}