From 99a55d76222f151435e6ede5ad68e38594ce7407 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9C=D0=BA=20=D0=98=D0=B3=D0=BE=D1=80=D1=8C?= Date: Mon, 27 Mar 2023 22:45:18 +0400 Subject: [PATCH] =?UTF-8?q?=D0=B4=D0=BE=D0=B4=D0=B5=D0=BB=D0=BA=D0=B8=20?= =?UTF-8?q?=D0=BF=D0=BE=20=D0=B7=D0=B0=D0=B4=D0=B0=D0=BD=D0=B8=D1=8E?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Views/Shared/_Layout.cshtml | 2 +- .../ViewModels/OrderViewModel.cs | 2 +- .../Implements/ClientStorage.cs | 5 ++++ .../Implements/OrderStorage.cs | 11 ++++++--- .../Models/Order.cs | 4 ++-- .../Implements/OrderStorage.cs | 12 +++++----- .../Models/Order.cs | 1 - .../Implements/ClientStorage.cs | 4 ++++ .../Implements/OrderStorage.cs | 23 +++++++++++++++---- .../Models/Order.cs | 1 - 10 files changed, 45 insertions(+), 20 deletions(-) diff --git a/BlacksmithWorkshop/BlacksmithWorkshopClientApp/Views/Shared/_Layout.cshtml b/BlacksmithWorkshop/BlacksmithWorkshopClientApp/Views/Shared/_Layout.cshtml index 0ec7f54..0cff161 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshopClientApp/Views/Shared/_Layout.cshtml +++ b/BlacksmithWorkshop/BlacksmithWorkshopClientApp/Views/Shared/_Layout.cshtml @@ -44,7 +44,7 @@ diff --git a/BlacksmithWorkshop/BlacksmithWorkshopContracts/ViewModels/OrderViewModel.cs b/BlacksmithWorkshop/BlacksmithWorkshopContracts/ViewModels/OrderViewModel.cs index 1985bb4..94f2857 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshopContracts/ViewModels/OrderViewModel.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshopContracts/ViewModels/OrderViewModel.cs @@ -22,6 +22,6 @@ namespace BlacksmithWorkshopContracts.ViewModels [DisplayName("Дата выполнения")] public DateTime? DateImplement { get; set; } [DisplayName("Клиент")] - public int ClientId { get; set; } + public string ClientFIO { get; set; } = string.Empty; } } \ No newline at end of file diff --git a/BlacksmithWorkshop/BlacksmithWorkshopDatebaseImplement/Implements/ClientStorage.cs b/BlacksmithWorkshop/BlacksmithWorkshopDatebaseImplement/Implements/ClientStorage.cs index fdbd2e6..28c09e0 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshopDatebaseImplement/Implements/ClientStorage.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshopDatebaseImplement/Implements/ClientStorage.cs @@ -51,6 +51,11 @@ namespace BlacksmithWorkshopDatabaseImplement.Implements { return null; } + var existingClient = context.Clients.FirstOrDefault(x => x.Email == newClient.Email);//проверка на уникальность + if (existingClient != null) + { + return null; + } context.Clients.Add(newClient); context.SaveChanges(); return newClient.GetViewModel; diff --git a/BlacksmithWorkshop/BlacksmithWorkshopDatebaseImplement/Implements/OrderStorage.cs b/BlacksmithWorkshop/BlacksmithWorkshopDatebaseImplement/Implements/OrderStorage.cs index 82841b1..d6e4e38 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshopDatebaseImplement/Implements/OrderStorage.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshopDatebaseImplement/Implements/OrderStorage.cs @@ -3,6 +3,7 @@ using BlacksmithWorkshopContracts.SearchModels; using BlacksmithWorkshopContracts.StoragesContracts; using BlacksmithWorkshopContracts.ViewModels; using BlacksmithWorkshopDatabaseImplement.Models; +using Microsoft.EntityFrameworkCore; namespace BlacksmithWorkshopDatabaseImplement.Implements { @@ -12,7 +13,8 @@ namespace BlacksmithWorkshopDatabaseImplement.Implements { using var context = new BlacksmithWorkshopDatabase(); List orderList = context.Orders - .Select(x => x.GetViewModel) + .Include(x => x.Client) + .Select(x => x.GetViewModel) .ToList(); foreach (var order in orderList) { @@ -34,6 +36,7 @@ namespace BlacksmithWorkshopDatabaseImplement.Implements { orderList = context.Orders .Where(x => x.Id == model.Id) + .Include(x => x.Client) .Select(x => x.GetViewModel) .ToList(); } @@ -41,14 +44,16 @@ namespace BlacksmithWorkshopDatabaseImplement.Implements { orderList = context.Orders .Where(x => x.DateCreate >= model.DateFrom && x.DateCreate <= model.DateTo) - .Select(x => x.GetViewModel) + .Include(x => x.Client) + .Select(x => x.GetViewModel) .ToList(); } else if (model.ClientId.HasValue) { orderList = context.Orders .Where(x => x.ClientId == model.ClientId) - .Select(x => x.GetViewModel) + .Include(x => x.Client) + .Select(x => x.GetViewModel) .ToList(); } foreach (var order in orderList) diff --git a/BlacksmithWorkshop/BlacksmithWorkshopDatebaseImplement/Models/Order.cs b/BlacksmithWorkshop/BlacksmithWorkshopDatebaseImplement/Models/Order.cs index 9054b80..1e02a3d 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshopDatebaseImplement/Models/Order.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshopDatebaseImplement/Models/Order.cs @@ -22,6 +22,7 @@ namespace BlacksmithWorkshopDatabaseImplement.Models public DateTime? DateImplement { get; private set; } [Required] public int ClientId { get; private set; } + public Client? Client { get; private set; }//вспомогательное поле для получения ФИО клиента public static Order? Create(OrderBindingModel model) { if (model == null) @@ -51,7 +52,6 @@ namespace BlacksmithWorkshopDatabaseImplement.Models Status = model.Status, DateCreate = model.DateCreate, DateImplement = model.DateImplement, - ClientId = model.ClientId }; } public void Update(OrderBindingModel? model) @@ -75,7 +75,7 @@ namespace BlacksmithWorkshopDatabaseImplement.Models Status = Status, DateCreate = DateCreate, DateImplement = DateImplement, - ClientId = ClientId + ClientFIO = Client?.ClientFIO ?? string.Empty }; } } diff --git a/BlacksmithWorkshop/BlacksmithWorkshopFileImplement/Implements/OrderStorage.cs b/BlacksmithWorkshop/BlacksmithWorkshopFileImplement/Implements/OrderStorage.cs index ce7f21e..050bc6c 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshopFileImplement/Implements/OrderStorage.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshopFileImplement/Implements/OrderStorage.cs @@ -14,7 +14,7 @@ namespace BlacksmithWorkshopFileImplement.Implements { source = DataFileSingleton.GetInstance(); } - private OrderViewModel AddManufactureName (OrderViewModel model) + private OrderViewModel AddManufactureAndClientName (OrderViewModel model) { model.ManufactureName = source.Manufactures.SingleOrDefault(x => x.Id == model.ManufactureId)?.ManufactureName ?? string.Empty; return model; @@ -22,7 +22,7 @@ namespace BlacksmithWorkshopFileImplement.Implements public List GetFullList() { return source.Orders - .Select(x => AddManufactureName(x.GetViewModel)) + .Select(x => AddManufactureAndClientName(x.GetViewModel)) .ToList(); } public List GetFilteredList(OrderSearchModel model) @@ -35,21 +35,21 @@ namespace BlacksmithWorkshopFileImplement.Implements { return source.Orders .Where(x => x.Id == model.Id) - .Select(x => AddManufactureName(x.GetViewModel)) + .Select(x => AddManufactureAndClientName(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)) + .Select(x => AddManufactureAndClientName(x.GetViewModel)) .ToList(); } else if (model.ClientId.HasValue)//далее ищем по Id клиента { return source.Orders .Where(x => x.ClientId == model.ClientId) - .Select(x => AddManufactureName(x.GetViewModel)) + .Select(x => AddManufactureAndClientName(x.GetViewModel)) .ToList(); } return new();//если нет ни того, ни другого, ни третьего, возвращаем пустой список @@ -65,7 +65,7 @@ namespace BlacksmithWorkshopFileImplement.Implements { return null; } - return AddManufactureName(order); + return AddManufactureAndClientName(order); } public OrderViewModel? Insert(OrderBindingModel model) { diff --git a/BlacksmithWorkshop/BlacksmithWorkshopFileImplement/Models/Order.cs b/BlacksmithWorkshop/BlacksmithWorkshopFileImplement/Models/Order.cs index 2e0755f..e2e542c 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshopFileImplement/Models/Order.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshopFileImplement/Models/Order.cs @@ -78,7 +78,6 @@ namespace BlacksmithWorkshopFileImplement.Models Status = Status, DateCreate = DateCreate, DateImplement = DateImplement, - ClientId = ClientId }; public XElement GetXElement => new ( diff --git a/BlacksmithWorkshop/BlacksmithWorkshopListImplement/Implements/ClientStorage.cs b/BlacksmithWorkshop/BlacksmithWorkshopListImplement/Implements/ClientStorage.cs index 32b5195..2707544 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshopListImplement/Implements/ClientStorage.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshopListImplement/Implements/ClientStorage.cs @@ -69,6 +69,10 @@ namespace BlacksmithWorkshopListImplement.Implements { model.Id = client.Id + 1; } + if (client.Email == model.Email)//проверка на уникальность + { + return null; + } } var res = Client.Create(model); if (res != null) diff --git a/BlacksmithWorkshop/BlacksmithWorkshopListImplement/Implements/OrderStorage.cs b/BlacksmithWorkshop/BlacksmithWorkshopListImplement/Implements/OrderStorage.cs index 5047ad0..a84095f 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshopListImplement/Implements/OrderStorage.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshopListImplement/Implements/OrderStorage.cs @@ -21,6 +21,8 @@ namespace BlacksmithWorkshopListImplement.Implements OrderViewModel vm = order.GetViewModel; var manufacture = _source.Manufactures.Find(x => x.Id == order.ManufactureId); vm.ManufactureName = manufacture?.ManufactureName ?? string.Empty; + var client = _source.Clients.Find(x => x.Id == order.ClientId); + vm.ClientFIO = client?.ClientFIO ?? string.Empty; result.Add(vm); } return result; @@ -41,7 +43,9 @@ namespace BlacksmithWorkshopListImplement.Implements OrderViewModel vm = order.GetViewModel; var manufacture = _source.Manufactures.Find(x => x.Id == order.ManufactureId); vm.ManufactureName = manufacture?.ManufactureName ?? string.Empty; - result.Add(vm); + var client = _source.Clients.Find(x => x.Id == order.ClientId); + vm.ClientFIO = client?.ClientFIO ?? string.Empty; + result.Add(vm); } } } @@ -54,7 +58,9 @@ namespace BlacksmithWorkshopListImplement.Implements OrderViewModel vm = order.GetViewModel; var manufacture = _source.Manufactures.Find(x => x.Id == order.ManufactureId); vm.ManufactureName = manufacture?.ManufactureName ?? string.Empty; - result.Add(vm); + var client = _source.Clients.Find(x => x.Id == order.ClientId); + vm.ClientFIO = client?.ClientFIO ?? string.Empty; + result.Add(vm); } } } @@ -67,7 +73,9 @@ namespace BlacksmithWorkshopListImplement.Implements OrderViewModel vm = order.GetViewModel; var manufacture = _source.Manufactures.Find(x => x.Id == order.ManufactureId); vm.ManufactureName = manufacture?.ManufactureName ?? string.Empty; - result.Add(vm); + var client = _source.Clients.Find(x => x.Id == order.ClientId); + vm.ClientFIO = client?.ClientFIO ?? string.Empty; + result.Add(vm); } } } @@ -83,8 +91,13 @@ namespace BlacksmithWorkshopListImplement.Implements { if (model.Id.HasValue && order.Id == model.Id) { - return order.GetViewModel; - } + OrderViewModel vm = order.GetViewModel; + var manufacture = _source.Manufactures.Find(x => x.Id == order.ManufactureId); + vm.ManufactureName = manufacture?.ManufactureName ?? string.Empty; + var client = _source.Clients.Find(x => x.Id == order.ClientId); + vm.ClientFIO = client?.ClientFIO ?? string.Empty; + return vm; + } } return null; } diff --git a/BlacksmithWorkshop/BlacksmithWorkshopListImplement/Models/Order.cs b/BlacksmithWorkshop/BlacksmithWorkshopListImplement/Models/Order.cs index ecc4224..2550c97 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshopListImplement/Models/Order.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshopListImplement/Models/Order.cs @@ -55,7 +55,6 @@ namespace BlacksmithWorkshopListImplement.Models Status = Status, DateCreate = DateCreate, DateImplement = DateImplement, - ClientId = ClientId }; } } \ No newline at end of file