From ec2637d8c0f8b470b4a9c801b1a393d403c618fb 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, 24 Apr 2023 00:58:32 +0400 Subject: [PATCH] =?UTF-8?q?=D1=84=D0=B8=D0=BA=D1=81=D1=8B=20=D0=BF=D0=BE?= =?UTF-8?q?=20=D0=BA=D0=BB=D0=B8=D0=B5=D0=BD=D1=82=D1=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../BusinessLogics/ClientLogic.cs | 4 ++- .../ViewModels/OrderViewModel.cs | 1 + .../Models/IOrderModel.cs | 1 + .../Implements/ClientStorage.cs | 30 ++++++++----------- .../Implements/ClientStorage.cs | 16 +++++++--- .../Implements/OrderStorage.cs | 1 + .../Implements/ClientStorage.cs | 8 ++--- 7 files changed, 34 insertions(+), 27 deletions(-) diff --git a/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/BusinessLogics/ClientLogic.cs b/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/BusinessLogics/ClientLogic.cs index 8d7d60c..f40ffba 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/BusinessLogics/ClientLogic.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/BusinessLogics/ClientLogic.cs @@ -3,7 +3,9 @@ using BlacksmithWorkshopContracts.BusinessLogicsContracts; using BlacksmithWorkshopContracts.SearchModels; using BlacksmithWorkshopContracts.StoragesContracts; using BlacksmithWorkshopContracts.ViewModels; +using DocumentFormat.OpenXml.InkML; using Microsoft.Extensions.Logging; +using System.Net; namespace BlacksmithWorkshopBusinessLogic.BusinessLogics { @@ -102,6 +104,6 @@ namespace BlacksmithWorkshopBusinessLogic.BusinessLogics { throw new InvalidOperationException("Клиент с таким адресом электронной почты уже есть"); } - } + } } } diff --git a/BlacksmithWorkshop/BlacksmithWorkshopContracts/ViewModels/OrderViewModel.cs b/BlacksmithWorkshop/BlacksmithWorkshopContracts/ViewModels/OrderViewModel.cs index 94f2857..70bebf2 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshopContracts/ViewModels/OrderViewModel.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshopContracts/ViewModels/OrderViewModel.cs @@ -9,6 +9,7 @@ namespace BlacksmithWorkshopContracts.ViewModels [DisplayName("Номер")] public int Id { get; set; } public int ManufactureId { get; set; } + public int ClientId { get; set; } [DisplayName("Изделие")] public string ManufactureName { get; set; } = string.Empty; [DisplayName("Количество")] diff --git a/BlacksmithWorkshop/BlacksmithWorkshopDataModels/Models/IOrderModel.cs b/BlacksmithWorkshop/BlacksmithWorkshopDataModels/Models/IOrderModel.cs index 9fe5b82..99d9e5c 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshopDataModels/Models/IOrderModel.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshopDataModels/Models/IOrderModel.cs @@ -5,6 +5,7 @@ namespace BlacksmithWorkshopDataModels.Models public interface IOrderModel : IId { int ManufactureId { get; } + int ClientId { get; } int Count { get; } double Sum { get; } OrderStatus Status { get; } diff --git a/BlacksmithWorkshop/BlacksmithWorkshopDatebaseImplement/Implements/ClientStorage.cs b/BlacksmithWorkshop/BlacksmithWorkshopDatebaseImplement/Implements/ClientStorage.cs index 28c09e0..c4553c0 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshopDatebaseImplement/Implements/ClientStorage.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshopDatebaseImplement/Implements/ClientStorage.cs @@ -28,21 +28,20 @@ namespace BlacksmithWorkshopDatabaseImplement.Implements public ClientViewModel? GetElement(ClientSearchModel model) { using var context = new BlacksmithWorkshopDatabase(); - if (!model.Id.HasValue && (string.IsNullOrEmpty(model.Email) || string.IsNullOrEmpty(model.Password))) - { - return null; - } - ClientViewModel? result = null; - if (model.Id.HasValue) - { - result = context.Clients.FirstOrDefault(x => x.Id == model.Id)?.GetViewModel; + if (model.Id.HasValue)//сначала ищем по Id + { + return context.Clients.FirstOrDefault(x => x.Id == model.Id)?.GetViewModel; } - else if (!string.IsNullOrEmpty(model.Email) && !string.IsNullOrEmpty(model.Password)) - { - result = context.Clients.FirstOrDefault(x => x.Email.Contains(model.Email) && x.Password.Contains(model.Password))?.GetViewModel; + else if (!string.IsNullOrEmpty(model.Email) && string.IsNullOrEmpty(model.Password))//затем по логину + { + return context.Clients.FirstOrDefault(x => x.Email == model.Email)?.GetViewModel; } - return result; - } + else if (!string.IsNullOrEmpty(model.Email) && !string.IsNullOrEmpty(model.Password))//затем по логину и паролю + { + return context.Clients.FirstOrDefault(x => x.Email == model.Email && x.Password == model.Password)?.GetViewModel; + } + return null; + } public ClientViewModel? Insert(ClientBindingModel model) { using var context = new BlacksmithWorkshopDatabase(); @@ -51,11 +50,6 @@ 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/BlacksmithWorkshopFileImplement/Implements/ClientStorage.cs b/BlacksmithWorkshop/BlacksmithWorkshopFileImplement/Implements/ClientStorage.cs index ee41e15..a2b82c0 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshopFileImplement/Implements/ClientStorage.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshopFileImplement/Implements/ClientStorage.cs @@ -32,12 +32,20 @@ namespace BlacksmithWorkshopFileImplement.Implements } public ClientViewModel? GetElement(ClientSearchModel model) { - if (!model.Id.HasValue && string.IsNullOrEmpty(model.Email) && string.IsNullOrEmpty(model.ClientFIO)) + if (model.Id.HasValue)//сначала ищем по Id { - return null; + return source.Clients.FirstOrDefault(x => x.Id == model.Id)?.GetViewModel; } - return source.Clients.FirstOrDefault(x => ((model.Id.HasValue && x.Id == model.Id) || (!string.IsNullOrEmpty(model.Email) && x.Email == model.Email && !string.IsNullOrEmpty(model.ClientFIO) && x.ClientFIO == model.ClientFIO)))?.GetViewModel; - } + else if (!string.IsNullOrEmpty(model.Email) && string.IsNullOrEmpty(model.Password))//затем по логину + { + return source.Clients.FirstOrDefault(x => x.Email == model.Email)?.GetViewModel; + } + else if (!string.IsNullOrEmpty(model.Email) && !string.IsNullOrEmpty(model.Password))//затем по логину и паролю + { + return source.Clients.FirstOrDefault(x => x.Email == model.Email && x.Password == model.Password)?.GetViewModel; + } + return null; + } public ClientViewModel? Insert(ClientBindingModel model) { model.Id = source.Clients.Count > 0 ? source.Clients.Max(x => x.Id) + 1 : 1; diff --git a/BlacksmithWorkshop/BlacksmithWorkshopFileImplement/Implements/OrderStorage.cs b/BlacksmithWorkshop/BlacksmithWorkshopFileImplement/Implements/OrderStorage.cs index 050bc6c..3ab0d7b 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshopFileImplement/Implements/OrderStorage.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshopFileImplement/Implements/OrderStorage.cs @@ -17,6 +17,7 @@ namespace BlacksmithWorkshopFileImplement.Implements private OrderViewModel AddManufactureAndClientName (OrderViewModel model) { model.ManufactureName = source.Manufactures.SingleOrDefault(x => x.Id == model.ManufactureId)?.ManufactureName ?? string.Empty; + model.ClientFIO = source.Clients.SingleOrDefault(x => x.Id == model.ClientId)?.ClientFIO ?? string.Empty; return model; } public List GetFullList() diff --git a/BlacksmithWorkshop/BlacksmithWorkshopListImplement/Implements/ClientStorage.cs b/BlacksmithWorkshop/BlacksmithWorkshopListImplement/Implements/ClientStorage.cs index 2707544..6f8cc68 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshopListImplement/Implements/ClientStorage.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshopListImplement/Implements/ClientStorage.cs @@ -53,6 +53,10 @@ namespace BlacksmithWorkshopListImplement.Implements { return client.GetViewModel; } + if (model.Email != null && client.Email.Contains(model.Email) && model.Password == null)//затем по логину + { + return client.GetViewModel; + } if (model.Email != null && client.Email.Contains(model.Email) && model.Password != null && client.Password.Contains(model.Password))//затем по логину и паролю { return client.GetViewModel; @@ -69,10 +73,6 @@ namespace BlacksmithWorkshopListImplement.Implements { model.Id = client.Id + 1; } - if (client.Email == model.Email)//проверка на уникальность - { - return null; - } } var res = Client.Create(model); if (res != null)