diff --git a/AircraftPlant/AbstractShopListImplement/OrderStorage.cs b/AircraftPlant/AbstractShopListImplement/OrderStorage.cs index 5f611de..1358529 100644 --- a/AircraftPlant/AbstractShopListImplement/OrderStorage.cs +++ b/AircraftPlant/AbstractShopListImplement/OrderStorage.cs @@ -66,7 +66,7 @@ namespace AircraftPlantListImplement.Implements return result; } - if (model.ClientId.HasValue && !model.Id.HasValue) + else if(model.ClientId.HasValue && !model.Id.HasValue) { foreach (var order in _source.Orders) { @@ -74,6 +74,27 @@ namespace AircraftPlantListImplement.Implements } } + else if (model.ImplementerId.HasValue) + { + foreach (var order in _source.Orders) + { + if (order.ImplementerId == model.ImplementerId) + { + result.Add(GetViewModel(order)); + } + } + } + else if (model.Status != null) + { + foreach (var order in _source.Orders) + { + if (order.Status.Equals(model.Status)) + { + result.Add(GetViewModel(order)); + } + } + } + foreach (var order in _source.Orders) { if (order.Id == model.Id) @@ -90,7 +111,7 @@ namespace AircraftPlantListImplement.Implements /// public OrderViewModel? GetElement(OrderSearchModel model) { - if (!model.Id.HasValue) + if (!model.Id.HasValue && !model.ImplementerId.HasValue) { return null; } @@ -101,6 +122,14 @@ namespace AircraftPlantListImplement.Implements { return GetViewModel(order); } + if (model.ImplementerId.HasValue && model.Status != null && order.ImplementerId == model.ImplementerId && order.Status.Equals(model.Status)) + { + return GetViewModel(order); + } + if (model.ImplementerId.HasValue && model.Status == null && order.ImplementerId == model.ImplementerId) + { + return GetViewModel(order); + } } return null; } diff --git a/AircraftPlant/AircraftPlantDatabaseImplement/Implements/OrderStorage.cs b/AircraftPlant/AircraftPlantDatabaseImplement/Implements/OrderStorage.cs index 745c49e..5431d1b 100644 --- a/AircraftPlant/AircraftPlantDatabaseImplement/Implements/OrderStorage.cs +++ b/AircraftPlant/AircraftPlantDatabaseImplement/Implements/OrderStorage.cs @@ -15,6 +15,7 @@ namespace AircraftPlantDatabaseImplement.Implements return context.Orders .Include(x => x.Plane) .Include(x => x.Client) + .Include(x => x.Implementer) .Select(x => x.GetViewModel) .ToList(); } @@ -31,6 +32,7 @@ namespace AircraftPlantDatabaseImplement.Implements return context.Orders .Include(x => x.Client) .Include(x => x.Plane) + .Include(x => x.Implementer) .Where(x => x.DateCreate >= model.DateFrom && x.DateCreate <= model.DateTo) .Select(x => x.GetViewModel) .ToList(); @@ -41,22 +43,38 @@ namespace AircraftPlantDatabaseImplement.Implements return context.Orders .Include(x => x.Plane) .Include(x => x.Client) + .Include(x => x.Implementer) .Where(x => x.ClientId == model.ClientId) .Select(x => x.GetViewModel) .ToList(); } - return context.Orders + else if (model.ImplementerId.HasValue) + { + return context.Orders .Include(x => x.Plane) .Include(x => x.Client) - .Where(x => x.Id == model.Id) + .Include(x => x.Implementer) + .Where(x => x.ImplementerId == model.ImplementerId) .Select(x => x.GetViewModel) .ToList(); + } + else if (model.Status != null) + { + return context.Orders + .Include(x => x.Plane) + .Include(x => x.Client) + .Include(x => x.Implementer) + .Where(x => x.Status.Equals(model.Status)) + .Select(x => x.GetViewModel) + .ToList(); + } + return new(); } public OrderViewModel? GetElement(OrderSearchModel model) { - if (!model.Id.HasValue) + if (!model.Id.HasValue && !model.ImplementerId.HasValue) { return null; } @@ -64,8 +82,12 @@ namespace AircraftPlantDatabaseImplement.Implements return context.Orders .Include(x => x.Plane) .Include(x => x.Client) - .FirstOrDefault(x => (model.Id.HasValue && x.Id == model.Id))? - .GetViewModel; + .Include(x => x.Implementer) + .FirstOrDefault(x => + model.ImplementerId.HasValue && x.ImplementerId == model.ImplementerId && model.Status != null && x.Status.Equals(model.Status) + || model.Status == null && model.ImplementerId.HasValue && x.ImplementerId == model.ImplementerId + || model.Id.HasValue && x.Id == model.Id) + ?.GetViewModel; } public OrderViewModel? Insert(OrderBindingModel model) diff --git a/AircraftPlant/AircraftPlantFileImplement/OrderStorage.cs b/AircraftPlant/AircraftPlantFileImplement/OrderStorage.cs index f01c83a..b49e040 100644 --- a/AircraftPlant/AircraftPlantFileImplement/OrderStorage.cs +++ b/AircraftPlant/AircraftPlantFileImplement/OrderStorage.cs @@ -28,29 +28,47 @@ namespace AircraftPlantFileImplement.Implements { return new(); } - if (model.DateFrom.HasValue) + else if (model.DateFrom.HasValue) { return _source.Orders .Where(x => x.DateCreate >= model.DateFrom && x.DateCreate <= model.DateTo) .Select(x => GetViewModel(x)) .ToList(); } - if (model.ClientId.HasValue && !model.Id.HasValue) + else if (model.ClientId.HasValue && !model.Id.HasValue) { return _source.Orders .Where(x => x.ClientId == model.ClientId) .Select(x => x.GetViewModel) .ToList(); } + else if (model.ImplementerId.HasValue) + { + return _source.Orders + .Where(x => x.ImplementerId == model.ImplementerId) + .Select(x => x.GetViewModel) + .ToList(); + } + else if (model.Status != null) + { + return _source.Orders + .Where(x => x.Status.Equals(model.Status)) + .Select(x => x.GetViewModel) + .ToList(); + } return _source.Orders.Where(x => x.Id.Equals(model.Id)).Select(x => GetViewModel(x)).ToList(); } public OrderViewModel? GetElement(OrderSearchModel model) { - if (!model.Id.HasValue) + if (!model.Id.HasValue && !model.ImplementerId.HasValue) { return null; } - return GetViewModel(_source.Orders.FirstOrDefault(x => (model.Id.HasValue && x.Id == model.Id))); + var order = _source.Orders.FirstOrDefault(x => + model.ImplementerId.HasValue && x.ImplementerId == model.ImplementerId && model.Status != null && x.Status.Equals(model.Status) + || model.Status == null && model.ImplementerId.HasValue && x.ImplementerId == model.ImplementerId + || model.Id.HasValue && x.Id == model.Id); + return order?.GetViewModel != null ? order.GetViewModel : null; } public OrderViewModel? Insert(OrderBindingModel model) {