diff --git a/FurnitureAssembly/FurnitureAssemFileImplement/Implements/OrderStorage.cs b/FurnitureAssembly/FurnitureAssemFileImplement/Implements/OrderStorage.cs index ffec323..a20a14e 100644 --- a/FurnitureAssembly/FurnitureAssemFileImplement/Implements/OrderStorage.cs +++ b/FurnitureAssembly/FurnitureAssemFileImplement/Implements/OrderStorage.cs @@ -27,7 +27,7 @@ namespace FurnitureAssemFileImplement.Implements public List GetFilteredList(OrderSearchModel model) { - if (!model.Id.HasValue && !model.DateFrom.HasValue && !model.DateTo.HasValue && !model.ClientId.HasValue) + if (!model.Id.HasValue && !model.DateFrom.HasValue && !model.DateTo.HasValue && !model.ClientId.HasValue && !model.Status.HasValue) { return new(); } @@ -39,21 +39,23 @@ namespace FurnitureAssemFileImplement.Implements .ToList(); } return source.Orders - .Where(x => !(((model.DateFrom.HasValue) && (model.DateTo.HasValue)) && !(model.DateFrom <= x.DateCreate && x.DateCreate <= model.DateTo) || - (model.ClientId.HasValue) && !(x.ClientId.Equals(model.ClientId)))) + .Where(x => !(((model.DateFrom.HasValue) && (model.DateTo.HasValue)) && !(model.DateFrom <= x.DateCreate && x.DateCreate <= model.DateTo) + || ((model.ClientId.HasValue) && !(x.ClientId.Equals(model.ClientId))) + || ((model.Status.HasValue) && !(x.Status.Equals(model.Status))) + )) .Select(x => GetOrderViewModel(x)) .ToList(); } public OrderViewModel? GetElement(OrderSearchModel model) { - if (!model.Id.HasValue) + if (!model.Id.HasValue && (!model.ImplementerId.HasValue || !model.Status.HasValue)) { return null; } var order = source.Orders .FirstOrDefault(x => - (model.Id.HasValue && x.Id == model.Id)); + (model.Id.HasValue && x.Id == model.Id) || (x.ImplementerId.Equals(model.ImplementerId) && x.Status.Equals(model.Status))); return GetOrderViewModel(order); } diff --git a/FurnitureAssembly/FurnitureAssemblyDatabaseImplement/Implements/OrderStorage.cs b/FurnitureAssembly/FurnitureAssemblyDatabaseImplement/Implements/OrderStorage.cs index 060ef69..78e7b1a 100644 --- a/FurnitureAssembly/FurnitureAssemblyDatabaseImplement/Implements/OrderStorage.cs +++ b/FurnitureAssembly/FurnitureAssemblyDatabaseImplement/Implements/OrderStorage.cs @@ -17,19 +17,28 @@ namespace FurnitureAssemblyDatabaseImplement.Implements public OrderViewModel? GetElement(OrderSearchModel model) { - if (!model.Id.HasValue) + if (!model.Id.HasValue && (!model.ImplementerId.HasValue || !model.Status.HasValue)) { return new(); } using var context = new FurnitureAssemblyDatabase(); - return context.Orders.Include(x => x.Furniture).Include(x => x.Client).FirstOrDefault(x => - (model.Id.HasValue && x.Id == model.Id)) - ?.GetViewModel; + if (model.Id.HasValue) + { + return context.Orders.Include(x => x.Furniture).Include(x => x.Client).Include(x => x.Implementer).FirstOrDefault(x => + (model.Id.HasValue && x.Id == model.Id)) + ?.GetViewModel; + } + return context.Orders + .Include(x => x.Furniture) + .Include(x => x.Client) + .Include(x => x.Implementer) + .FirstOrDefault(x => x.ImplementerId.Equals(model.ImplementerId) && x.Status.Equals(model.Status)) + ?.GetViewModel; } public List GetFilteredList(OrderSearchModel model) { - if (!model.Id.HasValue && (!model.DateFrom.HasValue || !model.DateTo.HasValue) && !model.ClientId.HasValue) + if (!model.Id.HasValue && (!model.DateFrom.HasValue || !model.DateTo.HasValue) && !model.ClientId.HasValue && !model.Status.HasValue) { return new(); } @@ -37,7 +46,7 @@ namespace FurnitureAssemblyDatabaseImplement.Implements if (model.Id.HasValue) { return context.Orders - .Include(x => x.Furniture).Include(x => x.Client) + .Include(x => x.Furniture).Include(x => x.Client).Include(x => x.Implementer) .Where(x => x.Id == model.Id) .Select(x => x.GetViewModel) .ToList(); @@ -46,8 +55,12 @@ namespace FurnitureAssemblyDatabaseImplement.Implements return context.Orders .Include(x => x.Furniture) .Include(x => x.Client) - .Where(x => !(((model.DateFrom.HasValue) && (model.DateTo.HasValue)) && !(model.DateFrom <= x.DateCreate && x.DateCreate <= model.DateTo) || - (model.ClientId.HasValue) && !(x.ClientId.Equals(model.ClientId)))) + .Include(x => x.Implementer) + .Where(x => !( + (((model.DateFrom.HasValue) && (model.DateTo.HasValue)) && !(model.DateFrom <= x.DateCreate && x.DateCreate <= model.DateTo) + || (model.ClientId.HasValue && !x.ClientId.Equals(model.ClientId)) + || (model.Status.HasValue && !x.Status.Equals(model.Status)))) + ) .Select(x => x.GetViewModel) .ToList(); } @@ -58,6 +71,7 @@ namespace FurnitureAssemblyDatabaseImplement.Implements return context.Orders .Include(x => x.Furniture) .Include(x => x.Client) + .Include(x => x.Implementer) .Select(x => x.GetViewModel) .ToList(); } @@ -72,7 +86,7 @@ namespace FurnitureAssemblyDatabaseImplement.Implements } context.Orders.Add(newOrder); context.SaveChanges(); - return context.Orders.Include(x => x.Furniture).Include(x => x.Client).FirstOrDefault(x => x.Id == newOrder.Id)?.GetViewModel; + return context.Orders.Include(x => x.Furniture).Include(x => x.Client).Include(x => x.Implementer).FirstOrDefault(x => x.Id == newOrder.Id)?.GetViewModel; } public OrderViewModel? Update(OrderBindingModel model) @@ -85,7 +99,7 @@ namespace FurnitureAssemblyDatabaseImplement.Implements } order.Update(model); context.SaveChanges(); - return context.Orders.Include(x => x.Furniture).Include(x => x.Client).FirstOrDefault(x => x.Id == order.Id)?.GetViewModel; + return context.Orders.Include(x => x.Furniture).Include(x => x.Client).Include(x => x.Implementer).FirstOrDefault(x => x.Id == order.Id)?.GetViewModel; } public OrderViewModel? Delete(OrderBindingModel model) @@ -96,7 +110,7 @@ namespace FurnitureAssemblyDatabaseImplement.Implements { context.Orders.Remove(order); context.SaveChanges(); - return context.Orders.Include(x => x.Furniture).Include(x => x.Client).FirstOrDefault(x => x.Id == order.Id)?.GetViewModel; + return context.Orders.Include(x => x.Furniture).Include(x => x.Client).Include(x => x.Implementer).FirstOrDefault(x => x.Id == order.Id)?.GetViewModel; } return null; } diff --git a/FurnitureAssembly/FurnitureAssemblyListImplement/Implements/OrderStorage.cs b/FurnitureAssembly/FurnitureAssemblyListImplement/Implements/OrderStorage.cs index 8942079..f8803e2 100644 --- a/FurnitureAssembly/FurnitureAssemblyListImplement/Implements/OrderStorage.cs +++ b/FurnitureAssembly/FurnitureAssemblyListImplement/Implements/OrderStorage.cs @@ -34,7 +34,7 @@ namespace FurnitureAssemblyListImplement.Implements public OrderViewModel? GetElement(OrderSearchModel model) { - if (!model.Id.HasValue) + if (!model.Id.HasValue && (!model.ImplementerId.HasValue || !model.Status.HasValue)) { return null; } @@ -42,6 +42,9 @@ namespace FurnitureAssemblyListImplement.Implements foreach (var order in _source.Orders) { if (model.Id.HasValue && order.Id == model.Id) + { + return GetOrderViewModel(order); + } else if (order.ImplementerId.Equals(model.ImplementerId) && order.Status.Equals(model.Status)) { return GetOrderViewModel(order); } @@ -51,7 +54,7 @@ namespace FurnitureAssemblyListImplement.Implements public List GetFilteredList(OrderSearchModel model) { - if (!model.Id.HasValue && (!model.DateFrom.HasValue || !model.DateTo.HasValue)) + if (!model.Id.HasValue && (!model.DateFrom.HasValue || !model.DateTo.HasValue) && !model.ClientId.HasValue && !model.Status.HasValue) { return new(); } @@ -70,8 +73,9 @@ namespace FurnitureAssemblyListImplement.Implements } foreach (var order in _source.Orders) { - if (!(((model.DateFrom.HasValue) && (model.DateTo.HasValue)) && !(model.DateFrom <= order.DateCreate && order.DateCreate <= model.DateTo) || - (model.ClientId.HasValue) && !(order.ClientId.Equals(model.ClientId)))) + if (!(((model.DateFrom.HasValue) && (model.DateTo.HasValue)) && !(model.DateFrom <= order.DateCreate && order.DateCreate <= model.DateTo) + || ((model.ClientId.HasValue) && !(order.ClientId.Equals(model.ClientId))) + || ((model.Status.HasValue) && !(order.Status.Equals(model.Status))))) { result.Add(GetOrderViewModel(order)); }