diff --git a/BeautyStudio/BeautyStudioBusinessLogic/BusinessLogic/OrderLogic.cs b/BeautyStudio/BeautyStudioBusinessLogic/BusinessLogic/OrderLogic.cs index 6f78571..25f9494 100644 --- a/BeautyStudio/BeautyStudioBusinessLogic/BusinessLogic/OrderLogic.cs +++ b/BeautyStudio/BeautyStudioBusinessLogic/BusinessLogic/OrderLogic.cs @@ -92,10 +92,10 @@ namespace BeautyStudioBusinessLogic.BusinessLogics { return; } - if (model.OrderAmount <= 0) + if (model.Sum <= 0) { throw new ArgumentNullException("Cумма заказа должна быть больше 0", - nameof(model.OrderAmount)); + nameof(model.Sum)); } } } diff --git a/BeautyStudio/BeautyStudioBusinessLogic/BusinessLogic/ProcedureLogic.cs b/BeautyStudio/BeautyStudioBusinessLogic/BusinessLogic/ProcedureLogic.cs index 84a0e39..1b40c15 100644 --- a/BeautyStudio/BeautyStudioBusinessLogic/BusinessLogic/ProcedureLogic.cs +++ b/BeautyStudio/BeautyStudioBusinessLogic/BusinessLogic/ProcedureLogic.cs @@ -100,13 +100,13 @@ namespace BeautyStudioBusinessLogic.BusinessLogics throw new ArgumentNullException("Нет названия процедуры", nameof(model.ProcedureName)); } - if (model.ProcedurePrice <= 0) + if (model.ProcedureCost <= 0) { throw new ArgumentNullException("Цена процедуры должна быть больше 0", - nameof(model.ProcedurePrice)); + nameof(model.ProcedureCost)); } _logger.LogInformation("Procedure. ProcedureName: {ProcedureName}. Cost: {Cost}. Id: {Id}", - model.ProcedureName, model.ProcedurePrice, model.Id); + model.ProcedureName, model.ProcedureCost, model.Id); var element = _procedureStorage.GetElement(new ProcedureSearchModel { ProcedureName = model.ProcedureName diff --git a/BeautyStudio/BeautyStudioBusinessLogic/BusinessLogic/ServiceLogic.cs b/BeautyStudio/BeautyStudioBusinessLogic/BusinessLogic/ServiceLogic.cs index 77bd596..047a5cb 100644 --- a/BeautyStudio/BeautyStudioBusinessLogic/BusinessLogic/ServiceLogic.cs +++ b/BeautyStudio/BeautyStudioBusinessLogic/BusinessLogic/ServiceLogic.cs @@ -99,13 +99,13 @@ namespace BeautyStudioBusinessLogic.BusinessLogics throw new ArgumentNullException("Нет названия услуги", nameof(model.ServiceName)); } - if (model.ServicePrice <= 0) + if (model.Sum <= 0) { throw new ArgumentNullException("Цена услуги должна быть больше 0", - nameof(model.ServicePrice)); + nameof(model.Sum)); } _logger.LogInformation("Service. ServiceName: {ServiceName}. Cost: {Cost}. Id: {Id}", - model.ServiceName, model.ServicePrice, model.Id); + model.ServiceName, model.Sum, model.Id); var element = _serviceStorage.GetElement(new ServiceSearchModel { ServiceName = model.ServiceName diff --git a/BeautyStudio/BeautyStudioBusinessLogic/BusinessLogic/StoreKeeperLogic.cs b/BeautyStudio/BeautyStudioBusinessLogic/BusinessLogic/StoreKeeperLogic.cs new file mode 100644 index 0000000..36fc316 --- /dev/null +++ b/BeautyStudio/BeautyStudioBusinessLogic/BusinessLogic/StoreKeeperLogic.cs @@ -0,0 +1,159 @@ +using BeautyStudioContracts.BindingModels; +using BeautyStudioContracts.BusinessLogicContracts; +using BeautyStudioContracts.SearchModels; +using BeautyStudioContracts.StoragesContracts; +using BeautyStudioContracts.ViewModels; +using Microsoft.Extensions.Logging; + +namespace BeautyStudioBusinessLogic.BusinessLogics +{ + public class StoreKeeperLogic : IStoreKeeperLogic + { + private readonly int _passwordMaxLength = 25; + private readonly int _passwordMinLength = 6; + + private readonly ILogger _logger; + private readonly IStoreKeeperStorage _storeKeeperStorage; + public StoreKeeperLogic(ILogger logger, IStoreKeeperStorage storeKeeperStorage) + { + _logger = logger; + _storeKeeperStorage = storeKeeperStorage; + } + public bool Create(StoreKeeperBindingModel model) + { + CheckModel(model); + + if (_storeKeeperStorage.Insert(model) == null) + { + _logger.LogWarning("Insert operation failed"); + + return false; + } + + return true; + } + + public bool Delete(StoreKeeperBindingModel model) + { + CheckModel(model, false); + + _logger.LogInformation("Delete. Id: {Id}", model.Id); + + if (_storeKeeperStorage.Delete(model) == null) + { + _logger.LogWarning("Delete operation failed"); + + return false; + } + + return true; + } + + public StoreKeeperViewModel? ReadElement(StoreKeeperSearchModel model) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + + _logger.LogInformation("ReadElement. StoreKeeperLogin: {StoreKeeperLogin}. StoreKeeperEmail: {StoreKeeperEmail} Id: {Id}", + model.StoreKeeperLogin, model.StoreKeeperEmail, model.Id); + + var element = _storeKeeperStorage.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(StoreKeeperSearchModel? model) + { + _logger.LogInformation("ReadElement. StoreKeeperLogin: {StoreKeeperLogin}. StoreKeeperEmail: {StoreKeeperEmail} Id: {Id}", + model?.StoreKeeperLogin, model?.StoreKeeperEmail, model?.Id); + + var list = model == null ? _storeKeeperStorage.GetFullList() : _storeKeeperStorage.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(StoreKeeperBindingModel model) + { + CheckModel(model); + + if (_storeKeeperStorage.Update(model) == null) + { + _logger.LogWarning("Update operation failed"); + return false; + } + return true; + } + private void CheckModel(StoreKeeperBindingModel model, bool withParams = true) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + + if (!withParams) + { + return; + } + if (string.IsNullOrEmpty(model.StoreKeeperFIO)) + { + throw new ArgumentNullException("Нет имени кладовщика", nameof(model.StoreKeeperLogin)); + } + if (string.IsNullOrEmpty(model.StoreKeeperLogin)) + { + throw new ArgumentNullException("Нет логина кладовщика", nameof(model.StoreKeeperLogin)); + } + if (string.IsNullOrEmpty(model.StoreKeeperEmail)) + { + throw new ArgumentNullException("Нет почты кладовщика", nameof(model.StoreKeeperEmail)); + } + if (string.IsNullOrEmpty(model.StoreKeeperPassword)) + { + throw new ArgumentNullException("Нет пароля кладовщика", nameof(model.StoreKeeperPassword)); + } + if (string.IsNullOrEmpty(model.StoreKeeperPhone)) + { + throw new ArgumentNullException("Нет телефона кладовщика", nameof(model.StoreKeeperEmail)); + } + + if (model.StoreKeeperPassword.Length < _passwordMinLength) + { + throw new ArgumentNullException("Пароль слишком короткий", nameof(model.StoreKeeperPassword)); + } + + if (model.StoreKeeperPassword.Length > _passwordMaxLength) + { + throw new ArgumentNullException("Пароль слишком длинный", nameof(model.StoreKeeperPassword)); + } + _logger.LogInformation("ReadElement. StoreKeeperLogin: {StoreKeeperLogin}. StoreKeeperEmail: {StoreKeeperEmail} Id: {Id}", + model.StoreKeeperLogin, model.StoreKeeperEmail, model.Id); + + var element = _storeKeeperStorage.GetElement(new StoreKeeperSearchModel + { + StoreKeeperEmail = model.StoreKeeperEmail + }); + + if (element != null && element.Id != model.Id) + { + throw new InvalidOperationException("Кладовщик с такой почтой уже есть"); + } + } + } +} diff --git a/BeautyStudio/BeautyStudioContracts/BindingModels/OrderBindingModel.cs b/BeautyStudio/BeautyStudioContracts/BindingModels/OrderBindingModel.cs index 6d5c3d7..69700ea 100644 --- a/BeautyStudio/BeautyStudioContracts/BindingModels/OrderBindingModel.cs +++ b/BeautyStudio/BeautyStudioContracts/BindingModels/OrderBindingModel.cs @@ -13,7 +13,7 @@ namespace BeautyStudioContracts.BindingModels public int Id { get; set; } public double Sum { get; set; } public DateTime DateCreate { get; set; } = DateTime.Now; - public DateTime DateComplete { get; set; } + public DateTime? DateComplete { get; set; } public OrderStatus Status { get; set; } = OrderStatus.Неизвестен; public int ClientId { get; set; } public int ServiceId { get; set; } diff --git a/BeautyStudio/BeautyStudioContracts/BindingModels/ServiceBindingModel.cs b/BeautyStudio/BeautyStudioContracts/BindingModels/ServiceBindingModel.cs index 5d2c313..b4d05b5 100644 --- a/BeautyStudio/BeautyStudioContracts/BindingModels/ServiceBindingModel.cs +++ b/BeautyStudio/BeautyStudioContracts/BindingModels/ServiceBindingModel.cs @@ -13,6 +13,5 @@ namespace BeautyStudioContracts.BindingModels public string ServiceName { get; set; } = string.Empty; public double Sum { get; set; } public int StaffId { get; set; } - public Dictionary Procedures { get; set; } = new(); } } diff --git a/BeautyStudio/BeautyStudioContracts/BusinessLogicContracts/IOrderLogic.cs b/BeautyStudio/BeautyStudioContracts/BusinessLogicContracts/IOrderLogic.cs index c9c871b..a24537e 100644 --- a/BeautyStudio/BeautyStudioContracts/BusinessLogicContracts/IOrderLogic.cs +++ b/BeautyStudio/BeautyStudioContracts/BusinessLogicContracts/IOrderLogic.cs @@ -12,6 +12,5 @@ namespace BeautyStudioContracts.BusinessLogicContracts bool Create(OrderBindingModel model); bool Delete(OrderBindingModel model); bool Update(OrderBindingModel model); - int GetNumberOfPages(int userId, int pageSize = 10); } } diff --git a/BeautyStudio/BeautyStudioContracts/BusinessLogicContracts/IStoreKeeperLogic.cs b/BeautyStudio/BeautyStudioContracts/BusinessLogicContracts/IStoreKeeperLogic.cs new file mode 100644 index 0000000..799100b --- /dev/null +++ b/BeautyStudio/BeautyStudioContracts/BusinessLogicContracts/IStoreKeeperLogic.cs @@ -0,0 +1,20 @@ +using BeautyStudioContracts.BindingModels; +using BeautyStudioContracts.SearchModels; +using BeautyStudioContracts.ViewModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BeautyStudioContracts.BusinessLogicContracts +{ + public interface IStoreKeeperLogic + { + List? ReadList(StoreKeeperSearchModel? model); + StoreKeeperViewModel? ReadElement(StoreKeeperSearchModel model); + bool Create(StoreKeeperBindingModel model); + bool Update(StoreKeeperBindingModel model); + bool Delete(StoreKeeperBindingModel model); + } +} diff --git a/BeautyStudio/BeautyStudioContracts/ViewModels/ProcedureCosmeticsViewModel.cs b/BeautyStudio/BeautyStudioContracts/ViewModels/ProcedureCosmeticsViewModel.cs new file mode 100644 index 0000000..87316ae --- /dev/null +++ b/BeautyStudio/BeautyStudioContracts/ViewModels/ProcedureCosmeticsViewModel.cs @@ -0,0 +1,24 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BeautyStudioContracts.ViewModels +{ + public class ProcedureCosmeticsViewModel + { + public CosmeticViewModel Cosmetic { get; set; } = null!; + public ProcedureViewModel Procedure { get; set; } = null!; + public int Count { get; set; } + + public ProcedureCosmeticsViewModel() { } + + public ProcedureCosmeticsViewModel(CosmeticViewModel cosmetic, ProcedureViewModel procedure, int count) + { + Cosmetic = cosmetic; + Procedure = procedure; + Count = count; + } + } +} diff --git a/BeautyStudio/BeautyStudioDatabaseImplement/BeautyStudioDatabase.cs b/BeautyStudio/BeautyStudioDatabaseImplement/BeautyStudioDatabase.cs index cf784e8..0b8f44e 100644 --- a/BeautyStudio/BeautyStudioDatabaseImplement/BeautyStudioDatabase.cs +++ b/BeautyStudio/BeautyStudioDatabaseImplement/BeautyStudioDatabase.cs @@ -24,6 +24,7 @@ namespace BeautyStudioDatabaseImplement public virtual DbSet Procedures { set; get; } public virtual DbSet ProcedureCosmetics { set; get; } public virtual DbSet Staffs { set; get; } + public virtual DbSet StoreKeepers { set; get; } public virtual DbSet Clients { set; get; } } } diff --git a/BeautyStudio/BeautyStudioDatabaseImplement/Implements/CosmeticStorage.cs b/BeautyStudio/BeautyStudioDatabaseImplement/Implements/CosmeticStorage.cs index 64504aa..392ecc7 100644 --- a/BeautyStudio/BeautyStudioDatabaseImplement/Implements/CosmeticStorage.cs +++ b/BeautyStudio/BeautyStudioDatabaseImplement/Implements/CosmeticStorage.cs @@ -101,7 +101,7 @@ namespace BeautyStudioDatabaseImplement.Implements return new(); } using var context = new BeautyStudioDatabase(); - var procedures = context.CosmeticProcedures + var procedures = context.ProcedureCosmetics .Where(x => x.CosmeticId == model.Id) .Select(x => x.Procedure.GetViewModel) .ToList(); diff --git a/BeautyStudio/BeautyStudioDatabaseImplement/Implements/ProcedureStorage.cs b/BeautyStudio/BeautyStudioDatabaseImplement/Implements/ProcedureStorage.cs index 83062a3..f1370a3 100644 --- a/BeautyStudio/BeautyStudioDatabaseImplement/Implements/ProcedureStorage.cs +++ b/BeautyStudio/BeautyStudioDatabaseImplement/Implements/ProcedureStorage.cs @@ -118,7 +118,7 @@ namespace BeautyStudioDatabaseImplement.Implements return new(); } using var context = new BeautyStudioDatabase(); - var cosmetics = context.CosmeticProcedures + var cosmetics = context.ProcedureCosmetics .Where(x => x.ProcedureId == model.Id) .Select(x => x.Cosmetic.GetViewModel) .ToList(); diff --git a/BeautyStudio/BeautyStudioDatabaseImplement/Implements/StoreKeeperStorage.cs b/BeautyStudio/BeautyStudioDatabaseImplement/Implements/StoreKeeperStorage.cs new file mode 100644 index 0000000..53f14d2 --- /dev/null +++ b/BeautyStudio/BeautyStudioDatabaseImplement/Implements/StoreKeeperStorage.cs @@ -0,0 +1,97 @@ +using BeautyStudioContracts.BindingModels; +using BeautyStudioContracts.SearchModels; +using BeautyStudioContracts.StoragesContracts; +using BeautyStudioContracts.ViewModels; +using BeautyStudioDatabaseImplement.Models; +using Microsoft.EntityFrameworkCore; +using System.Collections.Generic; +using System.Linq; + +namespace BeautyStudioDatabaseImplement.Implements +{ + public class StoreKeeperStorage : IStoreKeeperStorage + { + public StoreKeeperViewModel? Delete(StoreKeeperBindingModel model) + { + using var context = new BeautyStudioDatabase(); + + var element = context.StoreKeepers.FirstOrDefault(rec => rec.Id == model.Id); + + if (element != null) + { + context.StoreKeepers.Remove(element); + context.SaveChanges(); + + return element.GetViewModel; + } + + return null; + } + + public StoreKeeperViewModel? GetElement(StoreKeeperSearchModel model) + { + using var context = new BeautyStudioDatabase(); + if (model.Id.HasValue) + return context.StoreKeepers + .FirstOrDefault(x => x.Id == model.Id)? + .GetViewModel; + + if (!string.IsNullOrEmpty(model.StoreKeeperPassword) && + !string.IsNullOrEmpty(model.StoreKeeperLogin)) + return context.StoreKeepers + .FirstOrDefault(x => + x.StoreKeeperPassword.Equals(model.StoreKeeperPassword) && + x.StoreKeeperLogin.Equals(model.StoreKeeperLogin))? + .GetViewModel; + + return null; + } + + public List GetFilteredList(StoreKeeperSearchModel model) + { + throw new NotImplementedException(); + } + + public List GetFullList() + { + using var context = new BeautyStudioDatabase(); + return context.StoreKeepers + .Select(x => x.GetViewModel) + .ToList(); + } + + public StoreKeeperViewModel? Insert(StoreKeeperBindingModel model) + { + using var context = new BeautyStudioDatabase(); + + var newStoreKeepers = StoreKeeper.Create(model); + + if (newStoreKeepers == null) + { + return null; + } + + context.StoreKeepers.Add(newStoreKeepers); + context.SaveChanges(); + + return newStoreKeepers.GetViewModel; + } + + public StoreKeeperViewModel? Update(StoreKeeperBindingModel model) + { + using var context = new BeautyStudioDatabase(); + + var StoreKeepers = context.StoreKeepers.FirstOrDefault(x => x.Id == model.Id); + + if (StoreKeepers == null) + { + return null; + } + + StoreKeepers.Update(model); + context.SaveChanges(); + + return StoreKeepers.GetViewModel; + } + } +} diff --git a/BeautyStudio/BeautyStudioDatabaseImplement/Models/Client.cs b/BeautyStudio/BeautyStudioDatabaseImplement/Models/Client.cs index 925583d..b9ed321 100644 --- a/BeautyStudio/BeautyStudioDatabaseImplement/Models/Client.cs +++ b/BeautyStudio/BeautyStudioDatabaseImplement/Models/Client.cs @@ -20,9 +20,9 @@ namespace BeautyStudioDatabaseImplement.Models [Required] public string ClientPhone { get; set; } = string.Empty; [Required] - public string ClientPassword { get; set; } = string.Empty; + //связь один-ко-многим клиента с заказами [ForeignKey("ClientId")] public virtual List Orders { get; set; } = new(); diff --git a/BeautyStudio/BeautyStudioDatabaseImplement/Models/Cosmetic.cs b/BeautyStudio/BeautyStudioDatabaseImplement/Models/Cosmetic.cs index f789417..e737bf5 100644 --- a/BeautyStudio/BeautyStudioDatabaseImplement/Models/Cosmetic.cs +++ b/BeautyStudio/BeautyStudioDatabaseImplement/Models/Cosmetic.cs @@ -28,6 +28,10 @@ namespace BeautyStudioDatabaseImplement.Models public int LaborCostId { get; set; } public virtual LaborCost LaborCost { get; set; } = new(); + // связь многие-ко-многим косметики с процедурами + [ForeignKey("CosmeticId")] + public virtual List Procedures { get; set; } = new(); + public static Cosmetic Create(CosmeticBindingModel model) { diff --git a/BeautyStudio/BeautyStudioDatabaseImplement/Models/LaborCost.cs b/BeautyStudio/BeautyStudioDatabaseImplement/Models/LaborCost.cs index 4851f7c..9e433d2 100644 --- a/BeautyStudio/BeautyStudioDatabaseImplement/Models/LaborCost.cs +++ b/BeautyStudio/BeautyStudioDatabaseImplement/Models/LaborCost.cs @@ -21,6 +21,8 @@ namespace BeautyStudioDatabaseImplement.Models public virtual Staff Staff { get; set; } + // связь один-ко-многим трудозатрат с косметикой + [ForeignKey("LaborCostId")] public virtual List Cosmetics { get; set; } = new(); public static LaborCost? Create(LaborCostBindingModel? model) diff --git a/BeautyStudio/BeautyStudioDatabaseImplement/Models/Procedure.cs b/BeautyStudio/BeautyStudioDatabaseImplement/Models/Procedure.cs index ad5a9a6..6a59170 100644 --- a/BeautyStudio/BeautyStudioDatabaseImplement/Models/Procedure.cs +++ b/BeautyStudio/BeautyStudioDatabaseImplement/Models/Procedure.cs @@ -19,53 +19,36 @@ namespace BeautyStudioDatabaseImplement.Models public string ProcedureName { get; set; } = string.Empty; [Required] - public double ProcedurePrice { get; set; } + public double ProcedureCost { get; set; } [Required] - public double ProcedureDuration { get; set; } + public string ProcedureDescription { get; set; } + + [Required] + public double ProcedureDescription { get; set; } public int ClientId { get; set; } public virtual Client Client { get; set; } = null!; - // связь процедуры и оценок один - ко - многим + // связь процедур и косметики многие - ко - многим [ForeignKey("ProcedureId")] - public virtual List Evaluations { get; set; } = new(); - private List? _procedureEvaluations = null; - [NotMapped] - public List ProcedureEvaluations - { - get - { - _procedureEvaluations ??= Evaluations - .Select(x => x.GetViewModel) - .ToList(); - return _procedureEvaluations; - } - } + public virtual List Cosmetics { get; set; } = new(); - // связь процедур и косметки многие - ко - многим - [ForeignKey("ProcedureId")] - public virtual List Cosmetics { get; set; } = new(); - - private List? _cosmeticProcedures = null; + private List? _cosmeticProcedures = null; [NotMapped] - public List CosmeticProcedures + public List CosmeticProcedures { get { _cosmeticProcedures ??= Cosmetics - .Select(pc => new CosmeticProcedureViewModel(pc.Cosmetic.GetViewModel, pc.Procedure.GetViewModel, pc.ProcedureCosmeticCount)) + .Select(pc => new ProcedureCosmeticsViewModel(pc.Cosmetic.GetViewModel, pc.Procedure.GetViewModel, pc.ProcedureCosmeticCount)) .ToList(); return _cosmeticProcedures; } } - // связь процедур и заказов многие - ко - многим - [ForeignKey("ProcedureId")] - public virtual List Orders { get; set; } = new(); - - // связь процедур и заказов многие - ко - многим + // связь процедур и услуг многие - ко - многим [ForeignKey("ProcedureId")] public virtual List Services { get; set; } = new(); @@ -76,9 +59,9 @@ namespace BeautyStudioDatabaseImplement.Models { Id = model.Id, ProcedureName = model.ProcedureName, - ProcedurePrice = model.ProcedurePrice, - ProcedureDuration = model.ProcedureDuration, - Cosmetics = model.ProcedureCosmetics.Select(x => new CosmeticProcedure() + ProcedureCost = model.ProcedureCost, + ProcedureDescription = model.ProcedureDescription, + Cosmetics = model.CosmeticProcedures.Select(x => new CosmeticProcedure() { Cosmetic = context.Cosmetics.First(y => y.Id == x.Cosmetic.Id), ProcedureCosmeticCount = x.Count @@ -90,17 +73,17 @@ namespace BeautyStudioDatabaseImplement.Models public void Update(ProcedureBindingModel model) { ProcedureName = model.ProcedureName; - ProcedurePrice = model.ProcedurePrice; - ProcedureDuration = model.ProcedureDuration; + ProcedureCost = model.ProcedureCost; + ProcedureDescription = model.ProcedureDescription; } public ProcedureViewModel GetViewModel => new() { Id = Id, ProcedureName = ProcedureName, - ProcedurePrice = ProcedurePrice, - ProcedureDuration = ProcedureDuration, - CosmeticProcedures = CosmeticProcedures, + ProcedureCost = ProcedureCost, + ProcedureDescription = ProcedureDescription, + ProcedureCosmetics = CosmeticProcedures, ClientId = ClientId }; diff --git a/BeautyStudio/BeautyStudioDatabaseImplement/Models/ProcedureCosmetics.cs b/BeautyStudio/BeautyStudioDatabaseImplement/Models/ProcedureCosmetics.cs index f7388e1..0626298 100644 --- a/BeautyStudio/BeautyStudioDatabaseImplement/Models/ProcedureCosmetics.cs +++ b/BeautyStudio/BeautyStudioDatabaseImplement/Models/ProcedureCosmetics.cs @@ -17,6 +17,9 @@ namespace BeautyStudioDatabaseImplement.Models [Required] public int CosmeticId { get; set; } + [Required] + public int ProcedureCosmeticCount { get; set; } + public virtual Procedure Procedure { get; set; } = new(); public virtual Cosmetic Cosmetic { get; set; } = new(); diff --git a/BeautyStudio/BeautyStudioDatabaseImplement/Models/Service.cs b/BeautyStudio/BeautyStudioDatabaseImplement/Models/Service.cs index 607ab26..a4bab47 100644 --- a/BeautyStudio/BeautyStudioDatabaseImplement/Models/Service.cs +++ b/BeautyStudio/BeautyStudioDatabaseImplement/Models/Service.cs @@ -27,6 +27,14 @@ namespace BeautyStudioDatabaseImplement.Models public int StaffId { get; set; } public virtual Staff Staff { get; set; } + // связь многие-ко-многим услуг с заказами + [ForeignKey("ServiceId")] + public virtual List Orders { get; set; } = new(); + + // связь многие-ко-многим услуг с процедурами + [ForeignKey("ServiceId")] + public virtual List Procedures { get; set; } = new(); + public static Service Create(BeautyStudioDatabase context, ServiceBindingModel model) { return new Service() diff --git a/BeautyStudio/BeautyStudioDatabaseImplement/Models/Staff.cs b/BeautyStudio/BeautyStudioDatabaseImplement/Models/Staff.cs index ca030bb..0f1f707 100644 --- a/BeautyStudio/BeautyStudioDatabaseImplement/Models/Staff.cs +++ b/BeautyStudio/BeautyStudioDatabaseImplement/Models/Staff.cs @@ -25,12 +25,18 @@ namespace BeautyStudioDatabaseImplement.Models [Required] public string StaffPhone { get; set; } = string.Empty; + //связь один-ко-многим с трудозатратами [ForeignKey("StaffId")] public virtual List LaborCost { get; set; } = new(); + // связь один-ко-многим с услугами [ForeignKey("StaffId")] public virtual List Services { get; set; } = new(); + // связь один-ко-многим с заказами + [ForeignKey("StaffId")] + public virtual List Orders { get; set; } = new(); + public static Staff? Create(StaffBindingModel model) { diff --git a/BeautyStudio/BeautyStudioDatabaseImplement/Models/StoreKeeper.cs b/BeautyStudio/BeautyStudioDatabaseImplement/Models/StoreKeeper.cs new file mode 100644 index 0000000..2098017 --- /dev/null +++ b/BeautyStudio/BeautyStudioDatabaseImplement/Models/StoreKeeper.cs @@ -0,0 +1,73 @@ +using BeautyStudioContracts.BindingModels; +using BeautyStudioContracts.ViewModels; +using BeautyStudioDataModels.Models; +using System.ComponentModel.DataAnnotations.Schema; +using System.ComponentModel.DataAnnotations; + +namespace BeautyStudioDatabaseImplement.Models +{ + public class StoreKeeper : IStoreKeeperModel + { + public int Id { get; set; } + + [Required] + public string StoreKeeperFIO { get; set; } = string.Empty; + + [Required] + public string StoreKeeperEmail { get; set; } = string.Empty; + + [Required] + public string StoreKeeperLogin { get; set; } = string.Empty; + + [Required] + public string StoreKeeperPassword { get; set; } = string.Empty; + + [Required] + public string StoreKeeperPhone { get; set; } = string.Empty; + + //связь один-ко-многим кладовщика с косметикой + [ForeignKey("StoreKeeperId")] + public virtual List Cosmetics { get; set; } = new(); + + public static StoreKeeper? Create(StoreKeeperBindingModel model) + { + + if (model == null) + { + return null; + } + return new StoreKeeper() + { + Id = model.Id, + StoreKeeperFIO = model.StoreKeeperFIO, + StoreKeeperLogin = model.StoreKeeperLogin, + StoreKeeperEmail = model.StoreKeeperEmail, + StoreKeeperPassword = model.StoreKeeperPassword, + StoreKeeperPhone = model.StoreKeeperPhone, + }; + } + + public void Update(StoreKeeperBindingModel model) + { + if (model == null) + { + return; + } + StoreKeeperFIO = model.StoreKeeperFIO; + StoreKeeperLogin = model.StoreKeeperLogin; + StoreKeeperEmail = model.StoreKeeperEmail; + StoreKeeperPassword = model.StoreKeeperPassword; + StoreKeeperPhone = model.StoreKeeperPhone; + } + + public StoreKeeperViewModel GetViewModel => new() + { + Id = Id, + StoreKeeperFIO = StoreKeeperFIO, + StoreKeeperLogin = StoreKeeperLogin, + StoreKeeperEmail = StoreKeeperEmail, + StoreKeeperPassword = StoreKeeperPassword, + StoreKeeperPhone = StoreKeeperPhone, + }; + } +} \ No newline at end of file