From 0f00df1b952a94b0ad7eb24b79a63f86d1117aac Mon Sep 17 00:00:00 2001 From: Ismailov_Rovshan Date: Mon, 24 Apr 2023 22:44:37 +0400 Subject: [PATCH] =?UTF-8?q?=D0=93=D0=BE=D1=82=D0=BE=D0=B2=D0=BE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../BusinessLogic/ClientLogic.cs | 92 +++++++- .../RenovationWorkClientApp/Program.cs | 6 +- .../RenovationWorkClientApp.csproj | 2 + .../Views/Home/Create.cshtml | 10 +- .../RenovationWorkClientApp/appsettings.json | 2 +- .../ViewModels/OrderViewModel.cs | 6 + .../Implements/ClientStorage.cs | 59 ++++- .../Implements/OrderStorage.cs | 63 ++++-- .../20230424141242_Second.Designer.cs | 212 ++++++++++++++++++ .../Migrations/20230424141242_Second.cs | 90 ++++++++ .../RenovationWorkDatabaseModelSnapshot.cs | 56 +++++ .../Model/Client.cs | 64 ++++++ .../Model/Order.cs | 15 +- .../RenovationWorkDatabase.cs | 1 + .../DataFileSingleton.cs | 7 +- .../Implements/ClientStorage.cs | 63 +++++- .../Implements/OrderStorage.cs | 25 ++- .../Models/Client.cs | 78 +++++++ .../Models/Order.cs | 5 + .../DataListSingleton.cs | 9 +- .../Implements/ClientStorage.cs | 87 ++++++- .../Models/Client.cs | 50 +++++ .../Models/Order.cs | 4 + .../RenovationWorkRestApi/Program.cs | 4 +- .../FormCreateOrder.Designer.cs | 30 ++- .../RenovationWorkView/FormCreateOrder.cs | 15 +- .../RenovationWorkView/FormMain.Designer.cs | 16 +- RenovationWork/RenovationWorkView/FormMain.cs | 10 + 28 files changed, 1011 insertions(+), 70 deletions(-) create mode 100644 RenovationWork/RenovationWorkDatabaseImplement/Migrations/20230424141242_Second.Designer.cs create mode 100644 RenovationWork/RenovationWorkDatabaseImplement/Migrations/20230424141242_Second.cs create mode 100644 RenovationWork/RenovationWorkDatabaseImplement/Model/Client.cs create mode 100644 RenovationWork/RenovationWorkFileImplement/Models/Client.cs create mode 100644 RenovationWork/RenovationWorkListImplement/Models/Client.cs diff --git a/RenovationWork/RenovationWorkBusinessLogic/BusinessLogic/ClientLogic.cs b/RenovationWork/RenovationWorkBusinessLogic/BusinessLogic/ClientLogic.cs index 0599208..a773311 100644 --- a/RenovationWork/RenovationWorkBusinessLogic/BusinessLogic/ClientLogic.cs +++ b/RenovationWork/RenovationWorkBusinessLogic/BusinessLogic/ClientLogic.cs @@ -1,6 +1,8 @@ -using RenovationWorkContracts.BindingModels; +using Microsoft.Extensions.Logging; +using RenovationWorkContracts.BindingModels; using RenovationWorkContracts.BusinessLogicsContracts; using RenovationWorkContracts.SeatchModels; +using RenovationWorkContracts.StorageContracts; using RenovationWorkContracts.ViewModels; using System; using System.Collections.Generic; @@ -12,29 +14,107 @@ namespace RenovationWorkBusinessLogic.BusinessLogic { public class ClientLogic : IClientLogic //дописать { + private readonly ILogger _logger; + private readonly IClientStorage _clientStorage; + public ClientLogic(ILogger logger, IClientStorage clientStorage) + { + _logger = logger; + _clientStorage = clientStorage; + } public bool Create(ClientBindingModel model) { - throw new NotImplementedException(); + CheckModel(model); + if (_clientStorage.Insert(model) == null) + { + _logger.LogWarning("Insert operation failed"); + return false; + } + return true; } public bool Delete(ClientBindingModel model) { - throw new NotImplementedException(); + CheckModel(model, false); + _logger.LogInformation("Delete. Id:{Id}", model.Id); + if (_clientStorage.Delete(model) == null) + { + _logger.LogWarning("Delete operation failed"); + return false; + } + return true; } public ClientViewModel? ReadElement(ClientSearchModel model) { - throw new NotImplementedException(); + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + _logger.LogInformation("ReadElement. ClientFIO:{ClientFIO}. Id:{ Id}", model.ClientFIO, model.Id); + var element = _clientStorage.GetElement(model); + if (element == null) + { + _logger.LogWarning("ReadElement element not found"); + return null; + } + _logger.LogInformation("ReadElement find. Id:{Id}", element.Id); + return element; } public List? ReadList(ClientSearchModel? model) { - throw new NotImplementedException(); + _logger.LogInformation("ReadList. ClientFIO:{ClientFIO}. Id:{Id}", model?.ClientFIO, model?.Id); + var list = model == null ? _clientStorage.GetFullList() : _clientStorage.GetFilteredList(model); + if (list == null) + { + _logger.LogWarning("ReadList return null list"); + return null; + } + _logger.LogInformation("ReadList. Count:{Count}", list.Count); + return list; } public bool Update(ClientBindingModel model) { - throw new NotImplementedException(); + CheckModel(model); + if (_clientStorage.Update(model) == null) + { + _logger.LogWarning("Update operation failed"); + return false; + } + return true; + } + private void CheckModel(ClientBindingModel model, bool withParams = true) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + if (!withParams) + { + return; + } + if (string.IsNullOrEmpty(model.ClientFIO)) + { + throw new ArgumentNullException("Нет ФИО клиента", nameof(model.ClientFIO)); + } + if (string.IsNullOrEmpty(model.Email)) + { + throw new ArgumentNullException("У клиента отсутствует почта", nameof(model.Email)); + } + if (string.IsNullOrEmpty(model.Password)) + { + throw new ArgumentNullException("У клиента отсутствует пароль", nameof(model.Email)); + } + _logger.LogInformation("Client. ClientID:{Id}. ClientFIO: {ClientFIO}. Email:{ Email}. Password: { Password}", model.Id, model.ClientFIO, model.Email, model.Password); + var element = _clientStorage.GetElement(new ClientSearchModel + { + Email = model.Email + }); + if (element != null && element.Id != model.Id) + { + throw new InvalidOperationException("Такой клиент уже существует"); + } } } } \ No newline at end of file diff --git a/RenovationWork/RenovationWorkClientApp/Program.cs b/RenovationWork/RenovationWorkClientApp/Program.cs index 0727468..ac0dd66 100644 --- a/RenovationWork/RenovationWorkClientApp/Program.cs +++ b/RenovationWork/RenovationWorkClientApp/Program.cs @@ -1,10 +1,12 @@ +using RenovationWorkClientApp; + var builder = WebApplication.CreateBuilder(args); // Add services to the container. builder.Services.AddControllersWithViews(); var app = builder.Build(); - +APIClient.Connect(builder.Configuration); // Configure the HTTP request pipeline. if (!app.Environment.IsDevelopment()) { @@ -13,7 +15,7 @@ if (!app.Environment.IsDevelopment()) app.UseHsts(); } -app.UseHttpsRedirection(); + app.UseStaticFiles(); app.UseRouting(); diff --git a/RenovationWork/RenovationWorkClientApp/RenovationWorkClientApp.csproj b/RenovationWork/RenovationWorkClientApp/RenovationWorkClientApp.csproj index b3780d1..a10e139 100644 --- a/RenovationWork/RenovationWorkClientApp/RenovationWorkClientApp.csproj +++ b/RenovationWork/RenovationWorkClientApp/RenovationWorkClientApp.csproj @@ -14,4 +14,6 @@ + + diff --git a/RenovationWork/RenovationWorkClientApp/Views/Home/Create.cshtml b/RenovationWork/RenovationWorkClientApp/Views/Home/Create.cshtml index d2060b5..20736a2 100644 --- a/RenovationWork/RenovationWorkClientApp/Views/Home/Create.cshtml +++ b/RenovationWork/RenovationWorkClientApp/Views/Home/Create.cshtml @@ -8,7 +8,7 @@
Изделие:
- +
@@ -26,7 +26,7 @@