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)