From 39dd77a1f3015a5efb9a0a5fd993f5710e5af9cc Mon Sep 17 00:00:00 2001 From: bekodeg Date: Sun, 28 Apr 2024 11:49:26 +0400 Subject: [PATCH] =?UTF-8?q?=D0=B8=D1=81=D1=80=D0=B0=D0=B2=D0=BB=D0=B5?= =?UTF-8?q?=D0=BD=D0=B8=D0=B5=20=D0=B8=D0=B7=D0=BC=D0=B5=D0=BD=D0=B5=D0=BD?= =?UTF-8?q?=D0=B8=D1=8F=20=D1=81=D1=82=D0=B0=D1=82=D1=83=D1=81=D0=BE=D0=B2?= =?UTF-8?q?=20=D0=B7=D0=B0=D0=BA=D0=B0=D0=B7=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- SushiBar/SushiBar/Forms/FormMainLogic.cs | 4 +-- .../Implements/OrderStorage.cs | 27 ++++++++++--------- 2 files changed, 16 insertions(+), 15 deletions(-) diff --git a/SushiBar/SushiBar/Forms/FormMainLogic.cs b/SushiBar/SushiBar/Forms/FormMainLogic.cs index 7d96481..96e28b9 100644 --- a/SushiBar/SushiBar/Forms/FormMainLogic.cs +++ b/SushiBar/SushiBar/Forms/FormMainLogic.cs @@ -71,9 +71,9 @@ namespace SushiBar.Forms { int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); _logger.LogInformation("Заказ №{id}. Меняется статус на 'В работе'", id); - try + try { - var operationResult = _orderLogic.TakeOrderInWork(new OrderBindingModel { Id = id}); + var operationResult = _orderLogic.TakeOrderInWork(new OrderBindingModel { Id = id }); if (!operationResult) { throw new Exception("Ошибка при сохранении. Дополнительная информация в логах."); diff --git a/SushiBar/SushiBarDatabaseImplement/Implements/OrderStorage.cs b/SushiBar/SushiBarDatabaseImplement/Implements/OrderStorage.cs index 24c40d1..f34a7ae 100644 --- a/SushiBar/SushiBarDatabaseImplement/Implements/OrderStorage.cs +++ b/SushiBar/SushiBarDatabaseImplement/Implements/OrderStorage.cs @@ -14,19 +14,20 @@ namespace SushiBarDatabaseImplement.Implements { using var context = new SushiBarDatabase(); return context.Orders - .Include(x => x.Sushi) - .Select(x => x.GetViewModel) + .Include(o => o.Sushi) + .Select(o => o.GetViewModel) .ToList(); } public List GetFilteredList(OrderSearchModel model) { - var result = new List(); - var element = GetElement(model); - if (element != null) - { - result.Add(element); - } - return new(); + using var context = new SushiBarDatabase(); + return context.Orders + .Include(o => o.Sushi) + .Where(o => + (model.Id.HasValue && o.Id == model.Id) || + (model.DateFrom.HasValue && model.DateTo.HasValue && model.DateFrom < o.DateCreate && o.DateCreate < model.DateTo)) + .Select(o => o.GetViewModel) + .ToList(); } public OrderViewModel? GetElement(OrderSearchModel model) { @@ -36,8 +37,8 @@ namespace SushiBarDatabaseImplement.Implements } using var context = new SushiBarDatabase(); return context.Orders - .Include (x => x.Sushi) - .FirstOrDefault(x => x.Id == model.Id)?.GetViewModel; + .Include (o => o.Sushi) + .FirstOrDefault(o => o.Id == model.Id)?.GetViewModel; } public OrderViewModel? Insert(OrderBindingModel model) { @@ -57,7 +58,7 @@ namespace SushiBarDatabaseImplement.Implements using var transaction = context.Database.BeginTransaction(); try { - var order = context.Orders.FirstOrDefault(rec => + var order = context.Orders.Include(o => o.Sushi).FirstOrDefault(rec => rec.Id == model.Id); if (order == null) { @@ -78,7 +79,7 @@ namespace SushiBarDatabaseImplement.Implements { using var context = new SushiBarDatabase(); var element = context.Orders - .FirstOrDefault(x => x.Id == model.Id); + .FirstOrDefault(o => o.Id == model.Id); if (element != null) { context.Orders.Remove(element);