diff --git a/BeautySalonView/BeautySalonBusinessLogic/BeautySalonBusinessLogic.csproj b/BeautySalonView/BeautySalonBusinessLogic/BeautySalonBusinessLogic.csproj index 4cc37a2..d08f0db 100644 --- a/BeautySalonView/BeautySalonBusinessLogic/BeautySalonBusinessLogic.csproj +++ b/BeautySalonView/BeautySalonBusinessLogic/BeautySalonBusinessLogic.csproj @@ -19,7 +19,6 @@ - diff --git a/BeautySalonView/BeautySalonBusinessLogic/BusinessLogic/ClientLogic.cs b/BeautySalonView/BeautySalonBusinessLogic/BusinessLogic/ClientLogic.cs new file mode 100644 index 0000000..4c2b9c2 --- /dev/null +++ b/BeautySalonView/BeautySalonBusinessLogic/BusinessLogic/ClientLogic.cs @@ -0,0 +1,156 @@ +using BeautySalonContracts.BindingModels; +using BeautySalonContracts.BusinessLogicContracts; +using BeautySalonContracts.SearchModels; +using BeautySalonContracts.StoragesContracts; +using BeautySalonContracts.ViewModels; +using Microsoft.Extensions.Logging; + +namespace BeautySalonBusinessLogic.BusinessLogics +{ + public class ClientLogic : IClientLogic + { + private readonly int _passwordMaxLength = 50; + private readonly int _passwordMinLength = 10; + + private readonly ILogger _logger; + private readonly IClientStorage _clientStorage; + public ClientLogic(ILogger logger, IClientStorage clientStorage) + { + _logger = logger; + _clientStorage = clientStorage; + } + public bool Create(ClientBindingModel model) + { + CheckModel(model); + + if (_clientStorage.Insert(model) == null) + { + _logger.LogWarning("Insert 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; + } + + public ClientViewModel? ReadElement(ClientSearchModel model) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + + _logger.LogInformation("ReadElement. ClientLogin: {ClientLogin}. ClientFIO: {ClientFIO} ClientEmail: {ClientEmail} Id: {Id}", + model.ClientLogin, model.ClientFIO, model.ClientEmail, 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) + { + _logger.LogInformation("ReadList. ClientLogin: {ClientLogin}. ClientFIO: {ClientFIO} ClientEmail: {ClientEmail} Id: {Id}", + model?.ClientLogin, model?.ClientFIO, model?.ClientEmail, 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) + { + 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.ClientLogin)) + { + throw new ArgumentNullException("Нет логина клиента", nameof(model.ClientLogin)); + } + if (string.IsNullOrEmpty(model.ClientFIO)) + { + throw new ArgumentNullException("Нет ФИО клиента", nameof(model.ClientFIO)); + } + if (string.IsNullOrEmpty(model.ClientEmail)) + { + throw new ArgumentNullException("Нет почты клиента", nameof(model.ClientEmail)); + } + if (string.IsNullOrEmpty(model.ClientPassword)) + { + throw new ArgumentNullException("Нет пароля", nameof(model.ClientPassword)); + } + if (model.ClientPassword.Length < _passwordMinLength) + { + throw new ArgumentNullException("Пароль слишком короткий", nameof(model.ClientPassword)); + } + if (model.ClientPassword.Length > _passwordMaxLength) + { + throw new ArgumentNullException("Пароль слишком длинный", nameof(model.ClientPassword)); + } + + _logger.LogInformation("Client. ClientLogin: {ClientLogin}. ClientFIO: {ClientFIO} ClientEmail: {ClientEmail} Id: {Id}", + model.ClientLogin, model.ClientFIO, model.ClientEmail, model.Id); + + var element = _clientStorage.GetElement(new ClientSearchModel + { + ClientEmail = model.ClientEmail + }); + + if (element != null && element.Id != model.Id) + { + throw new InvalidOperationException("Клиент с такой почтой уже есть"); + } + } + } +} \ No newline at end of file diff --git a/BeautySalonView/BeautySalonBusinessLogic/BusinessLogic/EvaluationLogic.cs b/BeautySalonView/BeautySalonBusinessLogic/BusinessLogic/EvaluationLogic.cs new file mode 100644 index 0000000..8fd92f8 --- /dev/null +++ b/BeautySalonView/BeautySalonBusinessLogic/BusinessLogic/EvaluationLogic.cs @@ -0,0 +1,107 @@ +using BeautySalonContracts.BindingModels; +using BeautySalonContracts.BusinessLogicContracts; +using BeautySalonContracts.SearchModels; +using BeautySalonContracts.StoragesContracts; +using BeautySalonContracts.ViewModels; +using Microsoft.Extensions.Logging; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BeautySalonBusinessLogic.BusinessLogics +{ + public class EvaluationLogic : IEvaluationLogic + { + private readonly ILogger _logger; + private readonly IEvaluationStorage _evaluationStorage; + public EvaluationLogic(ILogger logger, IEvaluationStorage evaluationStorage) + { + _logger = logger; + _evaluationStorage = evaluationStorage; + } + public int GetNumberOfPages(int userId, int pageSize = 10) + { + return _evaluationStorage.GetNumberOfPages(userId, pageSize); + } + public List? ReadList(EvaluationSearchModel? model) + { + _logger.LogInformation("ReadList. Id: {Id}", + model?.Id); + var list = model == null ? _evaluationStorage.GetFullList() : + _evaluationStorage.GetFilteredList(model); + if (list == null) + { + _logger.LogWarning("ReadList return null list"); + return null; + } + _logger.LogInformation("ReadList. Count: {Count}", list.Count); + return list; + } + public EvaluationViewModel? ReadElement(EvaluationSearchModel model) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + _logger.LogInformation("ReadElement. Id: {Id}", model.Id); + var element = _evaluationStorage.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(EvaluationBindingModel model) + { + CheckModel(model); + if (_evaluationStorage.Insert(model) == null) + { + _logger.LogWarning("Insert operation failed"); + return false; + } + return true; + } + public bool Update(EvaluationBindingModel model) + { + CheckModel(model); + if (_evaluationStorage.Update(model) == null) + { + _logger.LogWarning("Update operation failed"); + return false; + } + return true; + } + public bool Delete(EvaluationBindingModel model) + { + CheckModel(model, false); + _logger.LogInformation("Delete. Id: {Id}", model.Id); + if (_evaluationStorage.Delete(model) == null) + { + _logger.LogWarning("Delete operation failed"); + return false; + } + return true; + } + private void CheckModel(EvaluationBindingModel model, bool withParams = true) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + if (!withParams) + { + return; + } + if (model.PointsProcedure <= 0) + { + throw new ArgumentNullException("Оценки за процедуру должны быть больше 0", nameof(model.PointsProcedure)); + } + _logger.LogInformation("Rating. PointsProcedure: {PointsProcedure}}. Id: {Id}", + model.PointsProcedure, model.PointsCosmetics, model.Id); + } + } +} diff --git a/BeautySalonView/BeautySalonBusinessLogic/BusinessLogic/OrderLogic.cs b/BeautySalonView/BeautySalonBusinessLogic/BusinessLogic/OrderLogic.cs new file mode 100644 index 0000000..a285fee --- /dev/null +++ b/BeautySalonView/BeautySalonBusinessLogic/BusinessLogic/OrderLogic.cs @@ -0,0 +1,106 @@ +using BeautySalonContracts.BindingModels; +using BeautySalonContracts.BusinessLogicContracts; +using BeautySalonContracts.SearchModels; +using BeautySalonContracts.StoragesContracts; +using BeautySalonContracts.ViewModels; +using Microsoft.Extensions.Logging; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BeautySalonBusinessLogic.BusinessLogics +{ + public class OrderLogic : IOrderLogic + { + private readonly ILogger _logger; + private readonly IOrderStorage _orderStorage; + public OrderLogic(ILogger logger, IOrderStorage orderStorage) + { + _logger = logger; + _orderStorage = orderStorage; + } + public int GetNumberOfPages(int userId, int pageSize = 10) + { + return _orderStorage.GetNumberOfPages(userId, pageSize); + } + public List? ReadList(OrderSearchModel? model) + { + _logger.LogInformation("Order. OrderID:{Id}", model?.Id); + var list = model == null ? _orderStorage.GetFullList() : _orderStorage.GetFilteredList(model); + if (list == null) + { + _logger.LogWarning("ReadList return null list"); + return null; + } + _logger.LogInformation("ReadList. Count:{Count}", list.Count); + return list; + } + + public OrderViewModel? ReadElement(OrderSearchModel model) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + _logger.LogInformation("ReadElement. OrderDate: {OrderDate}. Id: {Id}", + model.OrderDate, model.Id); + var element = _orderStorage.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(OrderBindingModel model) + { + CheckModel(model); + if (_orderStorage.Insert(model) == null) + { + _logger.LogWarning("Insert operation failed"); + return false; + } + return true; + } + public bool Update(OrderBindingModel model) + { + CheckModel(model); + if (_orderStorage.Update(model) == null) + { + _logger.LogWarning("Update operation failed"); + return false; + } + return true; + } + public bool Delete(OrderBindingModel model) + { + CheckModel(model, false); + _logger.LogInformation("Delete. Id: {Id}", model.Id); + if (_orderStorage.Delete(model) == null) + { + _logger.LogWarning("Delete operation failed"); + return false; + } + return true; + } + private void CheckModel(OrderBindingModel model, bool withParams = true) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + if (!withParams) + { + return; + } + if (model.OrderAmount <= 0) + { + throw new ArgumentNullException("Cумма заказа должна быть больше 0", + nameof(model.OrderAmount)); + } + } + } +} diff --git a/BeautySalonView/BeautySalonBusinessLogic/BusinessLogic/ProcedureLogic.cs b/BeautySalonView/BeautySalonBusinessLogic/BusinessLogic/ProcedureLogic.cs new file mode 100644 index 0000000..dc036c6 --- /dev/null +++ b/BeautySalonView/BeautySalonBusinessLogic/BusinessLogic/ProcedureLogic.cs @@ -0,0 +1,123 @@ +using BeautySalonContracts.BindingModels; +using BeautySalonContracts.BusinessLogicContracts; +using BeautySalonContracts.SearchModels; +using BeautySalonContracts.StoragesContracts; +using BeautySalonContracts.ViewModels; +using Microsoft.Extensions.Logging; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BeautySalonBusinessLogic.BusinessLogics +{ + public class ProcedureLogic : IProcedureLogic + { + private readonly ILogger _logger; + private readonly IProcedureStorage _procedureStorage; + public ProcedureLogic(ILogger logger, IProcedureStorage procedureStorage) + { + _logger = logger; + _procedureStorage = procedureStorage; + } + public int GetNumberOfPages(int userId, int pageSize = 10) + { + return _procedureStorage.GetNumberOfPages(userId, pageSize); + } + + public List? ReadList(ProcedureSearchModel? model) + { + _logger.LogInformation("ReadList. ProcedureName: {ProcedureName}. Id: {Id}", + model?.ProcedureName, model?.Id); + var list = model == null ? _procedureStorage.GetFullList() : + _procedureStorage.GetFilteredList(model); + if (list == null) + { + _logger.LogWarning("ReadList return null list"); + return null; + } + _logger.LogInformation("ReadList. Count: {Count}", list.Count); + return list; + } + public ProcedureViewModel? ReadElement(ProcedureSearchModel model) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + _logger.LogInformation("ReadElement. ProcedureName: {ProcedureName}. Id: {Id}", + model.ProcedureName, model.Id); + var element = _procedureStorage.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(ProcedureBindingModel model) + { + CheckModel(model); + if (_procedureStorage.Insert(model) == null) + { + _logger.LogWarning("Insert operation failed"); + return false; + } + return true; + } + public bool Update(ProcedureBindingModel model) + { + CheckModel(model); + if (_procedureStorage.Update(model) == null) + { + _logger.LogWarning("Update operation failed"); + return false; + } + return true; + } + public bool Delete(ProcedureBindingModel model) + { + CheckModel(model, false); + _logger.LogInformation("Delete. Id: {Id}", model.Id); + if (_procedureStorage.Delete(model) == null) + { + _logger.LogWarning("Delete operation failed"); + return false; + } + return true; + } + private void CheckModel(ProcedureBindingModel model, bool withParams = true) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + if (!withParams) + { + return; + } + if (string.IsNullOrEmpty(model.ProcedureName)) + { + throw new ArgumentNullException("Нет названия процедуры", nameof(model.ProcedureName)); + } + + if (model.ProcedurePrice <= 0) + { + throw new ArgumentNullException("Цена процедуры должна быть больше 0", + nameof(model.ProcedurePrice)); + } + _logger.LogInformation("Procedure. ProcedureName: {ProcedureName}. Cost: {Cost}. Id: {Id}", + model.ProcedureName, model.ProcedurePrice, model.Id); + var element = _procedureStorage.GetElement(new ProcedureSearchModel + { + ProcedureName = model.ProcedureName + }); + if (element != null && element.Id != model.Id) + { + throw new InvalidOperationException("Процедура с таким названием уже есть"); + } + } + } +} diff --git a/BeautySalonView/BeautySalonContracts/BeautySalonContracts.csproj b/BeautySalonView/BeautySalonContracts/BeautySalonContracts.csproj index 6d5d754..9c9950d 100644 --- a/BeautySalonView/BeautySalonContracts/BeautySalonContracts.csproj +++ b/BeautySalonView/BeautySalonContracts/BeautySalonContracts.csproj @@ -10,12 +10,4 @@ - - - - - - - - diff --git a/BeautySalonView/BeautySalonContracts/BindingModels/ClientBindingModel.cs b/BeautySalonView/BeautySalonContracts/BindingModels/ClientBindingModel.cs new file mode 100644 index 0000000..b1c3830 --- /dev/null +++ b/BeautySalonView/BeautySalonContracts/BindingModels/ClientBindingModel.cs @@ -0,0 +1,17 @@ +using BeautySalonDataModels.Models; + +namespace BeautySalonContracts.BindingModels +{ + public class ClientBindingModel : IClientModel + { + public int Id { get; set; } + + public string ClientLogin { get; set; } = string.Empty; + + public string ClientFIO { get; set; } = string.Empty; + + public string ClientEmail { get; set; } = string.Empty; + + public string ClientPassword { get; set; } = string.Empty; + } +} diff --git a/BeautySalonView/BeautySalonContracts/BindingModels/EvaluationBindingModel.cs b/BeautySalonView/BeautySalonContracts/BindingModels/EvaluationBindingModel.cs new file mode 100644 index 0000000..9928c28 --- /dev/null +++ b/BeautySalonView/BeautySalonContracts/BindingModels/EvaluationBindingModel.cs @@ -0,0 +1,14 @@ +using BeautySalonDataModels.Models; + +namespace BeautySalonContracts.BindingModels +{ + public class EvaluationBindingModel : IEvaluationModel + { + public int Id { get; set; } + public double PointsProcedure { get; set; } + public double PointsCosmetics { get; set; } + public int ProcedureId { get; set; } + public int ClientId { get; set; } + + } +} \ No newline at end of file diff --git a/BeautySalonView/BeautySalonContracts/BindingModels/OrderBindingModel.cs b/BeautySalonView/BeautySalonContracts/BindingModels/OrderBindingModel.cs new file mode 100644 index 0000000..fd627da --- /dev/null +++ b/BeautySalonView/BeautySalonContracts/BindingModels/OrderBindingModel.cs @@ -0,0 +1,18 @@ +using BeautySalonContracts.ViewModels; +using BeautySalonDataModels.Models; +using System; +using System.Collections.Generic; + +namespace BeautySalonContracts.BindingModels +{ + public class OrderBindingModel : IOrderModel + { + public int Id { get; set; } + public DateTime OrderDate { get; set; } + public double OrderAmount { get; set; } + public int ClientId { get; set; } + public List OrderServices { get; set; } = new(); + public List OrderCosmetics { get; set; } = new(); + public List OrderProcedures { get; set; } = new(); + } +} diff --git a/BeautySalonView/BeautySalonContracts/BindingModels/ProcedureBindingModel.cs b/BeautySalonView/BeautySalonContracts/BindingModels/ProcedureBindingModel.cs new file mode 100644 index 0000000..7d1994e --- /dev/null +++ b/BeautySalonView/BeautySalonContracts/BindingModels/ProcedureBindingModel.cs @@ -0,0 +1,16 @@ +using BeautySalonContracts.ViewModels; +using BeautySalonDataModels.Models; +using System.Collections.Generic; + +namespace BeautySalonContracts.BindingModels +{ + public class ProcedureBindingModel : IProcedureModel + { + public int Id { get; set; } + public string ProcedureName { get; set; } = string.Empty; + public double ProcedurePrice { get; set; } + public double ProcedureDuration { get; set; } + public int ClientId { get; set; } + public List ProcedureCosmetics { get; set; } = new(); + } +} diff --git a/BeautySalonView/BeautySalonContracts/BusinessLogicContracts/IClientLogic.cs b/BeautySalonView/BeautySalonContracts/BusinessLogicContracts/IClientLogic.cs new file mode 100644 index 0000000..5c4b32e --- /dev/null +++ b/BeautySalonView/BeautySalonContracts/BusinessLogicContracts/IClientLogic.cs @@ -0,0 +1,16 @@ +using System.Collections.Generic; +using BeautySalonContracts.BindingModels; +using BeautySalonContracts.ViewModels; +using BeautySalonContracts.SearchModels; + +namespace BeautySalonContracts.BusinessLogicContracts +{ + 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/BeautySalonView/BeautySalonContracts/BusinessLogicContracts/IEvaluationLogic.cs b/BeautySalonView/BeautySalonContracts/BusinessLogicContracts/IEvaluationLogic.cs new file mode 100644 index 0000000..54949d2 --- /dev/null +++ b/BeautySalonView/BeautySalonContracts/BusinessLogicContracts/IEvaluationLogic.cs @@ -0,0 +1,17 @@ +using System.Collections.Generic; +using BeautySalonContracts.BindingModels; +using BeautySalonContracts.ViewModels; +using BeautySalonContracts.SearchModels; + +namespace BeautySalonContracts.BusinessLogicContracts +{ + public interface IEvaluationLogic + { + List? ReadList(EvaluationSearchModel? model); + EvaluationViewModel? ReadElement(EvaluationSearchModel model); + bool Create(EvaluationBindingModel model); + bool Update(EvaluationBindingModel model); + bool Delete(EvaluationBindingModel model); + int GetNumberOfPages(int userId, int pageSize = 10); + } +} diff --git a/BeautySalonView/BeautySalonContracts/BusinessLogicContracts/IOrderLogic.cs b/BeautySalonView/BeautySalonContracts/BusinessLogicContracts/IOrderLogic.cs new file mode 100644 index 0000000..06fc8f3 --- /dev/null +++ b/BeautySalonView/BeautySalonContracts/BusinessLogicContracts/IOrderLogic.cs @@ -0,0 +1,17 @@ +using System.Collections.Generic; +using BeautySalonContracts.BindingModels; +using BeautySalonContracts.ViewModels; +using BeautySalonContracts.SearchModels; + +namespace BeautySalonContracts.BusinessLogicContracts +{ + public interface IOrderLogic + { + List? ReadList(OrderSearchModel? model); + OrderViewModel? ReadElement(OrderSearchModel model); + bool Create(OrderBindingModel model); + bool Delete(OrderBindingModel model); + bool Update(OrderBindingModel model); + int GetNumberOfPages(int userId, int pageSize = 10); + } +} diff --git a/BeautySalonView/BeautySalonContracts/BusinessLogicContracts/IProcedureLogic.cs b/BeautySalonView/BeautySalonContracts/BusinessLogicContracts/IProcedureLogic.cs new file mode 100644 index 0000000..f95ab6b --- /dev/null +++ b/BeautySalonView/BeautySalonContracts/BusinessLogicContracts/IProcedureLogic.cs @@ -0,0 +1,17 @@ +using System.Collections.Generic; +using BeautySalonContracts.BindingModels; +using BeautySalonContracts.ViewModels; +using BeautySalonContracts.SearchModels; + +namespace BeautySalonContracts.BusinessLogicContracts +{ + public interface IProcedureLogic + { + List? ReadList(ProcedureSearchModel? model); + ProcedureViewModel? ReadElement(ProcedureSearchModel model); + bool Create(ProcedureBindingModel model); + bool Update(ProcedureBindingModel model); + bool Delete(ProcedureBindingModel model); + int GetNumberOfPages(int userId, int pageSize = 10); + } +} diff --git a/BeautySalonView/BeautySalonContracts/SearchModels/ClientSearchModel.cs b/BeautySalonView/BeautySalonContracts/SearchModels/ClientSearchModel.cs new file mode 100644 index 0000000..ea2540f --- /dev/null +++ b/BeautySalonView/BeautySalonContracts/SearchModels/ClientSearchModel.cs @@ -0,0 +1,11 @@ +namespace BeautySalonContracts.SearchModels +{ + public class ClientSearchModel + { + public int? Id { get; set; } + public string? ClientLogin { get; set; } + public string? ClientFIO { get; set; } + public string? ClientEmail { get; set; } + public string? ClientPassword { get; set; } + } +} diff --git a/BeautySalonView/BeautySalonContracts/SearchModels/EvaluationSearchModel.cs b/BeautySalonView/BeautySalonContracts/SearchModels/EvaluationSearchModel.cs new file mode 100644 index 0000000..cf3ff71 --- /dev/null +++ b/BeautySalonView/BeautySalonContracts/SearchModels/EvaluationSearchModel.cs @@ -0,0 +1,10 @@ +namespace BeautySalonContracts.SearchModels +{ + public class EvaluationSearchModel + { + public int? Id { get; set; } + public int? ClientId { get; set; } + public int? PageNumber { get; set; } + public int? PageSize { get; set; } + } +} diff --git a/BeautySalonView/BeautySalonContracts/SearchModels/OrderSearchModel.cs b/BeautySalonView/BeautySalonContracts/SearchModels/OrderSearchModel.cs new file mode 100644 index 0000000..322bdea --- /dev/null +++ b/BeautySalonView/BeautySalonContracts/SearchModels/OrderSearchModel.cs @@ -0,0 +1,16 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BeautySalonContracts.SearchModels +{ + public class OrderSearchModel + { + public int? Id { get; set; } + public DateTime? OrderDate { get; set; } + public int? ClientId { get; set; } + + } +} diff --git a/BeautySalonView/BeautySalonContracts/SearchModels/ProcedureSearchModel.cs b/BeautySalonView/BeautySalonContracts/SearchModels/ProcedureSearchModel.cs new file mode 100644 index 0000000..2dfdfde --- /dev/null +++ b/BeautySalonView/BeautySalonContracts/SearchModels/ProcedureSearchModel.cs @@ -0,0 +1,11 @@ +namespace BeautySalonContracts.SearchModels +{ + public class ProcedureSearchModel + { + public int? Id { get; set; } + public string? ProcedureName { get; set; } + public int? ClientId { get; set; } + public int? PageNumber { get; set; } + public int? PageSize { get; set; } + } +} diff --git a/BeautySalonView/BeautySalonContracts/StoragesContracts/IClientStorage.cs b/BeautySalonView/BeautySalonContracts/StoragesContracts/IClientStorage.cs new file mode 100644 index 0000000..a4a64ff --- /dev/null +++ b/BeautySalonView/BeautySalonContracts/StoragesContracts/IClientStorage.cs @@ -0,0 +1,21 @@ +using BeautySalonContracts.BindingModels; +using BeautySalonContracts.SearchModels; +using BeautySalonContracts.ViewModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BeautySalonContracts.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/BeautySalonView/BeautySalonContracts/StoragesContracts/IEvaluationStorage.cs b/BeautySalonView/BeautySalonContracts/StoragesContracts/IEvaluationStorage.cs new file mode 100644 index 0000000..5ffb7e8 --- /dev/null +++ b/BeautySalonView/BeautySalonContracts/StoragesContracts/IEvaluationStorage.cs @@ -0,0 +1,23 @@ +using BeautySalonContracts.BindingModels; +using BeautySalonContracts.SearchModels; +using BeautySalonContracts.ViewModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BeautySalonContracts.StoragesContracts +{ + public interface IEvaluationStorage + { + List GetFullList(); + List GetFilteredList(EvaluationSearchModel model); + EvaluationViewModel? GetElement(EvaluationSearchModel model); + EvaluationViewModel? Insert(EvaluationBindingModel model); + EvaluationViewModel? Update(EvaluationBindingModel model); + EvaluationViewModel? Delete(EvaluationBindingModel model); + int GetNumberOfPages(int userId, int pageSize); + + } +} diff --git a/BeautySalonView/BeautySalonContracts/StoragesContracts/IOrderStorage.cs b/BeautySalonView/BeautySalonContracts/StoragesContracts/IOrderStorage.cs new file mode 100644 index 0000000..63e59eb --- /dev/null +++ b/BeautySalonView/BeautySalonContracts/StoragesContracts/IOrderStorage.cs @@ -0,0 +1,23 @@ +using BeautySalonContracts.BindingModels; +using BeautySalonContracts.SearchModels; +using BeautySalonContracts.ViewModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BeautySalonContracts.StoragesContracts +{ + public interface IOrderStorage + { + List GetFullList(); + List GetFilteredList(OrderSearchModel model); + OrderViewModel? GetElement(OrderSearchModel model); + OrderViewModel? Insert(OrderBindingModel model); + OrderViewModel? Update(OrderBindingModel model); + OrderViewModel? Delete(OrderBindingModel model); + int GetNumberOfPages(int userId, int pageSize); + + } +} diff --git a/BeautySalonView/BeautySalonContracts/StoragesContracts/IProcedureStorage.cs b/BeautySalonView/BeautySalonContracts/StoragesContracts/IProcedureStorage.cs new file mode 100644 index 0000000..18c38e4 --- /dev/null +++ b/BeautySalonView/BeautySalonContracts/StoragesContracts/IProcedureStorage.cs @@ -0,0 +1,22 @@ +using BeautySalonContracts.BindingModels; +using BeautySalonContracts.SearchModels; +using BeautySalonContracts.ViewModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BeautySalonContracts.StoragesContracts +{ + public interface IProcedureStorage + { + List GetFullList(); + List GetFilteredList(ProcedureSearchModel model); + ProcedureViewModel? GetElement(ProcedureSearchModel model); + ProcedureViewModel? Insert(ProcedureBindingModel model); + ProcedureViewModel? Update(ProcedureBindingModel model); + ProcedureViewModel? Delete(ProcedureBindingModel model); + int GetNumberOfPages(int userId, int pageSize); + } +} diff --git a/BeautySalonView/BeautySalonContracts/ViewModels/ClientViewModel.cs b/BeautySalonView/BeautySalonContracts/ViewModels/ClientViewModel.cs new file mode 100644 index 0000000..f2257e8 --- /dev/null +++ b/BeautySalonView/BeautySalonContracts/ViewModels/ClientViewModel.cs @@ -0,0 +1,27 @@ +using BeautySalonDataModels.Models; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BeautySalonContracts.ViewModels +{ + public class ClientViewModel : IClientModel + { + public int Id { get; set; } + + [DisplayName("Логин клиента")] + public string ClientLogin { get; set; } = string.Empty; + + [DisplayName("ФИО клиента")] + public string ClientFIO { get; set; } = string.Empty; + + [DisplayName("Почта клиента")] + public string ClientEmail { get; set; } = string.Empty; + + [DisplayName("Пароль клиента")] + public string ClientPassword { get; set; } = string.Empty; + } +} diff --git a/BeautySalonView/BeautySalonContracts/ViewModels/EvaluationViewModel.cs b/BeautySalonView/BeautySalonContracts/ViewModels/EvaluationViewModel.cs new file mode 100644 index 0000000..a831c03 --- /dev/null +++ b/BeautySalonView/BeautySalonContracts/ViewModels/EvaluationViewModel.cs @@ -0,0 +1,24 @@ +using BeautySalonDataModels.Models; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BeautySalonContracts.ViewModels +{ + public class EvaluationViewModel : IEvaluationModel + { + [DisplayName("Баллы за процедуру")] + public double PointsProcedure { get; set; } + + [DisplayName("Баллы за косметику")] + public double PointsCosmetics { get; set; } + public int ClientId { get; set; } + public int Id { get; set; } + + public int ProcedureId { get; set; } + public string ProcedureName { get; set; } = string.Empty; + } +} diff --git a/BeautySalonView/BeautySalonContracts/ViewModels/OrderCosmeticViewModel.cs b/BeautySalonView/BeautySalonContracts/ViewModels/OrderCosmeticViewModel.cs new file mode 100644 index 0000000..18ca225 --- /dev/null +++ b/BeautySalonView/BeautySalonContracts/ViewModels/OrderCosmeticViewModel.cs @@ -0,0 +1,16 @@ +namespace BeautySalonContracts.ViewModels +{ + public class OrderCosmeticViewModel + { + public CosmeticViewModel Cosmetic { get; set; } = null!; + public int Count { get; set; } + + public OrderCosmeticViewModel() { } + + public OrderCosmeticViewModel(CosmeticViewModel cosmetic, int count) + { + Cosmetic = cosmetic; + Count = count; + } + } +} \ No newline at end of file diff --git a/BeautySalonView/BeautySalonContracts/ViewModels/OrderProcedureViewModel.cs b/BeautySalonView/BeautySalonContracts/ViewModels/OrderProcedureViewModel.cs new file mode 100644 index 0000000..d8e8b9b --- /dev/null +++ b/BeautySalonView/BeautySalonContracts/ViewModels/OrderProcedureViewModel.cs @@ -0,0 +1,16 @@ +namespace BeautySalonContracts.ViewModels +{ + public class OrderProcedureViewModel + { + public ProcedureViewModel Procedure { get; set; } = null!; + public int Count { get; set; } + + public OrderProcedureViewModel() { } + + public OrderProcedureViewModel(ProcedureViewModel procedure, int count) + { + Procedure = procedure; + Count = count; + } + } +} diff --git a/BeautySalonView/BeautySalonContracts/ViewModels/OrderViewModel.cs b/BeautySalonView/BeautySalonContracts/ViewModels/OrderViewModel.cs new file mode 100644 index 0000000..244a2f8 --- /dev/null +++ b/BeautySalonView/BeautySalonContracts/ViewModels/OrderViewModel.cs @@ -0,0 +1,23 @@ +using BeautySalonDataModels.Models; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BeautySalonContracts.ViewModels +{ + public class OrderViewModel : IOrderModel + { + [DisplayName("Дата заказа")] + public DateTime OrderDate { get; set; } + + [DisplayName("Сумма")] + public double OrderAmount { get; set; } + public int ClientId { get; set; } + public int Id { get; set; } + public List OrderServices { get; set; } = new(); + public List OrderProcedures { get; set; } = new(); + } +} diff --git a/BeautySalonView/BeautySalonContracts/ViewModels/ProcedureEvaluationViewModel.cs b/BeautySalonView/BeautySalonContracts/ViewModels/ProcedureEvaluationViewModel.cs new file mode 100644 index 0000000..6d57cc8 --- /dev/null +++ b/BeautySalonView/BeautySalonContracts/ViewModels/ProcedureEvaluationViewModel.cs @@ -0,0 +1,16 @@ +namespace BeautySalonContracts.ViewModels +{ + public class ProcedureEvaluationViewModel + { + public CosmeticViewModel Cosmetic { get; set; } = null!; + public int Count { get; set; } + + public ProcedureEvaluationViewModel() { } + + public ProcedureEvaluationViewModel(CosmeticViewModel car, int count) + { + Cosmetic = car; + Count = count; + } + } +} diff --git a/BeautySalonView/BeautySalonContracts/ViewModels/ProcedureViewModel.cs b/BeautySalonView/BeautySalonContracts/ViewModels/ProcedureViewModel.cs new file mode 100644 index 0000000..646c7f5 --- /dev/null +++ b/BeautySalonView/BeautySalonContracts/ViewModels/ProcedureViewModel.cs @@ -0,0 +1,26 @@ +using BeautySalonDataModels.Models; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BeautySalonContracts.ViewModels +{ + public class ProcedureViewModel : IProcedureModel + { + [DisplayName("Наименование процедуры")] + public string ProcedureName { get; set; } = string.Empty; + + [DisplayName("Цена процедуры")] + public double ProcedurePrice { get; set; } + + public int ClientId { get; set; } + + public int Id { get; set; } + public List ProcedureCosmetics { get; set; } = new(); + public List ProcedureRatings { get; set; } = new(); + + } +} diff --git a/BeautySalonView/BeautySalonDataModels/BeautySalonDataModels.csproj b/BeautySalonView/BeautySalonDataModels/BeautySalonDataModels.csproj index 7264f69..b6a7529 100644 --- a/BeautySalonView/BeautySalonDataModels/BeautySalonDataModels.csproj +++ b/BeautySalonView/BeautySalonDataModels/BeautySalonDataModels.csproj @@ -8,7 +8,6 @@ - diff --git a/BeautySalonView/BeautySalonDataModels/Models/IClientModel.cs b/BeautySalonView/BeautySalonDataModels/Models/IClientModel.cs new file mode 100644 index 0000000..0725eec --- /dev/null +++ b/BeautySalonView/BeautySalonDataModels/Models/IClientModel.cs @@ -0,0 +1,10 @@ +namespace BeautySalonDataModels.Models +{ + public interface IClientModel : IId + { + string ClientLogin { get; } + string ClientFIO { get; } + string ClientEmail { get; } + string ClientPassword { get; } + } +} \ No newline at end of file diff --git a/BeautySalonView/BeautySalonDataModels/Models/IEvaluationModel.cs b/BeautySalonView/BeautySalonDataModels/Models/IEvaluationModel.cs new file mode 100644 index 0000000..510159d --- /dev/null +++ b/BeautySalonView/BeautySalonDataModels/Models/IEvaluationModel.cs @@ -0,0 +1,10 @@ +namespace BeautySalonDataModels.Models +{ + public interface IEvaluationModel : IId + { + double PointsProcedure { get; } + double PointsCosmetics { get; } + int ProcedureId { get; } + int ClientId { get; } + } +} diff --git a/BeautySalonView/BeautySalonDataModels/Models/IOrderModel.cs b/BeautySalonView/BeautySalonDataModels/Models/IOrderModel.cs new file mode 100644 index 0000000..89e7f4a --- /dev/null +++ b/BeautySalonView/BeautySalonDataModels/Models/IOrderModel.cs @@ -0,0 +1,12 @@ +using System; +using System.Collections.Generic; + +namespace BeautySalonDataModels.Models +{ + public interface IOrderModel : IId + { + DateTime OrderDate { get; } + double OrderAmount { get; } + int ClientId { get; } + } +} diff --git a/BeautySalonView/BeautySalonDataModels/Models/IProcedureModel.cs b/BeautySalonView/BeautySalonDataModels/Models/IProcedureModel.cs new file mode 100644 index 0000000..c0b0df3 --- /dev/null +++ b/BeautySalonView/BeautySalonDataModels/Models/IProcedureModel.cs @@ -0,0 +1,12 @@ +using System.Collections.Generic; + +namespace BeautySalonDataModels.Models +{ + public interface IProcedureModel : IId + { + string ProcedureName { get; } + double ProcedurePrice { get; } + int ClientId { get; } + + } +} diff --git a/BeautySalonView/BeautySalonDatabaseImplement/BeautySalonDatabaseImplement.csproj b/BeautySalonView/BeautySalonDatabaseImplement/BeautySalonDatabaseImplement.csproj index 30953fc..fb300cb 100644 --- a/BeautySalonView/BeautySalonDatabaseImplement/BeautySalonDatabaseImplement.csproj +++ b/BeautySalonView/BeautySalonDatabaseImplement/BeautySalonDatabaseImplement.csproj @@ -21,9 +21,4 @@ - - - - - diff --git a/BeautySalonView/BeautySalonDatabaseImplement/Implements/ClientStorage.cs b/BeautySalonView/BeautySalonDatabaseImplement/Implements/ClientStorage.cs new file mode 100644 index 0000000..4325afe --- /dev/null +++ b/BeautySalonView/BeautySalonDatabaseImplement/Implements/ClientStorage.cs @@ -0,0 +1,97 @@ +using BeautySalonContracts.BindingModels; +using BeautySalonContracts.SearchModels; +using BeautySalonContracts.StoragesContracts; +using BeautySalonContracts.ViewModels; +using BeautySalonDatabaseImplement.Models; +using Microsoft.EntityFrameworkCore; +using System.Collections.Generic; +using System.Linq; + +namespace BeautySalonDatabaseImplement.Implements +{ + public class ClientStorage : IClientStorage + { + public ClientViewModel? Delete(ClientBindingModel model) + { + using var context = new BeautySalonDatabase(); + + var element = context.Clients.FirstOrDefault(rec => rec.Id == model.Id); + + if (element != null) + { + context.Clients.Remove(element); + context.SaveChanges(); + + return element.GetViewModel; + } + + return null; + } + + + public ClientViewModel? GetElement(ClientSearchModel model) + { + using var context = new BeautySalonDatabase(); + if (model.Id.HasValue) + return context.Clients + .FirstOrDefault(x => x.Id == model.Id)? + .GetViewModel; + + if (!string.IsNullOrEmpty(model.ClientLogin) && + !string.IsNullOrEmpty(model.ClientPassword)) + return context.Clients + .FirstOrDefault(x => + x.ClientLogin.Equals(model.ClientLogin) && + x.ClientPassword.Equals(model.ClientPassword))? + .GetViewModel; + + return null; + } + + public List GetFilteredList(ClientSearchModel model) + { + throw new NotImplementedException(); + } + + public List GetFullList() + { + using var context = new BeautySalonDatabase(); + return context.Clients + .Select(x => x.GetViewModel) + .ToList(); + } + + public ClientViewModel? Insert(ClientBindingModel model) + { + using var context = new BeautySalonDatabase(); + + var newClient = Client.Create(model); + + if (newClient == null) + { + return null; + } + context.Clients.Add(newClient); + context.SaveChanges(); + + return newClient.GetViewModel; + } + + public ClientViewModel? Update(ClientBindingModel model) + { + using var context = new BeautySalonDatabase(); + + var client = context.Clients.FirstOrDefault(x => x.Id == model.Id); + + if (client == null) + { + return null; + } + + client.Update(model); + context.SaveChanges(); + + return client.GetViewModel; + } + } +} \ No newline at end of file diff --git a/BeautySalonView/BeautySalonDatabaseImplement/Implements/EvaluationStorage.cs b/BeautySalonView/BeautySalonDatabaseImplement/Implements/EvaluationStorage.cs new file mode 100644 index 0000000..5395bc1 --- /dev/null +++ b/BeautySalonView/BeautySalonDatabaseImplement/Implements/EvaluationStorage.cs @@ -0,0 +1,117 @@ +using BeautySalonContracts.BindingModels; +using BeautySalonContracts.SearchModels; +using BeautySalonContracts.StoragesContracts; +using BeautySalonContracts.ViewModels; +using BeautySalonDatabaseImplement.Models; +using Microsoft.EntityFrameworkCore; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BeautySalonDatabaseImplement.Implements +{ + public class EvaluationStorage : IEvaluationStorage + { + public List GetFullList() + { + using var context = new BeautySalonDatabase(); + return context.Ratings + .Include(x => x.Procedure) + .ToList() + .Select(x => x.GetViewModel) + .ToList(); + } + public int GetNumberOfPages(int userId, int pageSize) + { + using var context = new BeautySalonDatabase(); + int carsCount = context.LaborsCosts.Where(c => c.StaffMemberId == userId).Count(); + int numberOfpages = (int)Math.Ceiling((double)carsCount / pageSize); + return numberOfpages != 0 ? numberOfpages : 1; + } + + public List GetFilteredList(EvaluationSearchModel model) + { + using var context = new BeautySalonDatabase(); + if (model.Id.HasValue) + { + return context.Ratings + .Include(x => x.Procedure) + .Where(x => x.Id == model.Id) + .Select(x => x.GetViewModel) + .ToList(); + } + if (model.ClientId.HasValue && model.PageNumber.HasValue && model.PageSize.HasValue) + { + return context.Ratings + .Include(x => x.Procedure) + .Where(x => x.ClientId == model.ClientId) + .Skip(model.PageSize.Value * (model.PageNumber.Value - 1)) + .Take(model.PageSize.Value) + .Select(x => x.GetViewModel) + .ToList(); + } + return new(); + } + + public EvaluationViewModel? GetElement(EvaluationSearchModel model) + { + if (!model.Id.HasValue) + { + return null; + } + using var context = new BeautySalonDatabase(); + return context.Ratings + .Include(x => x.Procedure) + .FirstOrDefault(x => model.Id.HasValue && x.Id == model.Id) + ?.GetViewModel; + } + + public EvaluationViewModel? Insert(EvaluationBindingModel model) + { + var newRating = Evaluation.Create(model); + if (newRating == null) + { + return null; + } + using var context = new BeautySalonDatabase(); + context.Ratings.Add(newRating); + context.SaveChanges(); + return context.Ratings + .Include(x => x.Procedure) + .FirstOrDefault(x => x.Id == newRating.Id) + ?.GetViewModel; + } + + public EvaluationViewModel? Update(EvaluationBindingModel model) + { + using var context = new BeautySalonDatabase(); + var сosmetic = context.Ratings + .Include(x => x.Procedure) + .FirstOrDefault(x => x.Id == model.Id); + if (сosmetic == null) + { + return null; + } + сosmetic.Update(model); + context.SaveChanges(); + return сosmetic.GetViewModel; + } + + public EvaluationViewModel? Delete(EvaluationBindingModel model) + { + using var context = new BeautySalonDatabase(); + var element = context.Ratings + .Include(x => x.Procedure) + .FirstOrDefault(rec => rec.Id == model.Id); + if (element != null) + { + context.Ratings.Remove(element); + context.SaveChanges(); + return element.GetViewModel; + } + return null; + } + } +} diff --git a/BeautySalonView/BeautySalonDatabaseImplement/Implements/OrderStorage.cs b/BeautySalonView/BeautySalonDatabaseImplement/Implements/OrderStorage.cs new file mode 100644 index 0000000..1bcedd2 --- /dev/null +++ b/BeautySalonView/BeautySalonDatabaseImplement/Implements/OrderStorage.cs @@ -0,0 +1,149 @@ +using BeautySalonContracts.BindingModels; +using BeautySalonContracts.SearchModels; +using BeautySalonContracts.StoragesContracts; +using BeautySalonContracts.ViewModels; +using BeautySalonDatabaseImplement.Models; +using Microsoft.EntityFrameworkCore; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BeautySalonDatabaseImplement.Implements +{ + public class OrderStorage : IOrderStorage + { + public OrderViewModel? Delete(OrderBindingModel model) + { + using var context = new BeautySalonDatabase(); + var element = context.Orders + .Include(x => x.Services) + .Include(x => x.Procedures) + .FirstOrDefault(rec => rec.Id == model.Id); + if (element != null) + { + context.Orders.Remove(element); + context.SaveChanges(); + return element.GetViewModel; + } + return null; + } + + public OrderViewModel? GetElement(OrderSearchModel model) + { + if (!model.Id.HasValue) + { + return null; + } + using var context = new BeautySalonDatabase(); + return context.Orders + .Include(x => x.Services) + .ThenInclude(x => x.Service) + .Include(x => x.Procedures) + .ThenInclude(x => x.Procedure) + .FirstOrDefault(x => x.Id == model.Id) + ?.GetViewModel; + } + public int GetNumberOfPages(int userId, int pageSize) + { + using var context = new BeautySalonDatabase(); + int carsCount = context.Orders.Where(c => c.ClientId == userId).Count(); + int numberOfpages = (int)Math.Ceiling((double)carsCount / pageSize); + return numberOfpages != 0 ? numberOfpages : 1; + } + public List GetFilteredList(OrderSearchModel model) + { + if (model == null) + { + return new(); + } + using var context = new BeautySalonDatabase(); + if (model.ClientId.HasValue && model.DateFrom.HasValue && model.DateTo.HasValue) + { + return context.Orders + .Include(x => x.Services) + .ThenInclude(x => x.Service) + .Include(x => x.Procedures) + .ThenInclude(x => x.Procedure) + .ThenInclude(x => x.Ratings) + .Where(x => x.ClientId == model.ClientId && + x.OrderDate >= model.DateFrom && x.OrderDate <= model.DateTo).ToList() + .Select(x => x.GetViewModel) + .ToList(); + } + if (model.ClientId.HasValue && model.PageNumber.HasValue && model.PageSize.HasValue) + { + return context.Orders + .Include(x => x.Services) + .ThenInclude(x => x.Service) + .Where(x => x.ClientId == model.ClientId) + .Skip(model.PageSize.Value * (model.PageNumber.Value - 1)) + .Take(model.PageSize.Value) + .Select(x => x.GetViewModel) + .ToList(); + } + if (model.ClientId.HasValue) + { + return context.Orders + .Include(x => x.Services) + .ThenInclude(x => x.Service) + .Where(x => x.ClientId == model.ClientId) + .Select(x => x.GetViewModel) + .ToList(); + } + return new(); + } + + public List GetFullList() + { + using var context = new BeautySalonDatabase(); + return context.Orders + .Include(x => x.Services) + .ThenInclude(x => x.Service) + .Include(x => x.Procedures) + .ThenInclude(x => x.Procedure) + .ToList() + .Select(x => x.GetViewModel) + .ToList(); + } + + public OrderViewModel? Insert(OrderBindingModel model) + { + using var context = new BeautySalonDatabase(); + var newOrder = Order.Create(context, model); + if (newOrder == null) + { + return null; + } + context.Orders.Add(newOrder); + context.SaveChanges(); + return newOrder.GetViewModel; + } + + public OrderViewModel? Update(OrderBindingModel model) + { + using var context = new BeautySalonDatabase(); + using var transaction = context.Database.BeginTransaction(); + try + { + var order = context.Orders.FirstOrDefault(rec => rec.Id == model.Id); + if (order == null) + { + return null; + } + order.Update(model); + context.SaveChanges(); + order.UpdateServices(context, model); + order.UpdateProcedures(context, model); + transaction.Commit(); + return order.GetViewModel; + } + catch + { + transaction.Rollback(); + throw; + } + } + } +} diff --git a/BeautySalonView/BeautySalonDatabaseImplement/Implements/ProcedureStorage.cs b/BeautySalonView/BeautySalonDatabaseImplement/Implements/ProcedureStorage.cs new file mode 100644 index 0000000..5708dbe --- /dev/null +++ b/BeautySalonView/BeautySalonDatabaseImplement/Implements/ProcedureStorage.cs @@ -0,0 +1,131 @@ +using BeautySalonContracts.BindingModels; +using BeautySalonContracts.SearchModels; +using BeautySalonContracts.StoragesContracts; +using BeautySalonContracts.ViewModels; +using BeautySalonDatabaseImplement.Models; +using Microsoft.EntityFrameworkCore; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BeautySalonDatabaseImplement.Implements +{ + public class ProcedureStorage : IProcedureStorage + { + public ProcedureViewModel? Delete(ProcedureBindingModel model) + { + using var context = new BeautySalonDatabase(); + var element = context.Procedures + .Include(x => x.Cosmetics) + .Include(x => x.Orders) + .FirstOrDefault(rec => rec.Id == model.Id); + if (element != null) + { + context.Procedures.Remove(element); + context.SaveChanges(); + return element.GetViewModel; + } + return null; + } + + public ProcedureViewModel? GetElement(ProcedureSearchModel model) + { + if (string.IsNullOrEmpty(model.ProcedureName) && !model.Id.HasValue) + { + return null; + } + using var context = new BeautySalonDatabase(); + return context.Procedures + .Include(x => x.Cosmetics) + .ThenInclude(x => x.Cosmetic) + .FirstOrDefault(x => (!string.IsNullOrEmpty(model.ProcedureName) && x.ProcedureName == model.ProcedureName) || + (model.Id.HasValue && x.Id == model.Id)) + ?.GetViewModel; + } + public int GetNumberOfPages(int userId, int pageSize) + { + using var context = new BeautySalonDatabase(); + int carsCount = context.Procedures.Where(c => c.ClientId == userId).Count(); + int numberOfpages = (int)Math.Ceiling((double)carsCount / pageSize); + return numberOfpages != 0 ? numberOfpages : 1; + } + + public List GetFilteredList(ProcedureSearchModel model) + { + using var context = new BeautySalonDatabase(); + if (model.Id.HasValue) + { + return context.Procedures + .Where(x => x.Id == model.Id) + .Select(x => x.GetViewModel) + .ToList(); + } + if (model.ClientId.HasValue && model.PageNumber.HasValue && model.PageSize.HasValue) + { + return context.Procedures + .Where(x => x.ClientId == model.ClientId) + .Skip(model.PageSize.Value * (model.PageNumber.Value - 1)) + .Take(model.PageSize.Value) + .Select(x => x.GetViewModel) + .ToList(); + } + if (model.ClientId.HasValue) + { + return context.Procedures + .Where(x => x.ClientId == model.ClientId) + .Select(x => x.GetViewModel) + .ToList(); + } + return new(); + } + + public List GetFullList() + { + using var context = new BeautySalonDatabase(); + return context.Procedures + .Include(x => x.Cosmetics) + .ThenInclude(x => x.Cosmetic) + .Select(x => x.GetViewModel) + .ToList(); + } + + public ProcedureViewModel? Insert(ProcedureBindingModel model) + { + using var context = new BeautySalonDatabase(); + var newProcedure = Procedure.Create(context, model); + if (newProcedure == null) + { + return null; + } + context.Procedures.Add(newProcedure); + context.SaveChanges(); + return newProcedure.GetViewModel; + } + + public ProcedureViewModel? Update(ProcedureBindingModel model) + { + using var context = new BeautySalonDatabase(); + using var transaction = context.Database.BeginTransaction(); + try + { + var procedure = context.Procedures.FirstOrDefault(rec => rec.Id == model.Id); + if (procedure == null) + { + return null; + } + procedure.Update(model); + context.SaveChanges(); + procedure.UpdateCosmetics(context, model); + transaction.Commit(); + return procedure.GetViewModel; + } + catch + { + transaction.Rollback(); + throw; + } + } + } +} diff --git a/BeautySalonView/BeautySalonDatabaseImplement/Models/Client.cs b/BeautySalonView/BeautySalonDatabaseImplement/Models/Client.cs new file mode 100644 index 0000000..472dfb6 --- /dev/null +++ b/BeautySalonView/BeautySalonDatabaseImplement/Models/Client.cs @@ -0,0 +1,72 @@ +using BeautySalonContracts.BindingModels; +using BeautySalonContracts.ViewModels; +using BeautySalonDataModels.Models; +using System.ComponentModel.DataAnnotations; +using System.ComponentModel.DataAnnotations.Schema; + +namespace BeautySalonDatabaseImplement.Models +{ + public class Client : IClientModel + { + public int Id { get; set; } + + [Required] + public string ClientLogin { get; set; } = string.Empty; + + [Required] + public string ClientFIO { get; set; } = string.Empty; + [Required] + public string ClientEmail { get; set; } = string.Empty; + + [Required] + public string ClientPassword { get; set; } = string.Empty; + + [ForeignKey("ClientId")] + public virtual List Evaluations { get; set; } = new(); + + [ForeignKey("ClientId")] + public virtual List Orders { get; set; } = new(); + + [ForeignKey("ClientId")] + public virtual List Procedures { get; set; } = new(); + + public static Client? Create(ClientBindingModel model) + { + + if (model == null) + { + return null; + } + return new Client() + { + Id = model.Id, + ClientLogin = model.ClientLogin, + ClientFIO = model.ClientFIO, + ClientEmail = model.ClientEmail, + ClientPassword = model.ClientPassword, + }; + } + + public void Update(ClientBindingModel model) + { + if (model == null) + { + return; + } + ClientLogin = model.ClientLogin; + ClientFIO = model.ClientFIO; + ClientEmail = model.ClientEmail; + ClientPassword = model.ClientPassword; + } + + public ClientViewModel GetViewModel => new() + { + Id = Id, + ClientLogin = ClientLogin, + ClientFIO = ClientFIO, + ClientEmail = ClientEmail, + ClientPassword = ClientPassword, + }; + + } +} diff --git a/BeautySalonView/BeautySalonDatabaseImplement/Models/Evaluation.cs b/BeautySalonView/BeautySalonDatabaseImplement/Models/Evaluation.cs new file mode 100644 index 0000000..4d55a68 --- /dev/null +++ b/BeautySalonView/BeautySalonDatabaseImplement/Models/Evaluation.cs @@ -0,0 +1,69 @@ +using BeautySalonContracts.BindingModels; +using BeautySalonContracts.ViewModels; +using BeautySalonDataModels.Models; +using System; +using System.Collections.Generic; +using System.ComponentModel.DataAnnotations; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BeautySalonDatabaseImplement.Models +{ + public class Evaluation : IEvaluationModel + { + public int Id { get; set; } + + [Required] + public double PointsProcedure { get; set; } + + [Required] + public double PointsCosmetics { get; set; } + + [Required] + public int ProcedureId { get; set; } + + public int ClientId { get; set; } + + public virtual Client Client { get; set; } + + public virtual Procedure Procedure { get; set; } + + public static Evaluation? Create(EvaluationBindingModel? model) + { + if (model == null) + { + return null; + } + return new Evaluation() + { + Id = model.Id, + PointsProcedure=model.PointsProcedure, + PointsCosmetics=model.PointsCosmetics, + ProcedureId=model.ProcedureId, + ClientId=model.ClientId, + }; + } + + public void Update(EvaluationBindingModel? model) + { + if (model == null) + { + return; + } + PointsProcedure = model.PointsProcedure; + PointsCosmetics = model.PointsCosmetics; + ProcedureId = model.ProcedureId; + } + + public EvaluationViewModel GetViewModel => new() + { + Id = Id, + PointsProcedure=PointsProcedure, + PointsCosmetics=PointsCosmetics, + ProcedureId=ProcedureId, + ClientId=ClientId, + ProcedureName = Procedure.ProcedureName + }; + } +} diff --git a/BeautySalonView/BeautySalonDatabaseImplement/Models/Order.cs b/BeautySalonView/BeautySalonDatabaseImplement/Models/Order.cs new file mode 100644 index 0000000..e8e0360 --- /dev/null +++ b/BeautySalonView/BeautySalonDatabaseImplement/Models/Order.cs @@ -0,0 +1,142 @@ +using BeautySalonContracts.BindingModels; +using BeautySalonContracts.ViewModels; +using BeautySalonDataModels.Models; +using System; +using System.Collections.Generic; +using System.ComponentModel.DataAnnotations; +using System.ComponentModel.DataAnnotations.Schema; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BeautySalonDatabaseImplement.Models +{ + public class Order : IOrderModel + { + public int Id { get; set; } + + [Required] + public DateTime OrderDate { get; set; } + + [Required] + public double OrderAmount { get; set; } + + [Required] + public int ClientId { get; set; } + public virtual Client? Client { get; set; } + + private List? _orderServices = null; + + private List? _orderProcedures = null; + + [NotMapped] + public List OrderServices + { + get + { + _orderServices ??= Services + .Select(pc => new OrderServiceViewModel(pc.Service.GetViewModel, pc.OrderServiceCount)) + .ToList(); + return _orderServices; + } + } + + [NotMapped] + public List OrderProcedures + { + get + { + _orderProcedures ??= Procedures + .Select(pc => new OrderProcedureViewModel(pc.Procedure.GetViewModel, pc.OrderProcedureCount)) + .ToList(); + return _orderProcedures; + } + } + + // связь услуги и заказов многие - ко - многим + [ForeignKey("OrderId")] + public virtual List Services { get; set; } = new(); + + [ForeignKey("OrderId")] + public virtual List Procedures { get; set; } = new(); + + public static Order Create(BeautySalonDatabase context, OrderBindingModel model) + { + return new Order() + { + Id = model.Id, + OrderDate = model.OrderDate, + OrderAmount = model.OrderAmount, + Services = model.OrderServices.Select(x => new OrderService() + { + Service = context.Services.First(y => y.Id == x.Service.Id), + OrderServiceCount = x.Count + }).ToList(), + Procedures = model.OrderProcedures.Select(x => new OrderCosmetic() + { + Procedure = context.Procedures.First(y => y.Id == x.Procedure.Id), + OrderProcedureCount = x.Count + }).ToList(), + ClientId = model.ClientId, + }; + } + + public void Update(OrderBindingModel model) + { + OrderDate = model.OrderDate; + OrderAmount = model.OrderAmount; + } + + public OrderViewModel GetViewModel => new() + { + Id = Id, + OrderDate = OrderDate, + OrderAmount = OrderAmount, + OrderServices = OrderServices, + OrderProcedures = OrderProcedures, + ClientId = ClientId + }; + + public void UpdateServices(BeautySalonDatabase context, OrderBindingModel model) + { + var orderServices = context.OrderServices + .Where(x => x.OrderId == model.Id) + .ToList(); + context.OrderServices + .RemoveRange(orderServices); + var order = context.Orders.First(x => x.Id == Id); + foreach (var record in model.OrderServices) + { + context.OrderServices.Add(new OrderService + { + Order = order, + Service = context.Services.First(x => x.Id == record.Service.Id), + OrderServiceCount = record.Count + }); + context.SaveChanges(); + } + _orderServices = null; + } + + public void UpdateProcedures(BeautySalonDatabase context, OrderBindingModel model) + { + var orderProcedures = context.OrderProcedures + .Where(x => x.OrderId == model.Id) + .ToList(); + context.OrderProcedures + .RemoveRange(orderProcedures); + var order = context.Orders.First(x => x.Id == Id); + foreach (var record in model.OrderProcedures) + { + context.OrderProcedures.Add(new OrderCosmetic + { + Order = order, + Procedure = context.Procedures.First(x => x.Id == record.Procedure.Id), + OrderProcedureCount = record.Count + }); + context.SaveChanges(); + } + _orderProcedures = null; + } + } +} diff --git a/BeautySalonView/BeautySalonDatabaseImplement/Models/OrderCosmetic.cs b/BeautySalonView/BeautySalonDatabaseImplement/Models/OrderCosmetic.cs new file mode 100644 index 0000000..3689f4e --- /dev/null +++ b/BeautySalonView/BeautySalonDatabaseImplement/Models/OrderCosmetic.cs @@ -0,0 +1,27 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel.DataAnnotations; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BeautySalonDatabaseImplement.Models +{ + public class OrderCosmetic + { + public int Id { get; set; } + + [Required] + public int OrderId { get; set; } + + [Required] + public int ProcedureId { get; set; } + + [Required] + public int OrderProcedureCount { get; set; } + + public virtual Order Order { get; set; } = new(); + + public virtual Procedure Procedure { get; set; } = new(); + } +} diff --git a/BeautySalonView/BeautySalonDatabaseImplement/Models/Procedure.cs b/BeautySalonView/BeautySalonDatabaseImplement/Models/Procedure.cs new file mode 100644 index 0000000..71f7184 --- /dev/null +++ b/BeautySalonView/BeautySalonDatabaseImplement/Models/Procedure.cs @@ -0,0 +1,121 @@ +using BeautySalonContracts.BindingModels; +using BeautySalonContracts.ViewModels; +using BeautySalonDataModels.Models; +using System; +using System.Collections.Generic; +using System.ComponentModel.DataAnnotations; +using System.ComponentModel.DataAnnotations.Schema; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BeautySalonDatabaseImplement.Models +{ + public class Procedure : IProcedureModel + { + public int Id { get; set; } + + [Required] + public string ProcedureName { get; set; } = string.Empty; + + [Required] + public double ProcedurePrice { get; set; } + + public int ClientId { get; set; } + + public virtual Client Client { get; set; } = null!; + + private List? _procedureCosmetics = null; + + [NotMapped] + public List ProcedureCosmetics + { + get + { + _procedureCosmetics ??= Cosmetics + .Select(pc => new ProcedureCosmeticViewModel(pc.Cosmetic.GetViewModel, pc.ProcedureCosmeticCount)) + .ToList(); + return _procedureCosmetics; + } + } + // связь процедуры и оценок один - ко - многим + [ForeignKey("ProcedureId")] + public virtual List Ratings { get; set; } = new(); + + private List? _procedureRatings = null; + [NotMapped] + public List ProcedureRatings + { + get + { + _procedureRatings ??= Ratings + .Select(x => x.GetViewModel) + .ToList(); + return _procedureRatings; + } + } + + // связь процедур и косметки многие - ко - многим + [ForeignKey("ProcedureId")] + public virtual List Cosmetics { get; set; } = new(); + + // связь процедур и заказов многие - ко - многим + [ForeignKey("ProcedureId")] + public virtual List Orders { get; set; } = new(); + + + public static Procedure Create(BeautySalonDatabase context, ProcedureBindingModel model) + { + return new Procedure() + { + Id = model.Id, + ProcedureName = model.ProcedureName, + ProcedurePrice = model.ProcedurePrice, + Cosmetics = model.ProcedureCosmetics.Select(x => new ProcedureCosmetic() + { + Cosmetic = context.Cosmetics.First(y => y.Id == x.Cosmetic.Id), + ProcedureCosmeticCount = x.Count + }).ToList(), + ClientId = model.ClientId, + }; + } + + public void Update(ProcedureBindingModel model) + { + ProcedureName = model.ProcedureName; + ProcedurePrice = model.ProcedurePrice; + } + + public ProcedureViewModel GetViewModel => new() + { + Id = Id, + ProcedureName = ProcedureName, + ProcedurePrice = ProcedurePrice, + ProcedureCosmetics = ProcedureCosmetics, + ProcedureRatings = ProcedureRatings, + ClientId = ClientId + }; + + public void UpdateCosmetics(BeautySalonDatabase context, ProcedureBindingModel model) + { + var procedureCosmetics = context.ProcedureCosmetics + .Where(x => x.ProcedureId == model.Id) + .ToList(); + context.ProcedureCosmetics + .RemoveRange(procedureCosmetics); + var procedure = context.Procedures.First(x => x.Id == Id); + foreach (var record in model.ProcedureCosmetics) + { + context.ProcedureCosmetics.Add(new ProcedureCosmetic + { + Procedure = procedure, + Cosmetic = context.Cosmetics.First(x => x.Id == record.Cosmetic.Id), + ProcedureCosmeticCount = record.Count + }); + context.SaveChanges(); + } + _procedureCosmetics = null; + } + + } +}