From d3d2eef4f7c9ca61ce9820ebf0cb7f9407fc1307 Mon Sep 17 00:00:00 2001 From: Yunusov_Niyaz Date: Sat, 6 Apr 2024 19:58:28 +0400 Subject: [PATCH] =?UTF-8?q?=D0=9D=D0=B5=20=D0=B4=D0=BE=D0=B4=D0=B5=D0=BB?= =?UTF-8?q?=D0=B0=D0=BD=D0=BE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CarRepairShop/CarRepairShop.sln | 12 +- CarRepairShop/CarRepairShop/Program.cs | 4 +- .../BusinessLogics/ClientLogic.cs | 118 ++++++++++++++++++ .../{ => BusinessLogics}/ComponentLogic.cs | 10 +- .../{ => BusinessLogics}/OrderLogic.cs | 2 +- .../{ => BusinessLogics}/RepairLogic.cs | 2 +- .../BindingModels/ClientBindingModel.cs | 12 ++ .../BindingModels/OrderBindingModel.cs | 1 + .../BusinessLogicsContracts/IClientLogic.cs | 15 +++ .../SearchModels/ClientSearchModel.cs | 10 ++ .../SearchModels/OrderSearchModel.cs | 1 + .../StoragesContracts/IClientStorage.cs | 16 +++ .../ViewModels/ClientViewModel.cs | 16 +++ .../ViewModels/OrderViewModel.cs | 4 + .../CarRepairShopDataModels/IClientModel.cs | 9 ++ .../CarRepairShopDataModels/IOrderModel.cs | 1 + .../Implements/ClientStorage.cs | 81 ++++++++++++ .../Implements/OrderStorage.cs | 9 +- .../Models/Client.cs | 63 ++++++++++ .../Models/Order.cs | 7 ++ .../RepairsShopDatabase.cs | 1 + .../DataFileSingleton.cs | 6 + .../Implements/ClientStorage.cs | 78 ++++++++++++ .../Implements/OrderStorage.cs | 13 +- .../Models/Client.cs | 67 ++++++++++ .../Models/Order.cs | 5 + .../DataListSingleton.cs | 2 + .../Implements/ClientStorage.cs | 98 +++++++++++++++ .../Implements/OrderStorage.cs | 10 +- .../Models/Client.cs | 45 +++++++ .../Models/Order.cs | 3 + .../CarRepairShopRestApi.csproj | 19 +++ .../Controllers/ClientController.cs | 67 ++++++++++ .../Controllers/MainController.cs | 86 +++++++++++++ CarRepairShop/CarRepairShopRestApi/Program.cs | 41 ++++++ .../Properties/launchSettings.json | 31 +++++ .../appsettings.Development.json | 8 ++ .../CarRepairShopRestApi/appsettings.json | 9 ++ 38 files changed, 967 insertions(+), 15 deletions(-) create mode 100644 CarRepairShop/CarRepairShopBusinessLogic/BusinessLogics/ClientLogic.cs rename CarRepairShop/CarRepairShopBusinessLogic/{ => BusinessLogics}/ComponentLogic.cs (93%) rename CarRepairShop/CarRepairShopBusinessLogic/{ => BusinessLogics}/OrderLogic.cs (98%) rename CarRepairShop/CarRepairShopBusinessLogic/{ => BusinessLogics}/RepairLogic.cs (98%) create mode 100644 CarRepairShop/CarRepairShopContracts/BindingModels/ClientBindingModel.cs create mode 100644 CarRepairShop/CarRepairShopContracts/BusinessLogicsContracts/IClientLogic.cs create mode 100644 CarRepairShop/CarRepairShopContracts/SearchModels/ClientSearchModel.cs create mode 100644 CarRepairShop/CarRepairShopContracts/StoragesContracts/IClientStorage.cs create mode 100644 CarRepairShop/CarRepairShopContracts/ViewModels/ClientViewModel.cs create mode 100644 CarRepairShop/CarRepairShopDataModels/IClientModel.cs create mode 100644 CarRepairShop/CarRepairShopDatabaseImplement/Implements/ClientStorage.cs create mode 100644 CarRepairShop/CarRepairShopDatabaseImplement/Models/Client.cs create mode 100644 CarRepairShop/CarRepairShopFileImplement/Implements/ClientStorage.cs create mode 100644 CarRepairShop/CarRepairShopFileImplement/Models/Client.cs create mode 100644 CarRepairShop/CarRepairShopListImplement/Implements/ClientStorage.cs create mode 100644 CarRepairShop/CarRepairShopListImplement/Models/Client.cs create mode 100644 CarRepairShop/CarRepairShopRestApi/CarRepairShopRestApi.csproj create mode 100644 CarRepairShop/CarRepairShopRestApi/Controllers/ClientController.cs create mode 100644 CarRepairShop/CarRepairShopRestApi/Controllers/MainController.cs create mode 100644 CarRepairShop/CarRepairShopRestApi/Program.cs create mode 100644 CarRepairShop/CarRepairShopRestApi/Properties/launchSettings.json create mode 100644 CarRepairShop/CarRepairShopRestApi/appsettings.Development.json create mode 100644 CarRepairShop/CarRepairShopRestApi/appsettings.json diff --git a/CarRepairShop/CarRepairShop.sln b/CarRepairShop/CarRepairShop.sln index a02c51f..252684c 100644 --- a/CarRepairShop/CarRepairShop.sln +++ b/CarRepairShop/CarRepairShop.sln @@ -15,7 +15,13 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CarRepairShopListImplement" EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CarRepairShopFileImplement", "CarRepairShopFileImplement\CarRepairShopFileImplement.csproj", "{53D685FB-4609-4562-A930-49FAAB77BC9B}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CarRepairShopDatabaseImplement", "CarRepairShopDatabaseImplement\CarRepairShopDatabaseImplement.csproj", "{F1BAC88A-6D0D-4276-92C4-757F48D0D80F}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CarRepairShopDatabaseImplement", "CarRepairShopDatabaseImplement\CarRepairShopDatabaseImplement.csproj", "{F1BAC88A-6D0D-4276-92C4-757F48D0D80F}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CarRepairShopRestApi", "CarRepairShopRestApi\CarRepairShopRestApi.csproj", "{747BCB1C-6E82-4E5B-A03E-B1E66CF9182E}" + ProjectSection(ProjectDependencies) = postProject + {550ABD23-557C-41F3-97DF-DCA974DC2C91} = {550ABD23-557C-41F3-97DF-DCA974DC2C91} + {F1BAC88A-6D0D-4276-92C4-757F48D0D80F} = {F1BAC88A-6D0D-4276-92C4-757F48D0D80F} + EndProjectSection EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -51,6 +57,10 @@ Global {F1BAC88A-6D0D-4276-92C4-757F48D0D80F}.Debug|Any CPU.Build.0 = Debug|Any CPU {F1BAC88A-6D0D-4276-92C4-757F48D0D80F}.Release|Any CPU.ActiveCfg = Release|Any CPU {F1BAC88A-6D0D-4276-92C4-757F48D0D80F}.Release|Any CPU.Build.0 = Release|Any CPU + {747BCB1C-6E82-4E5B-A03E-B1E66CF9182E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {747BCB1C-6E82-4E5B-A03E-B1E66CF9182E}.Debug|Any CPU.Build.0 = Debug|Any CPU + {747BCB1C-6E82-4E5B-A03E-B1E66CF9182E}.Release|Any CPU.ActiveCfg = Release|Any CPU + {747BCB1C-6E82-4E5B-A03E-B1E66CF9182E}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/CarRepairShop/CarRepairShop/Program.cs b/CarRepairShop/CarRepairShop/Program.cs index bb24df2..3d7c198 100644 --- a/CarRepairShop/CarRepairShop/Program.cs +++ b/CarRepairShop/CarRepairShop/Program.cs @@ -1,4 +1,3 @@ -using CarRepairShopBusinessLogic; using CarRepairShopBusinessLogic.BusinessLogics; using CarRepairShopBusinessLogic.OfficePackage.Implements; using CarRepairShopBusinessLogic.OfficePackage; @@ -43,6 +42,8 @@ namespace CarRepairShop services.AddTransient(); services.AddTransient(); services.AddTransient(); + services.AddTransient(); + services.AddTransient(); services.AddTransient(); services.AddTransient(); services.AddTransient(); @@ -50,6 +51,7 @@ namespace CarRepairShop services.AddTransient(); services.AddTransient(); services.AddTransient(); + services.AddTransient(); services.AddTransient(); services.AddTransient(); services.AddTransient(); diff --git a/CarRepairShop/CarRepairShopBusinessLogic/BusinessLogics/ClientLogic.cs b/CarRepairShop/CarRepairShopBusinessLogic/BusinessLogics/ClientLogic.cs new file mode 100644 index 0000000..a05600d --- /dev/null +++ b/CarRepairShop/CarRepairShopBusinessLogic/BusinessLogics/ClientLogic.cs @@ -0,0 +1,118 @@ +using CarRepairShopContracts.BindingModels; +using CarRepairShopContracts.BusinessLogicsContracts; +using CarRepairShopContracts.SearchModels; +using CarRepairShopContracts.StoragesContracts; +using CarRepairShopContracts.ViewModels; +using Microsoft.Extensions.Logging; + +namespace CarRepairShopBusinessLogic.BusinessLogics +{ + public class ClientLogic : IClientLogic + { + private readonly ILogger _logger; + private readonly IClientStorage _clientStorage; + public ClientLogic(ILogger logger, IClientStorage + componentStorage) + { + _logger = logger; + _clientStorage = componentStorage; + } + public List? ReadList(ClientSearchModel? model) + { + _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 ClientViewModel? ReadElement(ClientSearchModel model) + { + 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 bool Create(ClientBindingModel model) + { + CheckModel(model); + if (_clientStorage.Insert(model) == null) + { + _logger.LogWarning("Insert operation failed"); + return false; + } + return true; + } + public bool Update(ClientBindingModel model) + { + CheckModel(model); + if (_clientStorage.Update(model) == null) + { + _logger.LogWarning("Update operation failed"); + return false; + } + return true; + } + public bool Delete(ClientBindingModel model) + { + CheckModel(model, false); + _logger.LogInformation("Delete. Id:{Id}", model.Id); + if (_clientStorage.Delete(model) == null) + { + _logger.LogWarning("Delete 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("Нет Email клиента", + nameof(model.ClientFIO)); + } + if (string.IsNullOrEmpty(model.Password)) + { + throw new ArgumentNullException("Нет пароля клиента", + nameof(model.ClientFIO)); + } + _logger.LogInformation("Client. ClientFIO:{ClientFIO}." + + "Email:{ Email}. Password:{ Password}. Id: { Id} ", model.ClientFIO, model.Email, model.Password, model.Id); + var element = _clientStorage.GetElement(new ClientSearchModel + { + Email = model.Email, + }); + if (element != null && element.Id != model.Id) + { + throw new InvalidOperationException("Клиент с таким логином уже есть"); + } + } + } +} diff --git a/CarRepairShop/CarRepairShopBusinessLogic/ComponentLogic.cs b/CarRepairShop/CarRepairShopBusinessLogic/BusinessLogics/ComponentLogic.cs similarity index 93% rename from CarRepairShop/CarRepairShopBusinessLogic/ComponentLogic.cs rename to CarRepairShop/CarRepairShopBusinessLogic/BusinessLogics/ComponentLogic.cs index 880be09..811a251 100644 --- a/CarRepairShop/CarRepairShopBusinessLogic/ComponentLogic.cs +++ b/CarRepairShop/CarRepairShopBusinessLogic/BusinessLogics/ComponentLogic.cs @@ -5,7 +5,7 @@ using CarRepairShopContracts.StoragesContracts; using CarRepairShopContracts.ViewModels; using Microsoft.Extensions.Logging; -namespace CarRepairShopBusinessLogic +namespace CarRepairShopBusinessLogic.BusinessLogics { public class ComponentLogic : IComponentLogic { @@ -19,8 +19,8 @@ namespace CarRepairShopBusinessLogic public List? ReadList(ComponentSearchModel? model) { _logger.LogInformation("ReadList. ComponentName:{ComponentName}.Id:{ Id}", model?.ComponentName, model?.Id); - var list = model == null ? _componentStorage.GetFullList() : - _componentStorage.GetFilteredList(model); + var list = model == null ? _componentStorage.GetFullList() : + _componentStorage.GetFilteredList(model); if (list == null) { _logger.LogWarning("ReadList return null list"); @@ -36,7 +36,7 @@ namespace CarRepairShopBusinessLogic throw new ArgumentNullException(nameof(model)); } _logger.LogInformation("ReadElement. ComponentName:{ComponentName}.Id:{ Id}", model.ComponentName, model.Id); - var element = _componentStorage.GetElement(model); + var element = _componentStorage.GetElement(model); if (element == null) { _logger.LogWarning("ReadElement element not found"); @@ -98,7 +98,7 @@ namespace CarRepairShopBusinessLogic _logger.LogInformation("Component. ComponentName:{ComponentName}. Cost:{ Cost}. Id: { Id}", model.ComponentName, model.Cost, model.Id); var element = _componentStorage.GetElement(new ComponentSearchModel { - ComponentName = model.ComponentName + ComponentName = model.ComponentName }); if (element != null && element.Id != model.Id) { diff --git a/CarRepairShop/CarRepairShopBusinessLogic/OrderLogic.cs b/CarRepairShop/CarRepairShopBusinessLogic/BusinessLogics/OrderLogic.cs similarity index 98% rename from CarRepairShop/CarRepairShopBusinessLogic/OrderLogic.cs rename to CarRepairShop/CarRepairShopBusinessLogic/BusinessLogics/OrderLogic.cs index c00d197..acd49da 100644 --- a/CarRepairShop/CarRepairShopBusinessLogic/OrderLogic.cs +++ b/CarRepairShop/CarRepairShopBusinessLogic/BusinessLogics/OrderLogic.cs @@ -6,7 +6,7 @@ using CarRepairShopContracts.ViewModels; using CarRepairShopDataModels.Enums; using Microsoft.Extensions.Logging; -namespace CarRepairShopBusinessLogic +namespace CarRepairShopBusinessLogic.BusinessLogics { public class OrderLogic : IOrderLogic { diff --git a/CarRepairShop/CarRepairShopBusinessLogic/RepairLogic.cs b/CarRepairShop/CarRepairShopBusinessLogic/BusinessLogics/RepairLogic.cs similarity index 98% rename from CarRepairShop/CarRepairShopBusinessLogic/RepairLogic.cs rename to CarRepairShop/CarRepairShopBusinessLogic/BusinessLogics/RepairLogic.cs index 1c80564..6db13a7 100644 --- a/CarRepairShop/CarRepairShopBusinessLogic/RepairLogic.cs +++ b/CarRepairShop/CarRepairShopBusinessLogic/BusinessLogics/RepairLogic.cs @@ -5,7 +5,7 @@ using CarRepairShopContracts.StoragesContracts; using CarRepairShopContracts.ViewModels; using Microsoft.Extensions.Logging; -namespace CarRepairShopBusinessLogic +namespace CarRepairShopBusinessLogic.BusinessLogics { public class RepairLogic : IRepairLogic { diff --git a/CarRepairShop/CarRepairShopContracts/BindingModels/ClientBindingModel.cs b/CarRepairShop/CarRepairShopContracts/BindingModels/ClientBindingModel.cs new file mode 100644 index 0000000..d80762e --- /dev/null +++ b/CarRepairShop/CarRepairShopContracts/BindingModels/ClientBindingModel.cs @@ -0,0 +1,12 @@ +using CarRepairShopDataModels; + +namespace CarRepairShopContracts.BindingModels +{ + public class ClientBindingModel : IClientModel + { + public int Id { get; set; } + public string ClientFIO { get; set; } = string.Empty; + public string Email { get; set; } = string.Empty; + public string Password { get; set; } = string.Empty; + } +} diff --git a/CarRepairShop/CarRepairShopContracts/BindingModels/OrderBindingModel.cs b/CarRepairShop/CarRepairShopContracts/BindingModels/OrderBindingModel.cs index 9f23e56..8708051 100644 --- a/CarRepairShop/CarRepairShopContracts/BindingModels/OrderBindingModel.cs +++ b/CarRepairShop/CarRepairShopContracts/BindingModels/OrderBindingModel.cs @@ -7,6 +7,7 @@ namespace CarRepairShopContracts.BindingModels { public int Id { get; set; } public int RepairId { get; set; } + public int ClientId { get; set; } public int Count { get; set; } public double Sum { get; set; } public OrderStatus Status { get; set; } = OrderStatus.Неизвестен; diff --git a/CarRepairShop/CarRepairShopContracts/BusinessLogicsContracts/IClientLogic.cs b/CarRepairShop/CarRepairShopContracts/BusinessLogicsContracts/IClientLogic.cs new file mode 100644 index 0000000..7b8423f --- /dev/null +++ b/CarRepairShop/CarRepairShopContracts/BusinessLogicsContracts/IClientLogic.cs @@ -0,0 +1,15 @@ +using CarRepairShopContracts.BindingModels; +using CarRepairShopContracts.SearchModels; +using CarRepairShopContracts.ViewModels; + +namespace CarRepairShopContracts.BusinessLogicsContracts +{ + public interface IClientLogic + { + List? ReadList(ClientSearchModel? model); + ClientViewModel? ReadElement(ClientSearchModel model); + bool Create(ClientBindingModel model); + bool Update(ClientBindingModel model); + bool Delete(ClientBindingModel model); + } +} diff --git a/CarRepairShop/CarRepairShopContracts/SearchModels/ClientSearchModel.cs b/CarRepairShop/CarRepairShopContracts/SearchModels/ClientSearchModel.cs new file mode 100644 index 0000000..7403255 --- /dev/null +++ b/CarRepairShop/CarRepairShopContracts/SearchModels/ClientSearchModel.cs @@ -0,0 +1,10 @@ +namespace CarRepairShopContracts.SearchModels +{ + public class ClientSearchModel + { + public int? Id { get; set; } + public string? ClientFIO { get; set; } + public string? Email { get; set; } + public string? Password { get; set; } + } +} diff --git a/CarRepairShop/CarRepairShopContracts/SearchModels/OrderSearchModel.cs b/CarRepairShop/CarRepairShopContracts/SearchModels/OrderSearchModel.cs index ebff88e..74ad8e0 100644 --- a/CarRepairShop/CarRepairShopContracts/SearchModels/OrderSearchModel.cs +++ b/CarRepairShop/CarRepairShopContracts/SearchModels/OrderSearchModel.cs @@ -3,6 +3,7 @@ public class OrderSearchModel { public int? Id { get; set; } + public int? ClientId { get; set; } public DateTime? DateFrom { get; set; } public DateTime? DateTo { get; set;} } diff --git a/CarRepairShop/CarRepairShopContracts/StoragesContracts/IClientStorage.cs b/CarRepairShop/CarRepairShopContracts/StoragesContracts/IClientStorage.cs new file mode 100644 index 0000000..f039863 --- /dev/null +++ b/CarRepairShop/CarRepairShopContracts/StoragesContracts/IClientStorage.cs @@ -0,0 +1,16 @@ +using CarRepairShopContracts.BindingModels; +using CarRepairShopContracts.SearchModels; +using CarRepairShopContracts.ViewModels; + +namespace CarRepairShopContracts.StoragesContracts +{ + public interface IClientStorage + { + List GetFullList(); + List GetFilteredList(ClientSearchModel model); + ClientViewModel? GetElement(ClientSearchModel model); + ClientViewModel? Insert(ClientBindingModel model); + ClientViewModel? Update(ClientBindingModel model); + ClientViewModel? Delete(ClientBindingModel model); + } +} diff --git a/CarRepairShop/CarRepairShopContracts/ViewModels/ClientViewModel.cs b/CarRepairShop/CarRepairShopContracts/ViewModels/ClientViewModel.cs new file mode 100644 index 0000000..67aa5d3 --- /dev/null +++ b/CarRepairShop/CarRepairShopContracts/ViewModels/ClientViewModel.cs @@ -0,0 +1,16 @@ +using CarRepairShopDataModels; +using System.ComponentModel; + +namespace CarRepairShopContracts.ViewModels +{ + public class ClientViewModel : IClientModel + { + public int Id { get; set; } + [DisplayName("ФИО клиента")] + public string ClientFIO { get; set; } = string.Empty; + [DisplayName("Логин (эл. почта)")] + public string Email { get; set; } = string.Empty; + [DisplayName("Пароль")] + public string Password { get; set; } = string.Empty; + } +} diff --git a/CarRepairShop/CarRepairShopContracts/ViewModels/OrderViewModel.cs b/CarRepairShop/CarRepairShopContracts/ViewModels/OrderViewModel.cs index d5ea81b..674830c 100644 --- a/CarRepairShop/CarRepairShopContracts/ViewModels/OrderViewModel.cs +++ b/CarRepairShop/CarRepairShopContracts/ViewModels/OrderViewModel.cs @@ -12,6 +12,10 @@ namespace CarRepairShopContracts.ViewModels public int RepairId { get; set; } [DisplayName("Ремонт")] public string RepairName { get; set; } = string.Empty; + public int ClientId { get; set; } + [DisplayName("Клиент")] + public string ClientFIO { get; set; } = string.Empty; + [DisplayName("Количество")] public int Count { get; set; } [DisplayName("Сумма")] diff --git a/CarRepairShop/CarRepairShopDataModels/IClientModel.cs b/CarRepairShop/CarRepairShopDataModels/IClientModel.cs new file mode 100644 index 0000000..62cac8c --- /dev/null +++ b/CarRepairShop/CarRepairShopDataModels/IClientModel.cs @@ -0,0 +1,9 @@ +namespace CarRepairShopDataModels +{ + public interface IClientModel : IId + { + string ClientFIO { get; } + string Email { get; } + string Password { get; } + } +} diff --git a/CarRepairShop/CarRepairShopDataModels/IOrderModel.cs b/CarRepairShop/CarRepairShopDataModels/IOrderModel.cs index 484696d..2dae534 100644 --- a/CarRepairShop/CarRepairShopDataModels/IOrderModel.cs +++ b/CarRepairShop/CarRepairShopDataModels/IOrderModel.cs @@ -5,6 +5,7 @@ namespace CarRepairShopDataModels public interface IOrderModel { int RepairId { get; } + int ClientId { get; } int Count { get; } double Sum { get; } OrderStatus Status { get; } diff --git a/CarRepairShop/CarRepairShopDatabaseImplement/Implements/ClientStorage.cs b/CarRepairShop/CarRepairShopDatabaseImplement/Implements/ClientStorage.cs new file mode 100644 index 0000000..f534769 --- /dev/null +++ b/CarRepairShop/CarRepairShopDatabaseImplement/Implements/ClientStorage.cs @@ -0,0 +1,81 @@ +using CarRepairShopContracts.BindingModels; +using CarRepairShopContracts.SearchModels; +using CarRepairShopContracts.StoragesContracts; +using CarRepairShopContracts.ViewModels; +using CarRepairShopDatabaseImplement.Models; + +namespace CarRepairShopDatabaseImplement.Implements +{ + public class ClientStorage : IClientStorage + { + public List GetFullList() + { + using var context = new RepairsShopDatabase(); + return context.Clients + .Select(x => x.GetViewModel) + .ToList(); + } + public List GetFilteredList(ClientSearchModel model) + { + if (string.IsNullOrEmpty(model.ClientFIO) && string.IsNullOrEmpty(model.Email)) + { + return new(); + } + using var context = new RepairsShopDatabase(); + return context.Clients + .Where(x => (string.IsNullOrEmpty(model.ClientFIO) || x.ClientFIO.Contains(model.ClientFIO) && + (string.IsNullOrEmpty(model.Email) || x.ClientFIO.Contains(model.Email)))) + .Select(x => x.GetViewModel) + .ToList(); + } + public ClientViewModel? GetElement(ClientSearchModel model) + { + if (string.IsNullOrEmpty(model.ClientFIO) && string.IsNullOrEmpty(model.Email) && + !model.Id.HasValue) + { + return null; + } + using var context = new RepairsShopDatabase(); + return context.Clients + .FirstOrDefault(x => (string.IsNullOrEmpty(model.ClientFIO) || x.ClientFIO == model.ClientFIO) && + (!model.Id.HasValue || x.Id == model.Id) && (string.IsNullOrEmpty(model.Email) || x.Email == model.Email)) + ?.GetViewModel; + } + public ClientViewModel? Insert(ClientBindingModel model) + { + var newClient = Client.Create(model); + if (newClient == null) + { + return null; + } + using var context = new RepairsShopDatabase(); + context.Clients.Add(newClient); + context.SaveChanges(); + return newClient.GetViewModel; + } + public ClientViewModel? Update(ClientBindingModel model) + { + using var context = new RepairsShopDatabase(); + var client = context.Clients.FirstOrDefault(x => x.Id == model.Id); + if (client == null) + { + return null; + } + client.Update(model); + context.SaveChanges(); + return client.GetViewModel; + } + public ClientViewModel? Delete(ClientBindingModel model) + { + using var context = new RepairsShopDatabase(); + var element = context.Clients.FirstOrDefault(rec => rec.Id == model.Id); + if (element != null) + { + context.Clients.Remove(element); + context.SaveChanges(); + return element.GetViewModel; + } + return null; + } + } +} diff --git a/CarRepairShop/CarRepairShopDatabaseImplement/Implements/OrderStorage.cs b/CarRepairShop/CarRepairShopDatabaseImplement/Implements/OrderStorage.cs index d4f9aae..fe02f3a 100644 --- a/CarRepairShop/CarRepairShopDatabaseImplement/Implements/OrderStorage.cs +++ b/CarRepairShop/CarRepairShopDatabaseImplement/Implements/OrderStorage.cs @@ -22,7 +22,8 @@ namespace CarRepairShopDatabaseImplement.Implements return context.Orders .Where(x => ((!model.Id.HasValue || x.Id == model.Id) && (!model.DateFrom.HasValue || x.DateCreate >= model.DateFrom) && - (!model.DateTo.HasValue || x.DateCreate <= model.DateTo))) + (!model.DateTo.HasValue || x.DateCreate <= model.DateTo) && + (!model.ClientId.HasValue || x.ClientId == model.ClientId))) .Select(x => x.GetViewModel) .ToList(); } @@ -33,7 +34,7 @@ namespace CarRepairShopDatabaseImplement.Implements return null; } using var context = new RepairsShopDatabase(); - return context.Orders.FirstOrDefault(x => x.Id == model.Id)?.GetViewModel; + return context.Orders.Include(x => x.Repair).Include(x => x.Client).FirstOrDefault(x => x.Id == model.Id)?.GetViewModel; } public OrderViewModel? Insert(OrderBindingModel model) { @@ -50,7 +51,7 @@ namespace CarRepairShopDatabaseImplement.Implements public OrderViewModel? Update(OrderBindingModel model) { using var context = new RepairsShopDatabase(); - var order = context.Orders.FirstOrDefault(x => x.Id == + var order = context.Orders.Include(x => x.Repair).Include(x => x.Client).FirstOrDefault(x => x.Id == model.Id); if (order == null) { @@ -63,7 +64,7 @@ namespace CarRepairShopDatabaseImplement.Implements public OrderViewModel? Delete(OrderBindingModel model) { using var context = new RepairsShopDatabase(); - var element = context.Orders.FirstOrDefault(rec => rec.Id == + var element = context.Orders.Include(x => x.Repair).Include(x => x.Client).FirstOrDefault(rec => rec.Id == model.Id); if (element != null) { diff --git a/CarRepairShop/CarRepairShopDatabaseImplement/Models/Client.cs b/CarRepairShop/CarRepairShopDatabaseImplement/Models/Client.cs new file mode 100644 index 0000000..5c6f070 --- /dev/null +++ b/CarRepairShop/CarRepairShopDatabaseImplement/Models/Client.cs @@ -0,0 +1,63 @@ +using CarRepairShopContracts.BindingModels; +using CarRepairShopContracts.ViewModels; +using CarRepairShopDataModels; +using System.ComponentModel.DataAnnotations.Schema; +using System.ComponentModel.DataAnnotations; + +namespace CarRepairShopDatabaseImplement.Models +{ + public class Client : IClientModel + { + public int Id { get; private set; } + [Required] + public string ClientFIO { get; private set; } = string.Empty; + [Required] + public string Email { get; set; } = string.Empty; + [Required] + public string Password { get; set; } = string.Empty; + [ForeignKey("ClientId")] + public virtual List Orders { get; set; } = + new(); + public static Client? Create(ClientBindingModel model) + { + if (model == null) + { + return null; + } + return new Client() + { + Id = model.Id, + ClientFIO = model.ClientFIO, + Email = model.Email, + Password = model.Password + }; + } + public static Client Create(ClientViewModel model) + { + return new Client() + { + Id = model.Id, + ClientFIO = model.ClientFIO, + Email = model.Email, + Password = model.Password + }; + } + public void Update(ClientBindingModel model) + { + if (model == null) + { + return; + } + ClientFIO = model.ClientFIO; + Email = model.Email; + Password = model.Password; + } + public ClientViewModel GetViewModel => new() + { + Id = Id, + ClientFIO = ClientFIO, + Email = Email, + Password = Password + }; + } +} diff --git a/CarRepairShop/CarRepairShopDatabaseImplement/Models/Order.cs b/CarRepairShop/CarRepairShopDatabaseImplement/Models/Order.cs index 86c3047..9ba1064 100644 --- a/CarRepairShop/CarRepairShopDatabaseImplement/Models/Order.cs +++ b/CarRepairShop/CarRepairShopDatabaseImplement/Models/Order.cs @@ -19,6 +19,10 @@ namespace CarRepairShopDatabaseImplement.Models public DateTime? DateImplement { get; private set; } [Required] public int RepairId { get; private set; } + public virtual Repair? Repairs { get; private set; } + [Required] + public int ClientId { get; private set; } + public virtual Client? Client { get; private set; } public virtual Repair? Repair { get; set; } public static Order? Create(OrderBindingModel model) @@ -32,6 +36,7 @@ namespace CarRepairShopDatabaseImplement.Models DateCreate = model.DateCreate, DateImplement = model.DateImplement, RepairId = model.RepairId, + ClientId = model.ClientId, }; } @@ -48,7 +53,9 @@ namespace CarRepairShopDatabaseImplement.Models public OrderViewModel GetViewModel => new() { RepairId = RepairId, + ClientId = ClientId, RepairName = Repair?.RepairName ?? string.Empty, + ClientFIO = Client?.ClientFIO ?? string.Empty, Count = Count, Sum = Sum, Status = Status, diff --git a/CarRepairShop/CarRepairShopDatabaseImplement/RepairsShopDatabase.cs b/CarRepairShop/CarRepairShopDatabaseImplement/RepairsShopDatabase.cs index 089eea5..74ec3f3 100644 --- a/CarRepairShop/CarRepairShopDatabaseImplement/RepairsShopDatabase.cs +++ b/CarRepairShop/CarRepairShopDatabaseImplement/RepairsShopDatabase.cs @@ -18,5 +18,6 @@ namespace CarRepairShopDatabaseImplement public virtual DbSet Repairs { set; get; } public virtual DbSet RepairComponents { set; get; } public virtual DbSet Orders { set; get; } + public virtual DbSet Clients { set; get; } } } diff --git a/CarRepairShop/CarRepairShopFileImplement/DataFileSingleton.cs b/CarRepairShop/CarRepairShopFileImplement/DataFileSingleton.cs index 2210ec9..a81b6bc 100644 --- a/CarRepairShop/CarRepairShopFileImplement/DataFileSingleton.cs +++ b/CarRepairShop/CarRepairShopFileImplement/DataFileSingleton.cs @@ -9,9 +9,11 @@ namespace CarRepairShopFileImplement private readonly string ComponentFileName = "Component.xml"; private readonly string OrderFileName = "Order.xml"; private readonly string RepairFileName = "Repair.xml"; + private readonly string ClientFileName = "Client.xml"; public List Components { get; private set; } public List Orders { get; private set; } public List Repairs { get; private set; } + public List Clients { get; private set; } public static DataFileSingleton GetInstance() { if (instance == null) @@ -26,6 +28,8 @@ namespace CarRepairShopFileImplement "Repairs", x => x.GetXElement); public void SaveOrders() => SaveData(Orders, OrderFileName, "Orders", x => x.GetXElement); + public void SaveClients() => SaveData(Clients, ClientFileName, + "Clients", x => x.GetXElement); private DataFileSingleton() { Components = LoadData(ComponentFileName, "Component", x => @@ -34,6 +38,8 @@ namespace CarRepairShopFileImplement Repair.Create(x)!)!; Orders = LoadData(OrderFileName, "Order", x => Order.Create(x)!)!; + Clients = LoadData(ClientFileName, "Client", x => + Client.Create(x)!)!; } private static List? LoadData(string filename, string xmlNodeName, Func selectFunction) diff --git a/CarRepairShop/CarRepairShopFileImplement/Implements/ClientStorage.cs b/CarRepairShop/CarRepairShopFileImplement/Implements/ClientStorage.cs new file mode 100644 index 0000000..8a6b4a5 --- /dev/null +++ b/CarRepairShop/CarRepairShopFileImplement/Implements/ClientStorage.cs @@ -0,0 +1,78 @@ +using CarRepairShopContracts.BindingModels; +using CarRepairShopContracts.SearchModels; +using CarRepairShopContracts.StoragesContracts; +using CarRepairShopContracts.ViewModels; +using CarRepairShopFileImplement.Models; + +namespace CarRepairShopFileImplement.Implements +{ + public class ClientStorage : IClientStorage + { + private readonly DataFileSingleton source; + public ClientStorage() + { + source = DataFileSingleton.GetInstance(); + } + public List GetFullList() + { + return source.Clients + .Select(x => x.GetViewModel) + .ToList(); + } + public List GetFilteredList(ClientSearchModel + model) + { + if (string.IsNullOrEmpty(model.ClientFIO) && string.IsNullOrEmpty(model.Email)) + { + return new(); + } + return source.Clients + .Where(x => (string.IsNullOrEmpty(model.ClientFIO) || x.ClientFIO.Contains(model.ClientFIO) && + (string.IsNullOrEmpty(model.Email) || x.ClientFIO.Contains(model.Email)))) + .Select(x => x.GetViewModel) + .ToList(); + } + public ClientViewModel? GetElement(ClientSearchModel model) + { + return source.Clients + .FirstOrDefault(x => (string.IsNullOrEmpty(model.ClientFIO) || x.ClientFIO == model.ClientFIO) && + (!model.Id.HasValue || x.Id == model.Id) && (string.IsNullOrEmpty(model.Email) || x.Email == model.Email)) + ?.GetViewModel; + } + public ClientViewModel? Insert(ClientBindingModel model) + { + model.Id = source.Clients.Count > 0 ? source.Clients.Max(x => + x.Id) + 1 : 1; + var newClient = Client.Create(model); + if (newClient == null) + { + return null; + } + source.Clients.Add(newClient); + source.SaveClients(); + return newClient.GetViewModel; + } + public ClientViewModel? Update(ClientBindingModel model) + { + var client = source.Clients.FirstOrDefault(x => x.Id == model.Id); + if (client == null) + { + return null; + } + client.Update(model); + source.SaveClients(); + return client.GetViewModel; + } + public ClientViewModel? Delete(ClientBindingModel model) + { + var element = source.Clients.FirstOrDefault(rec => rec.Id == model.Id); + if (element != null) + { + source.Clients.Remove(element); + source.SaveClients(); + return element.GetViewModel; + } + return null; + } + } +} diff --git a/CarRepairShop/CarRepairShopFileImplement/Implements/OrderStorage.cs b/CarRepairShop/CarRepairShopFileImplement/Implements/OrderStorage.cs index 5c6cf88..ce6243b 100644 --- a/CarRepairShop/CarRepairShopFileImplement/Implements/OrderStorage.cs +++ b/CarRepairShop/CarRepairShopFileImplement/Implements/OrderStorage.cs @@ -23,7 +23,8 @@ namespace CarRepairShopFileImplement.Implements { return source.Orders.Where(x => ((!model.Id.HasValue || x.Id == model.Id) && (!model.DateFrom.HasValue || x.DateCreate >= model.DateFrom) && - (!model.DateTo.HasValue || x.DateCreate <= model.DateTo))) + (!model.DateTo.HasValue || x.DateCreate <= model.DateTo) && + (!model.ClientId.HasValue || x.ClientId == model.ClientId))) .Select(x => AccessRepairStorage(x.GetViewModel)).ToList(); } public OrderViewModel? GetElement(OrderSearchModel model) @@ -83,5 +84,15 @@ namespace CarRepairShopFileImplement.Implements } return model; } + + public OrderViewModel AccessClientStorage(OrderViewModel model) + { + if (model == null) + return null; + var client = source.Clients.FirstOrDefault(x => x.Id == model.Id); + if (client != null) + model.ClientFIO = client.ClientFIO; + return model; + } } } diff --git a/CarRepairShop/CarRepairShopFileImplement/Models/Client.cs b/CarRepairShop/CarRepairShopFileImplement/Models/Client.cs new file mode 100644 index 0000000..2f9708d --- /dev/null +++ b/CarRepairShop/CarRepairShopFileImplement/Models/Client.cs @@ -0,0 +1,67 @@ +using CarRepairShopContracts.BindingModels; +using CarRepairShopContracts.ViewModels; +using CarRepairShopDataModels; +using System.Xml.Linq; + +namespace CarRepairShopFileImplement.Models +{ + public class Client : IClientModel + { + public int Id { get; private set; } + public string ClientFIO { get; private set; } = string.Empty; + public string Email { get; set; } = string.Empty; + public string Password { get; set; } = string.Empty; + public static Client? Create(ClientBindingModel model) + { + if (model == null) + { + return null; + } + return new Client() + { + Id = model.Id, + ClientFIO = model.ClientFIO, + Email = model.Email, + Password = model.Password + }; + } + public static Client? Create(XElement element) + { + if (element == null) + { + return null; + } + return new Client() + { + Id = Convert.ToInt32(element.Attribute("Id")!.Value), + ClientFIO = element.Element("ClientFIO")!.Value, + Email = element.Element("Email")!.Value, + Password = element.Element("Password")!.Value + }; + } + public void Update(ClientBindingModel model) + { + if (model == null) + { + return; + } + ClientFIO = model.ClientFIO; + Email = model.Email; + Password = model.Password; + } + public ClientViewModel GetViewModel => new() + { + Id = Id, + ClientFIO = ClientFIO, + Email = Email, + Password = Password + }; + + public XElement GetXElement => new("Client", + new XAttribute("Id", Id), + new XElement("ClientFIO", ClientFIO), + new XElement("Email", Email.ToString()), + new XElement("Password", Password.ToString()) + ); + } +} diff --git a/CarRepairShop/CarRepairShopFileImplement/Models/Order.cs b/CarRepairShop/CarRepairShopFileImplement/Models/Order.cs index 51dfdbf..efbba77 100644 --- a/CarRepairShop/CarRepairShopFileImplement/Models/Order.cs +++ b/CarRepairShop/CarRepairShopFileImplement/Models/Order.cs @@ -10,6 +10,7 @@ namespace CarRepairShopFileImplement.Models { public int Id { get; private set; } public int RepairId { get; private set; } + public int ClientId { get; private set; } public int Count { get; private set; } public double Sum { get; private set; } public OrderStatus Status { get; private set; } @@ -26,6 +27,7 @@ namespace CarRepairShopFileImplement.Models { Id = model.Id, RepairId = model.RepairId, + ClientId = model.ClientId, Count = model.Count, Sum = model.Sum, Status = model.Status, @@ -43,6 +45,7 @@ namespace CarRepairShopFileImplement.Models { Id = Convert.ToInt32(element.Attribute("Id")!.Value), RepairId = Convert.ToInt32(element.Element("RepairId")!.Value), + ClientId = Convert.ToInt32(element.Element("ClientId")!.Value), Count = Convert.ToInt32(element.Element("Count")!.Value), Sum = Convert.ToDouble(element.Element("Sum")!.Value), Status = (OrderStatus)Enum.Parse(typeof(OrderStatus), element.Element("Status")!.Value.ToString()), @@ -63,6 +66,7 @@ namespace CarRepairShopFileImplement.Models { Id = Id, RepairId = RepairId, + ClientId = ClientId, Count = Count, Sum = Sum, Status = Status, @@ -72,6 +76,7 @@ namespace CarRepairShopFileImplement.Models public XElement GetXElement => new("Order", new XAttribute("Id", Id), new XElement("RepairId", RepairId), + new XElement("ClientId", ClientId), new XElement("Sum", Sum.ToString()), new XElement("Count", Count), new XElement("Status", Status.ToString()), diff --git a/CarRepairShop/CarRepairShopListImplement/DataListSingleton.cs b/CarRepairShop/CarRepairShopListImplement/DataListSingleton.cs index d2f576d..ecf828b 100644 --- a/CarRepairShop/CarRepairShopListImplement/DataListSingleton.cs +++ b/CarRepairShop/CarRepairShopListImplement/DataListSingleton.cs @@ -8,11 +8,13 @@ namespace CarRepairShopListImplement public List Components { get; set; } public List Orders { get; set; } public List Repairs { get; set; } + public List Clients { get; set; } private DataListSingleton() { Components = new List(); Orders = new List(); Repairs = new List(); + Clients = new List(); } public static DataListSingleton GetInstance() { diff --git a/CarRepairShop/CarRepairShopListImplement/Implements/ClientStorage.cs b/CarRepairShop/CarRepairShopListImplement/Implements/ClientStorage.cs new file mode 100644 index 0000000..b64ca54 --- /dev/null +++ b/CarRepairShop/CarRepairShopListImplement/Implements/ClientStorage.cs @@ -0,0 +1,98 @@ +using CarRepairShopContracts.BindingModels; +using CarRepairShopContracts.SearchModels; +using CarRepairShopContracts.StoragesContracts; +using CarRepairShopContracts.ViewModels; +using CarRepairShopListImplement.Models; + +namespace CarRepairShopListImplement.Implements +{ + public class ClientStorage : IClientStorage + { + private readonly DataListSingleton _source; + public ClientStorage() + { + _source = DataListSingleton.GetInstance(); + } + public List GetFullList() + { + var result = new List(); + foreach (var client in _source.Clients) + { + result.Add(client.GetViewModel); + } + return result; + } + public List GetFilteredList(ClientSearchModel + model) + { + var result = new List(); + if (string.IsNullOrEmpty(model.ClientFIO) && string.IsNullOrEmpty(model.Email)) + { + return result; + } + foreach (var client in _source.Clients) + { + if (client.ClientFIO.Contains(model.ClientFIO)) + { + result.Add(client.GetViewModel); + } + } + return result; + } + public ClientViewModel? GetElement(ClientSearchModel model) + { + foreach (var client in _source.Clients) + { + if ((string.IsNullOrEmpty(model.ClientFIO) || client.ClientFIO == model.ClientFIO) && + (!model.Id.HasValue || client.Id == model.Id) && (string.IsNullOrEmpty(model.Email) || client.Email == model.Email)) + { + return client.GetViewModel; + } + } + return null; + } + public ClientViewModel? Insert(ClientBindingModel model) + { + model.Id = 1; + foreach (var client in _source.Clients) + { + if (model.Id <= client.Id) + { + model.Id = client.Id + 1; + } + } + var newClient = Client.Create(model); + if (newClient == null) + { + return null; + } + _source.Clients.Add(newClient); + return newClient.GetViewModel; + } + public ClientViewModel? Update(ClientBindingModel model) + { + foreach (var client in _source.Clients) + { + if (client.Id == model.Id) + { + client.Update(model); + return client.GetViewModel; + } + } + return null; + } + public ClientViewModel? Delete(ClientBindingModel model) + { + for (int i = 0; i < _source.Clients.Count; ++i) + { + if (_source.Clients[i].Id == model.Id) + { + var element = _source.Clients[i]; + _source.Clients.RemoveAt(i); + return element.GetViewModel; + } + } + return null; + } + } +} diff --git a/CarRepairShop/CarRepairShopListImplement/Implements/OrderStorage.cs b/CarRepairShop/CarRepairShopListImplement/Implements/OrderStorage.cs index 579a78a..208fdc5 100644 --- a/CarRepairShop/CarRepairShopListImplement/Implements/OrderStorage.cs +++ b/CarRepairShop/CarRepairShopListImplement/Implements/OrderStorage.cs @@ -29,7 +29,8 @@ namespace CarRepairShopListImplement.Implements { if ((!model.Id.HasValue || order.Id == model.Id) && (!model.DateFrom.HasValue || order.DateCreate >= model.DateFrom) && - (!model.DateTo.HasValue || order.DateCreate <= model.DateTo)) + (!model.DateTo.HasValue || order.DateCreate <= model.DateTo) && + (!model.ClientId.HasValue || order.ClientId == model.ClientId)) { result.Add(AccessRepairStorage(order.GetViewModel)); } @@ -107,5 +108,12 @@ namespace CarRepairShopListImplement.Implements } return model; } + public OrderViewModel AccessClientStorage(OrderViewModel model) + { + var client = _source.Clients.FirstOrDefault(x => x.Id == model.ClientId); + if (client != null) + model.ClientFIO = client.ClientFIO; + return model; + } } } diff --git a/CarRepairShop/CarRepairShopListImplement/Models/Client.cs b/CarRepairShop/CarRepairShopListImplement/Models/Client.cs new file mode 100644 index 0000000..fa14b5d --- /dev/null +++ b/CarRepairShop/CarRepairShopListImplement/Models/Client.cs @@ -0,0 +1,45 @@ +using CarRepairShopContracts.BindingModels; +using CarRepairShopContracts.ViewModels; +using CarRepairShopDataModels; + +namespace CarRepairShopListImplement.Models +{ + public class Client : IClientModel + { + public int Id { get; private set; } + public string ClientFIO { get; private set; } = string.Empty; + public string Email { get; set; } = string.Empty; + public string Password { get; set; } = string.Empty; + public static Client? Create(ClientBindingModel model) + { + if (model == null) + { + return null; + } + return new Client() + { + Id = model.Id, + ClientFIO = model.ClientFIO, + Email = model.Email, + Password = model.Password + }; + } + public void Update(ClientBindingModel model) + { + if (model == null) + { + return; + } + ClientFIO = model.ClientFIO; + Email = model.Email; + Password = model.Password; + } + public ClientViewModel GetViewModel => new() + { + Id = Id, + ClientFIO = ClientFIO, + Email = Email, + Password = Password + }; + } +} diff --git a/CarRepairShop/CarRepairShopListImplement/Models/Order.cs b/CarRepairShop/CarRepairShopListImplement/Models/Order.cs index 74962bc..cf0be57 100644 --- a/CarRepairShop/CarRepairShopListImplement/Models/Order.cs +++ b/CarRepairShop/CarRepairShopListImplement/Models/Order.cs @@ -8,6 +8,7 @@ namespace CarRepairShopListImplement.Models public class Order : IOrderModel { public int RepairId { get; private set; } + public int ClientId { get; private set; } public int Count { get; private set; } public double Sum { get; private set; } public OrderStatus Status { get; private set; } = OrderStatus.Неизвестен; @@ -23,6 +24,7 @@ namespace CarRepairShopListImplement.Models return new Order { RepairId = model.RepairId, + ClientId = model.ClientId, Count = model.Count, Sum = model.Sum, Status = model.Status, @@ -43,6 +45,7 @@ namespace CarRepairShopListImplement.Models public OrderViewModel GetViewModel => new() { RepairId = RepairId, + ClientId = ClientId, Count = Count, Sum = Sum, DateCreate = DateCreate, diff --git a/CarRepairShop/CarRepairShopRestApi/CarRepairShopRestApi.csproj b/CarRepairShop/CarRepairShopRestApi/CarRepairShopRestApi.csproj new file mode 100644 index 0000000..9b4fb1b --- /dev/null +++ b/CarRepairShop/CarRepairShopRestApi/CarRepairShopRestApi.csproj @@ -0,0 +1,19 @@ + + + + net6.0 + enable + enable + + + + + + + + + + + + + diff --git a/CarRepairShop/CarRepairShopRestApi/Controllers/ClientController.cs b/CarRepairShop/CarRepairShopRestApi/Controllers/ClientController.cs new file mode 100644 index 0000000..308bb66 --- /dev/null +++ b/CarRepairShop/CarRepairShopRestApi/Controllers/ClientController.cs @@ -0,0 +1,67 @@ +using CarRepairShopContracts.BindingModels; +using CarRepairShopContracts.BusinessLogicsContracts; +using CarRepairShopContracts.SearchModels; +using CarRepairShopContracts.ViewModels; +using Microsoft.AspNetCore.Mvc; + +namespace CarRepairShopRestApi.Controllers +{ + [Route("api/[controller]/[action]")] + [ApiController] + public class ClientController : Controller + { + private readonly ILogger _logger; + private readonly IClientLogic _logic; + public ClientController(IClientLogic logic, ILogger + logger) + { + _logger = logger; + _logic = logic; + } + [HttpGet] + public ClientViewModel? Login(string login, string password) + { + try + { + return _logic.ReadElement(new ClientSearchModel + { + Email = login, + Password = password + }); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка входа в систему"); + throw; + } + } + [HttpPost] + public void Register(ClientBindingModel model) + { + try + { + _logic.Create(model); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка регистрации"); + throw; + } + } + [HttpPost] + public void UpdateData(ClientBindingModel model) + { + try + { + _logic.Update(model); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка обновления данных"); + throw; + } + } + } +} + +} diff --git a/CarRepairShop/CarRepairShopRestApi/Controllers/MainController.cs b/CarRepairShop/CarRepairShopRestApi/Controllers/MainController.cs new file mode 100644 index 0000000..3518219 --- /dev/null +++ b/CarRepairShop/CarRepairShopRestApi/Controllers/MainController.cs @@ -0,0 +1,86 @@ +using CarRepairShopContracts.BindingModels; +using CarRepairShopContracts.BusinessLogicsContracts; +using CarRepairShopContracts.SearchModels; +using CarRepairShopContracts.ViewModels; +using DocumentFormat.OpenXml.Office2010.Excel; +using Microsoft.AspNetCore.Http; +using Microsoft.AspNetCore.Mvc; + +namespace CarRepairShopRestApi.Controllers +{ + [Route("api/[controller]/[action]")] + [ApiController] + public class MainController : Controller + { + private readonly ILogger _logger; + private readonly IOrderLogic _order; + private readonly IRepairLogic _repair; + public MainController(ILogger logger, IOrderLogic order, + IRepairLogic repair) + { + _logger = logger; + _order = order; + _repair = repair; + } + [HttpGet] + public List? GetProductList() + { + try + { + return _repair.ReadList(null); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка получения списка продуктов"); + throw; + } + } + [HttpGet] + public RepairViewModel? GetProduct(int productId) + { + try + { + return _repair.ReadElement(new RepairSearchModel + { + Id = + productId + }); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка получения продукта по id={Id}", + productId); + throw; + } + } + [HttpGet] + public List? GetOrders(int clientId) + { + try + { + return _order.ReadList(new OrderSearchModel + { + ClientId = clientId + }); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка получения списка заказов клиента id ={ Id}", clientId); + throw; + } + } + [HttpPost] + public void CreateOrder(OrderBindingModel model) + { + try + { + _order.CreateOrder(model); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка создания заказа"); + throw; + } + } + } +} diff --git a/CarRepairShop/CarRepairShopRestApi/Program.cs b/CarRepairShop/CarRepairShopRestApi/Program.cs new file mode 100644 index 0000000..1724c5e --- /dev/null +++ b/CarRepairShop/CarRepairShopRestApi/Program.cs @@ -0,0 +1,41 @@ +using CarRepairShopBusinessLogic.BusinessLogics; +using CarRepairShopContracts.BusinessLogicsContracts; +using CarRepairShopContracts.StoragesContracts; +using CarRepairShopDatabaseImplement.Implements; + +using Microsoft.OpenApi.Models; +var builder = WebApplication.CreateBuilder(args); +builder.Logging.SetMinimumLevel(LogLevel.Trace); +builder.Logging.AddLog4Net("log4net.config"); +// Add services to the container. +builder.Services.AddTransient(); +builder.Services.AddTransient(); +builder.Services.AddTransient(); +builder.Services.AddTransient(); +builder.Services.AddTransient(); +builder.Services.AddTransient(); +builder.Services.AddControllers(); +// Learn more about configuring Swagger/OpenAPI at +https://aka.ms/aspnetcore/swashbuckle +builder.Services.AddEndpointsApiExplorer(); +builder.Services.AddSwaggerGen(c => +{ + c.SwaggerDoc("v1", new OpenApiInfo + { + Title = "IceCreamShopRestApi", + Version + = "v1" + }); +}); +var app = builder.Build(); +// Configure the HTTP request pipeline. +if (app.Environment.IsDevelopment()) +{ + app.UseSwagger(); + app.UseSwaggerUI(c => c.SwaggerEndpoint("/swagger/v1/swagger.json", + "IceCreamShopRestApi v1")); +} +app.UseHttpsRedirection(); +app.UseAuthorization(); +app.MapControllers(); +app.Run(); \ No newline at end of file diff --git a/CarRepairShop/CarRepairShopRestApi/Properties/launchSettings.json b/CarRepairShop/CarRepairShopRestApi/Properties/launchSettings.json new file mode 100644 index 0000000..dfd367b --- /dev/null +++ b/CarRepairShop/CarRepairShopRestApi/Properties/launchSettings.json @@ -0,0 +1,31 @@ +{ + "$schema": "https://json.schemastore.org/launchsettings.json", + "iisSettings": { + "windowsAuthentication": false, + "anonymousAuthentication": true, + "iisExpress": { + "applicationUrl": "http://localhost:35194", + "sslPort": 44389 + } + }, + "profiles": { + "CarRepairShopRestApi": { + "commandName": "Project", + "dotnetRunMessages": true, + "launchBrowser": true, + "launchUrl": "swagger", + "applicationUrl": "https://localhost:7136;http://localhost:5119", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + } + }, + "IIS Express": { + "commandName": "IISExpress", + "launchBrowser": true, + "launchUrl": "swagger", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + } + } + } +} diff --git a/CarRepairShop/CarRepairShopRestApi/appsettings.Development.json b/CarRepairShop/CarRepairShopRestApi/appsettings.Development.json new file mode 100644 index 0000000..0c208ae --- /dev/null +++ b/CarRepairShop/CarRepairShopRestApi/appsettings.Development.json @@ -0,0 +1,8 @@ +{ + "Logging": { + "LogLevel": { + "Default": "Information", + "Microsoft.AspNetCore": "Warning" + } + } +} diff --git a/CarRepairShop/CarRepairShopRestApi/appsettings.json b/CarRepairShop/CarRepairShopRestApi/appsettings.json new file mode 100644 index 0000000..10f68b8 --- /dev/null +++ b/CarRepairShop/CarRepairShopRestApi/appsettings.json @@ -0,0 +1,9 @@ +{ + "Logging": { + "LogLevel": { + "Default": "Information", + "Microsoft.AspNetCore": "Warning" + } + }, + "AllowedHosts": "*" +}