diff --git a/BlacksmithWorkshop/BlacksmithWorkshopDatebaseImplement/Implements/OrderStorage.cs b/BlacksmithWorkshop/BlacksmithWorkshopDatebaseImplement/Implements/OrderStorage.cs index 59a09f9..a5c29f5 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshopDatebaseImplement/Implements/OrderStorage.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshopDatebaseImplement/Implements/OrderStorage.cs @@ -24,15 +24,26 @@ namespace BlacksmithWorkshopDatabaseImplement.Implements } public List GetFilteredList(OrderSearchModel model) { - if (!model.DateFrom.HasValue || !model.DateTo.HasValue) + if (!model.Id.HasValue && (!model.DateFrom.HasValue || !model.DateTo.HasValue)) { return new(); } using var context = new BlacksmithWorkshopDatabase(); - List orderList = context.Orders - .Where(x => x.DateCreate >= model.DateFrom && x.DateCreate <= model.DateTo) - .Select(x => x.GetViewModel) - .ToList(); + List orderList = new(); + if (model.Id.HasValue) //сначала ищем по Id + { + orderList = context.Orders + .Where(x => x.Id == model.Id) + .Select(x => x.GetViewModel) + .ToList(); + } + else if (model.DateFrom.HasValue && model.DateTo.HasValue) //если у модели нет Id, ищем по датам + { + orderList = context.Orders + .Where(x => x.DateCreate >= model.DateFrom && x.DateCreate <= model.DateTo) + .Select(x => x.GetViewModel) + .ToList(); + } foreach (var order in orderList) { string manufactureName = context.Manufactures diff --git a/BlacksmithWorkshop/BlacksmithWorkshopFileImplement/Implements/OrderStorage.cs b/BlacksmithWorkshop/BlacksmithWorkshopFileImplement/Implements/OrderStorage.cs index 4715a2d..d37e815 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshopFileImplement/Implements/OrderStorage.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshopFileImplement/Implements/OrderStorage.cs @@ -27,14 +27,25 @@ namespace BlacksmithWorkshopFileImplement.Implements } public List GetFilteredList(OrderSearchModel model) { - if (!model.DateFrom.HasValue || !model.DateTo.HasValue) + if (!model.Id.HasValue && (!model.DateFrom.HasValue || !model.DateTo.HasValue)) { return new(); } - return source.Orders + if (model.Id.HasValue)//сначала ищем по Id + { + return source.Orders + .Where(x => x.Id == model.Id) + .Select(x => AddManufactureName(x.GetViewModel)) + .ToList(); + } + else if (model.DateFrom.HasValue && model.DateTo.HasValue)//если Id в модели нет, ищем по датам + { + return source.Orders .Where(x => x.DateCreate >= model.DateFrom && x.DateCreate <= model.DateTo) .Select(x => AddManufactureName(x.GetViewModel)) .ToList(); + } + return new();//если нет ни того, ни другого, возвращаем пустой список } public OrderViewModel? GetElement(OrderSearchModel model) { diff --git a/BlacksmithWorkshop/BlacksmithWorkshopListImplement/Implements/OrderStorage.cs b/BlacksmithWorkshop/BlacksmithWorkshopListImplement/Implements/OrderStorage.cs index 1753e42..3246ce6 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshopListImplement/Implements/OrderStorage.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshopListImplement/Implements/OrderStorage.cs @@ -28,18 +28,34 @@ namespace BlacksmithWorkshopListImplement.Implements public List GetFilteredList(OrderSearchModel model) { var result = new List(); - if (!model.DateFrom.HasValue || !model.DateTo.HasValue) + if (!model.Id.HasValue && (!model.DateFrom.HasValue || !model.DateTo.HasValue)) { return result; } - foreach (var order in _source.Orders) + if (model.Id.HasValue)//сначала ищем по Id { - if (model.Id.HasValue && order.DateCreate >= model.DateFrom && order.DateCreate <= model.DateTo) + foreach (var order in _source.Orders) { - OrderViewModel vm = order.GetViewModel; - var manufacture = _source.Manufactures.Find(x => x.Id == order.ManufactureId); - vm.ManufactureName = manufacture?.ManufactureName ?? string.Empty; - result.Add(vm); + if (model.Id == order.Id) + { + OrderViewModel vm = order.GetViewModel; + var manufacture = _source.Manufactures.Find(x => x.Id == order.ManufactureId); + vm.ManufactureName = manufacture?.ManufactureName ?? string.Empty; + result.Add(vm); + } + } + } + else if (model.DateFrom.HasValue && model.DateTo.HasValue)//если у модели нет Id, ищем по датам + { + foreach (var order in _source.Orders) + { + if (order.DateCreate >= model.DateFrom && order.DateCreate <= model.DateTo) + { + OrderViewModel vm = order.GetViewModel; + var manufacture = _source.Manufactures.Find(x => x.Id == order.ManufactureId); + vm.ManufactureName = manufacture?.ManufactureName ?? string.Empty; + result.Add(vm); + } } } return result;