From 28b2066e9d5771adf515133de1b335855332c2a8 Mon Sep 17 00:00:00 2001 From: goldfest Date: Wed, 29 May 2024 19:52:09 +0400 Subject: [PATCH] =?UTF-8?q?=D0=BF=D0=BE=D0=B4=D1=80=D0=B5=D0=B4=D0=B0?= =?UTF-8?q?=D0=BA=D1=82=D0=B8=D1=80=D0=BE=D0=B2=D0=B0=D0=BB=20=D0=B4=D0=BB?= =?UTF-8?q?=D1=8F=20=D0=BC=D0=B5=D0=BD=D0=B5=D0=B4=D0=B6=D0=B5=D1=80=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../BusinessLogics/ManagerLogic.cs | 17 +++++++++++++---- .../CarCenterDataBase.cs | 2 +- .../Implements/ManagerStorage.cs | 5 ++++- ...=> 20240529155030_InitialCreate.Designer.cs} | 2 +- ...reate.cs => 20240529155030_InitialCreate.cs} | 0 .../Controllers/HomeController.cs | 2 ++ 6 files changed, 21 insertions(+), 7 deletions(-) rename CarCenter/CarCenterDataBaseImplement/Migrations/{20240529142629_InitialCreate.Designer.cs => 20240529155030_InitialCreate.Designer.cs} (99%) rename CarCenter/CarCenterDataBaseImplement/Migrations/{20240529142629_InitialCreate.cs => 20240529155030_InitialCreate.cs} (100%) diff --git a/CarCenter/CarCenterBusinessLogic/BusinessLogics/ManagerLogic.cs b/CarCenter/CarCenterBusinessLogic/BusinessLogics/ManagerLogic.cs index b85fd3b..e981fd2 100644 --- a/CarCenter/CarCenterBusinessLogic/BusinessLogics/ManagerLogic.cs +++ b/CarCenter/CarCenterBusinessLogic/BusinessLogics/ManagerLogic.cs @@ -159,14 +159,23 @@ namespace CarCenterBusinessLogic.BusinessLogics _logger.LogInformation("Manager. ManagerFIO: {ManagerFIO}. ManagerLogin: {ManagerLogin}. Id: {Id}", model.ManagerFIO, model.ManagerLogin, model.Id); - var element = _managerStorage.GetElement(new ManagerSearchModel + var element1 = _managerStorage.GetElement(new ManagerSearchModel { ManagerEmail = model.ManagerEmail }); - - if (element != null && element.Id != model.Id) + var element2 = _managerStorage.GetElement(new ManagerSearchModel { - throw new InvalidOperationException("менеджер с таким логином уже есть"); + ManagerLogin = model.ManagerLogin + }); + + if (element1 != null && element1.Id != model.Id) + { + throw new InvalidOperationException("Менеджер с такой почтой уже есть"); + } + + if (element2 != null && element2.Id != model.Id) + { + throw new InvalidOperationException("Менеджер с такой почтой уже есть"); } } } diff --git a/CarCenter/CarCenterDataBaseImplement/CarCenterDataBase.cs b/CarCenter/CarCenterDataBaseImplement/CarCenterDataBase.cs index bcab7d9..56119d9 100644 --- a/CarCenter/CarCenterDataBaseImplement/CarCenterDataBase.cs +++ b/CarCenter/CarCenterDataBaseImplement/CarCenterDataBase.cs @@ -9,7 +9,7 @@ namespace CarCenterDataBaseImplement { if (optionsBuilder.IsConfigured == false) { - optionsBuilder.UseSqlServer(@"Data Source=DESKTOP-D5A5OOG\GOLDFEST;Initial Catalog=CarCenter;Integrated Security=True;MultipleActiveResultSets=True;;TrustServerCertificate=True"); + optionsBuilder.UseSqlServer(@"Data Source=DESKTOP-D5A5OOG\GOLDFEST;Initial Catalog=CarCenter2;Integrated Security=True;MultipleActiveResultSets=True;;TrustServerCertificate=True"); } base.OnConfiguring(optionsBuilder); diff --git a/CarCenter/CarCenterDataBaseImplement/Implements/ManagerStorage.cs b/CarCenter/CarCenterDataBaseImplement/Implements/ManagerStorage.cs index a285971..81edc15 100644 --- a/CarCenter/CarCenterDataBaseImplement/Implements/ManagerStorage.cs +++ b/CarCenter/CarCenterDataBaseImplement/Implements/ManagerStorage.cs @@ -24,7 +24,10 @@ namespace CarCenterDataBaseImplement.Implements { if (!model.Id.HasValue && string.IsNullOrEmpty(model.ManagerLogin)) { return null; } using var context = new CarCenterDataBase(); - return context.Managers.FirstOrDefault(x => (model.Id.HasValue && x.Id == model.Id) || (!string.IsNullOrEmpty(model.ManagerLogin) && !string.IsNullOrEmpty(model.ManagerPassword) && x.ManagerLogin.Equals(model.ManagerLogin) && x.ManagerPassword.Equals(model.ManagerPassword)))?.GetViewModel; ; + if (!string.IsNullOrEmpty(model.ManagerLogin) && string.IsNullOrEmpty(model.ManagerPassword)) + return context.Managers.FirstOrDefault(x => x.ManagerLogin == model.ManagerLogin)?.GetViewModel; + else + return context.Managers.FirstOrDefault(x => (model.Id.HasValue && x.Id == model.Id) || (!string.IsNullOrEmpty(model.ManagerLogin) && !string.IsNullOrEmpty(model.ManagerPassword) && x.ManagerLogin.Equals(model.ManagerLogin) && x.ManagerPassword.Equals(model.ManagerPassword)))?.GetViewModel; } public List GetFilteredList(ManagerSearchModel model) diff --git a/CarCenter/CarCenterDataBaseImplement/Migrations/20240529142629_InitialCreate.Designer.cs b/CarCenter/CarCenterDataBaseImplement/Migrations/20240529155030_InitialCreate.Designer.cs similarity index 99% rename from CarCenter/CarCenterDataBaseImplement/Migrations/20240529142629_InitialCreate.Designer.cs rename to CarCenter/CarCenterDataBaseImplement/Migrations/20240529155030_InitialCreate.Designer.cs index 6515ef6..7cb4a40 100644 --- a/CarCenter/CarCenterDataBaseImplement/Migrations/20240529142629_InitialCreate.Designer.cs +++ b/CarCenter/CarCenterDataBaseImplement/Migrations/20240529155030_InitialCreate.Designer.cs @@ -12,7 +12,7 @@ using Microsoft.EntityFrameworkCore.Storage.ValueConversion; namespace CarCenterDataBaseImplement.Migrations { [DbContext(typeof(CarCenterDataBase))] - [Migration("20240529142629_InitialCreate")] + [Migration("20240529155030_InitialCreate")] partial class InitialCreate { /// diff --git a/CarCenter/CarCenterDataBaseImplement/Migrations/20240529142629_InitialCreate.cs b/CarCenter/CarCenterDataBaseImplement/Migrations/20240529155030_InitialCreate.cs similarity index 100% rename from CarCenter/CarCenterDataBaseImplement/Migrations/20240529142629_InitialCreate.cs rename to CarCenter/CarCenterDataBaseImplement/Migrations/20240529155030_InitialCreate.cs diff --git a/CarCenter/CarCenterManagerAPP/Controllers/HomeController.cs b/CarCenter/CarCenterManagerAPP/Controllers/HomeController.cs index 3665c4f..26920d2 100644 --- a/CarCenter/CarCenterManagerAPP/Controllers/HomeController.cs +++ b/CarCenter/CarCenterManagerAPP/Controllers/HomeController.cs @@ -81,6 +81,8 @@ namespace ManagerApp.Controllers { if (password1 == password2 && _data.Register(new() { ManagerEmail = email, ManagerLogin = login, ManagerFIO = fio, ManagerNumber = number, ManagerPassword = password1 })) { + var manager = _data.Login(login, password1); + UserManager.manager = manager; Response.Redirect("Index"); } }