This commit is contained in:
kamilia 2024-05-19 14:24:04 +04:00
parent 96bb26dc1b
commit 15ccb0dca1

View File

@ -15,13 +15,14 @@ namespace AircraftPlantDatabaseImplement.Implements
return context.Orders return context.Orders
.Include(x => x.Plane) .Include(x => x.Plane)
.Include(x => x.Client) .Include(x => x.Client)
.Include(x => x.Implementer)
.Select(x => x.GetViewModel) .Select(x => x.GetViewModel)
.ToList(); .ToList();
} }
public List<OrderViewModel> GetFilteredList(OrderSearchModel model) public List<OrderViewModel> GetFilteredList(OrderSearchModel model)
{ {
if (!model.Id.HasValue && !model.ClientId.HasValue && (!model.DateFrom.HasValue || !model.DateTo.HasValue)) if (!model.Id.HasValue && !model.ClientId.HasValue && (!model.DateFrom.HasValue || !model.DateTo.HasValue) && model.Status == null)
{ {
return new(); return new();
} }
@ -31,6 +32,7 @@ namespace AircraftPlantDatabaseImplement.Implements
return context.Orders return context.Orders
.Include(x => x.Client) .Include(x => x.Client)
.Include(x => x.Plane) .Include(x => x.Plane)
.Include(x => x.Implementer)
.Where(x => x.DateCreate >= model.DateFrom && x.DateCreate <= model.DateTo) .Where(x => x.DateCreate >= model.DateFrom && x.DateCreate <= model.DateTo)
.Select(x => x.GetViewModel) .Select(x => x.GetViewModel)
.ToList(); .ToList();
@ -41,11 +43,21 @@ namespace AircraftPlantDatabaseImplement.Implements
return context.Orders return context.Orders
.Include(x => x.Plane) .Include(x => x.Plane)
.Include(x => x.Client) .Include(x => x.Client)
.Include(x => x.Implementer)
.Where(x => x.ClientId == model.ClientId) .Where(x => x.ClientId == model.ClientId)
.Select(x => x.GetViewModel) .Select(x => x.GetViewModel)
.ToList(); .ToList();
} }
if (model.Status.HasValue)
{
return context.Orders
.Include(x => x.Plane)
.Include(x => x.Client)
.Include(x => x.Implementer)
.Where(x => x.Status == model.Status)
.Select(x => x.GetViewModel)
.ToList();
}
return context.Orders return context.Orders
.Include(x => x.Plane) .Include(x => x.Plane)
.Include(x => x.Client) .Include(x => x.Client)
@ -61,11 +73,36 @@ namespace AircraftPlantDatabaseImplement.Implements
return null; return null;
} }
using var context = new AircraftPlantDatabase(); using var context = new AircraftPlantDatabase();
return context.Orders if (model.Id.HasValue)
{
return context.Orders
.Include(x => x.Plane) .Include(x => x.Plane)
.Include(x => x.Client) .Include(x => x.Client)
.FirstOrDefault(x => (model.Id.HasValue && x.Id == model.Id))? .Include(x => x.Implementer)
.GetViewModel; .FirstOrDefault(x => x.Id == model.Id)
?.GetViewModel;
}
if (model.ImplementerId.HasValue && model.Status.HasValue)
{
return context.Orders
.Include(x => x.Plane)
.Include(x => x.Client)
.Include(x => x.Implementer)
.FirstOrDefault(x => x.ImplementerId == model.ImplementerId && x.Status == model.Status)
?.GetViewModel;
}
if (model.ImplementerId.HasValue)
{
return context.Orders
.Include(x => x.Plane)
.Include(x => x.Client)
.Include(x => x.Implementer)
.FirstOrDefault(x => x.ImplementerId == model.ImplementerId)
?.GetViewModel;
}
return null;
} }
public OrderViewModel? Insert(OrderBindingModel model) public OrderViewModel? Insert(OrderBindingModel model)