diff --git a/.gitignore b/.gitignore index ca1c7a3..2934365 100644 --- a/.gitignore +++ b/.gitignore @@ -398,3 +398,4 @@ FodyWeavers.xsd # JetBrains Rider *.sln.iml +/BeautySalonView/BeautySalonContracts/SearchModels/EvaluationSearchModel.cs diff --git a/BeautySalonView/BeatySalonRestApi/Controllers/ProcedureController.cs b/BeautySalonView/BeatySalonRestApi/Controllers/ProcedureController.cs index 6e4420c..f90835a 100644 --- a/BeautySalonView/BeatySalonRestApi/Controllers/ProcedureController.cs +++ b/BeautySalonView/BeatySalonRestApi/Controllers/ProcedureController.cs @@ -67,7 +67,7 @@ namespace BeutySalonClientApp.Controllers { try { - return procedure.ReadList(new ProcedureSearchModel { ClientId = userId, PageNumber = page, PageSize = 10 }); + return procedure.ReadList(new ProcedureSearchModel { ClientId = userId}); } catch (Exception ex) { diff --git a/BeautySalonView/BeautySalonContracts/SearchModels/EvaluationSearchModel.cs b/BeautySalonView/BeautySalonContracts/SearchModels/EvaluationSearchModel.cs index 5ec647c..5b5418e 100644 --- a/BeautySalonView/BeautySalonContracts/SearchModels/EvaluationSearchModel.cs +++ b/BeautySalonView/BeautySalonContracts/SearchModels/EvaluationSearchModel.cs @@ -3,7 +3,10 @@ public class EvaluationSearchModel { public int? Id { get; set; } + public double? PointsProcedure { get; set; } + public double? PointsCosmetics { get; set; } public int? ClientId { get; set; } - public int? ProcedureId { get; set; } + public int? PageNumber { get; set; } + public int? PageSize { get; set; } } } diff --git a/BeautySalonView/BeautySalonContracts/ViewModels/OrderCosmeticViewModel.cs b/BeautySalonView/BeautySalonContracts/ViewModels/OrderCosmeticViewModel.cs index 9053e9e..8e045ba 100644 --- a/BeautySalonView/BeautySalonContracts/ViewModels/OrderCosmeticViewModel.cs +++ b/BeautySalonView/BeautySalonContracts/ViewModels/OrderCosmeticViewModel.cs @@ -2,14 +2,12 @@ { public class OrderCosmeticViewModel { - public int OrderId { get; set; } public CosmeticViewModel Cosmetic { get; set; } = null!; public OrderCosmeticViewModel() { } - public OrderCosmeticViewModel(int orderId, CosmeticViewModel cosmetic) + public OrderCosmeticViewModel(CosmeticViewModel cosmetic) { - OrderId = orderId; Cosmetic = cosmetic; } } diff --git a/BeautySalonView/BeautySalonContracts/ViewModels/OrderProcedureViewModel.cs b/BeautySalonView/BeautySalonContracts/ViewModels/OrderProcedureViewModel.cs index cc8defc..d8e8b9b 100644 --- a/BeautySalonView/BeautySalonContracts/ViewModels/OrderProcedureViewModel.cs +++ b/BeautySalonView/BeautySalonContracts/ViewModels/OrderProcedureViewModel.cs @@ -2,15 +2,13 @@ { public class OrderProcedureViewModel { - public int OrderId { get; set; } public ProcedureViewModel Procedure { get; set; } = null!; public int Count { get; set; } public OrderProcedureViewModel() { } - public OrderProcedureViewModel(int orderId, ProcedureViewModel procedure, int count) + public OrderProcedureViewModel(ProcedureViewModel procedure, int count) { - OrderId = orderId; Procedure = procedure; Count = count; } diff --git a/BeautySalonView/BeautySalonContracts/ViewModels/OrderServiceViewModel.cs b/BeautySalonView/BeautySalonContracts/ViewModels/OrderServiceViewModel.cs index 24cd40c..c5ca135 100644 --- a/BeautySalonView/BeautySalonContracts/ViewModels/OrderServiceViewModel.cs +++ b/BeautySalonView/BeautySalonContracts/ViewModels/OrderServiceViewModel.cs @@ -2,15 +2,13 @@ { public class OrderServiceViewModel { - public int OrderId { get; set; } public ServiceViewModel Service { get; set; } = null!; public int Count { get; set; } public OrderServiceViewModel() { } - public OrderServiceViewModel(int orderId, ServiceViewModel service, int count) + public OrderServiceViewModel(ServiceViewModel service, int count) { - OrderId = orderId; Service = service; Count = count; } diff --git a/BeautySalonView/BeautySalonContracts/ViewModels/ProcedureEvaluationViewModel.cs b/BeautySalonView/BeautySalonContracts/ViewModels/ProcedureEvaluationViewModel.cs deleted file mode 100644 index 990be09..0000000 --- a/BeautySalonView/BeautySalonContracts/ViewModels/ProcedureEvaluationViewModel.cs +++ /dev/null @@ -1,18 +0,0 @@ -namespace BeautySalonContracts.ViewModels -{ - public class ProcedureEvaluationViewModel - { - public int OrderId { get; set; } - public EvaluationViewModel Evaluation { get; set; } = null!; - public int Count { get; set; } - - public ProcedureEvaluationViewModel() { } - - public ProcedureEvaluationViewModel(int orderId, EvaluationViewModel evaluation, int count) - { - OrderId = orderId; - Evaluation = evaluation; - Count = count; - } - } -} diff --git a/BeautySalonView/BeautySalonContracts/ViewModels/ServiceCosmeticViewModel.cs b/BeautySalonView/BeautySalonContracts/ViewModels/ServiceCosmeticViewModel.cs index e7c202a..8d42d78 100644 --- a/BeautySalonView/BeautySalonContracts/ViewModels/ServiceCosmeticViewModel.cs +++ b/BeautySalonView/BeautySalonContracts/ViewModels/ServiceCosmeticViewModel.cs @@ -2,15 +2,15 @@ { public class ServiceCosmeticViewModel { - public int CosmeticId { get; set; } + public CosmeticViewModel Cosmetic { get; set; } = null!; public ServiceViewModel Service { get; set; } = null!; public int Count { get; set; } public ServiceCosmeticViewModel() { } - public ServiceCosmeticViewModel(int cosmeticId, ServiceViewModel service, int count) + public ServiceCosmeticViewModel(CosmeticViewModel cosmetic, ServiceViewModel service, int count) { - CosmeticId = cosmeticId; + Cosmetic = cosmetic; Service = service; Count = count; } diff --git a/BeautySalonView/BeautySalonContracts/ViewModels/ServiceProceduresViewModel.cs b/BeautySalonView/BeautySalonContracts/ViewModels/ServiceProceduresViewModel.cs index 55c2cd8..18dfea2 100644 --- a/BeautySalonView/BeautySalonContracts/ViewModels/ServiceProceduresViewModel.cs +++ b/BeautySalonView/BeautySalonContracts/ViewModels/ServiceProceduresViewModel.cs @@ -8,15 +8,13 @@ namespace BeautySalonContracts.ViewModels { public class ServiceProcedureViewModel { - public int ServiceId { get; set; } public ProcedureViewModel Procedure { get; set; } = null!; public int Count { get; set; } public ServiceProcedureViewModel() { } - public ServiceProcedureViewModel(int serviceId, ProcedureViewModel procedure, int count) + public ServiceProcedureViewModel(ProcedureViewModel procedure, int count) { - ServiceId = serviceId; Procedure = procedure; Count = count; } diff --git a/BeautySalonView/BeautySalonDatabaseImplement/BeautySalonDatabase.cs b/BeautySalonView/BeautySalonDatabaseImplement/BeautySalonDatabase.cs index 21478fa..8935b6f 100644 --- a/BeautySalonView/BeautySalonDatabaseImplement/BeautySalonDatabase.cs +++ b/BeautySalonView/BeautySalonDatabaseImplement/BeautySalonDatabase.cs @@ -31,6 +31,7 @@ namespace BeautySalonDatabaseImplement public virtual DbSet Evaluations { set; get; } public virtual DbSet Procedures { set; get; } public virtual DbSet ServiceCosmetics { set; get; } + public virtual DbSet ServiceProcedures { set; get; } public virtual DbSet StaffMembers { set; get; } public virtual DbSet Clients { set; get; } public virtual DbSet OrderCosmetics { set; get; } diff --git a/BeautySalonView/BeautySalonDatabaseImplement/Implements/CosmeticStorage.cs b/BeautySalonView/BeautySalonDatabaseImplement/Implements/CosmeticStorage.cs index 73267f1..61c95db 100644 --- a/BeautySalonView/BeautySalonDatabaseImplement/Implements/CosmeticStorage.cs +++ b/BeautySalonView/BeautySalonDatabaseImplement/Implements/CosmeticStorage.cs @@ -3,6 +3,7 @@ using BeautySalonContracts.SearchModels; using BeautySalonContracts.StoragesContracts; using BeautySalonContracts.ViewModels; using BeautySalonDatabaseImplement.Models; +using Microsoft.EntityFrameworkCore; using System.Collections.Generic; using System.ComponentModel; using System.Linq; @@ -15,10 +16,11 @@ namespace BeautySalonDatabaseImplement.Implements { using var context = new BeautySalonDatabase(); return context.Cosmetics + //.Include(x => x.Procedures) + //.ThenInclude(x => x.Procedure) .Select(x => x.GetViewModel) .ToList(); } - public List GetFilteredList(CosmeticSearchModel model) { using var context = new BeautySalonDatabase(); diff --git a/BeautySalonView/BeautySalonDatabaseImplement/Implements/EvaluationStorage.cs b/BeautySalonView/BeautySalonDatabaseImplement/Implements/EvaluationStorage.cs index 75ccc32..053f141 100644 --- a/BeautySalonView/BeautySalonDatabaseImplement/Implements/EvaluationStorage.cs +++ b/BeautySalonView/BeautySalonDatabaseImplement/Implements/EvaluationStorage.cs @@ -30,7 +30,7 @@ namespace BeautySalonDatabaseImplement.Implements if (model.Id.HasValue) { return context.Evaluations - .Include(x => x.Procedure) + .Include(x => x.Procedure) .Where(x => x.Id == model.Id) .Select(x => x.GetViewModel) .ToList(); @@ -61,17 +61,17 @@ namespace BeautySalonDatabaseImplement.Implements public EvaluationViewModel? Insert(EvaluationBindingModel model) { - var newRating = Evaluation.Create(model); - if (newRating == null) + var newEvaluation = Evaluation.Create(model); + if (newEvaluation == null) { return null; } using var context = new BeautySalonDatabase(); - context.Evaluations.Add(newRating); + context.Evaluations.Add(newEvaluation); context.SaveChanges(); return context.Evaluations .Include(x => x.Procedure) - .FirstOrDefault(x => x.Id == newRating.Id) + .FirstOrDefault(x => x.Id == newEvaluation.Id) ?.GetViewModel; } diff --git a/BeautySalonView/BeautySalonDatabaseImplement/Implements/LaborCostsStorage.cs b/BeautySalonView/BeautySalonDatabaseImplement/Implements/LaborCostsStorage.cs index 44c3804..f5e1dc1 100644 --- a/BeautySalonView/BeautySalonDatabaseImplement/Implements/LaborCostsStorage.cs +++ b/BeautySalonView/BeautySalonDatabaseImplement/Implements/LaborCostsStorage.cs @@ -49,6 +49,13 @@ namespace BeautySalonDatabaseImplement.Implements .Select(x => x.GetViewModel) .ToList(); } + if (model.StaffMemberId.HasValue) + { + return context.LaborCosts + .Where(x => x.StaffMemberId == model.StaffMemberId) + .Select(x => x.GetViewModel) + .ToList(); + } return new(); } diff --git a/BeautySalonView/BeautySalonDatabaseImplement/Implements/ProcedureStorage.cs b/BeautySalonView/BeautySalonDatabaseImplement/Implements/ProcedureStorage.cs index fbef22d..5aeef85 100644 --- a/BeautySalonView/BeautySalonDatabaseImplement/Implements/ProcedureStorage.cs +++ b/BeautySalonView/BeautySalonDatabaseImplement/Implements/ProcedureStorage.cs @@ -19,7 +19,6 @@ namespace BeautySalonDatabaseImplement.Implements 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) { @@ -62,13 +61,6 @@ namespace BeautySalonDatabaseImplement.Implements .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(); } @@ -118,5 +110,19 @@ namespace BeautySalonDatabaseImplement.Implements throw; } } + + public List GetProcedureCosmetics(ProcedureSearchModel model) + { + if (model == null) + { + return new(); + } + using var context = new BeautySalonDatabase(); + var cosmetics = context.CosmeticProcedures + .Where(x => x.ProcedureId == model.Id) + .Select(x => x.Cosmetic.GetViewModel) + .ToList(); + return cosmetics; + } } } diff --git a/BeautySalonView/BeautySalonDatabaseImplement/Implements/ServiceStorage.cs b/BeautySalonView/BeautySalonDatabaseImplement/Implements/ServiceStorage.cs index cd684eb..cf7dffb 100644 --- a/BeautySalonView/BeautySalonDatabaseImplement/Implements/ServiceStorage.cs +++ b/BeautySalonView/BeautySalonDatabaseImplement/Implements/ServiceStorage.cs @@ -18,8 +18,8 @@ namespace BeautySalonDatabaseImplement.Implements { using var context = new BeautySalonDatabase(); var element = context.Services + .Include(x => x.Procedures) .Include(x => x.Cosmetics) - .Include(x => x.Orders) .FirstOrDefault(rec => rec.Id == model.Id); if (element != null) { @@ -38,6 +38,8 @@ namespace BeautySalonDatabaseImplement.Implements } using var context = new BeautySalonDatabase(); return context.Services + .Include(x => x.Procedures) + .ThenInclude(x => x.Procedure) .Include(x => x.Cosmetics) .ThenInclude(x => x.Cosmetic) .FirstOrDefault(x => (!string.IsNullOrEmpty(model.ServiceName) && x.ServiceName == model.ServiceName) || @@ -55,6 +57,8 @@ namespace BeautySalonDatabaseImplement.Implements if (model.Id.HasValue) { return context.Services + .Include(x => x.Procedures) + .ThenInclude(x => x.Procedure) .Include(x => x.Cosmetics) .ThenInclude(x => x.Cosmetic) .Where(x => x.Id == model.Id) @@ -62,6 +66,18 @@ namespace BeautySalonDatabaseImplement.Implements .Select(x => x.GetViewModel) .ToList(); } + if (model.StaffMemberId.HasValue) + { + return context.Services + .Include(x => x.Procedures) + .ThenInclude(x => x.Procedure) + .Include(x => x.Cosmetics) + .ThenInclude(x => x.Cosmetic) + .Where(x => x.StaffMemberId == model.StaffMemberId) + .ToList() + .Select(x => x.GetViewModel) + .ToList(); + } return new(); } @@ -69,6 +85,8 @@ namespace BeautySalonDatabaseImplement.Implements { using var context = new BeautySalonDatabase(); return context.Services + .Include(x => x.Procedures) + .ThenInclude(x => x.Procedure) .Include(x => x.Cosmetics) .ThenInclude(x => x.Cosmetic) .Select(x => x.GetViewModel) @@ -102,6 +120,7 @@ namespace BeautySalonDatabaseImplement.Implements service.Update(model); context.SaveChanges(); service.UpdateCosmetics(context, model); + service.UpdateProcedures(context, model); transaction.Commit(); return service.GetViewModel; } diff --git a/BeautySalonView/BeautySalonDatabaseImplement/Models/Client.cs b/BeautySalonView/BeautySalonDatabaseImplement/Models/Client.cs index fb483a2..5ec6f52 100644 --- a/BeautySalonView/BeautySalonDatabaseImplement/Models/Client.cs +++ b/BeautySalonView/BeautySalonDatabaseImplement/Models/Client.cs @@ -17,7 +17,8 @@ namespace BeautySalonDatabaseImplement.Models public string ClientFIO { get; set; } = string.Empty; [Required] public string ClientEmail { get; set; } = string.Empty; - + [Required] + public string ClientPhone { get; set; } = string.Empty; [Required] public string ClientPhone { get; set; } = string.Empty; diff --git a/BeautySalonView/BeautySalonDatabaseImplement/Models/Cosmetic.cs b/BeautySalonView/BeautySalonDatabaseImplement/Models/Cosmetic.cs index a8afa24..76efdc1 100644 --- a/BeautySalonView/BeautySalonDatabaseImplement/Models/Cosmetic.cs +++ b/BeautySalonView/BeautySalonDatabaseImplement/Models/Cosmetic.cs @@ -23,8 +23,9 @@ namespace BeautySalonDatabaseImplement.Models [Required] public double CosmeticPrice { get; set; } + [Required] public int LaborCostId { get; set; } - public virtual LaborCosts LaborCost { get; set; } + public virtual LaborCosts LaborCost { get; set; } = new(); [ForeignKey("CosmeticId")] public virtual List Orders { get; set; } = new(); diff --git a/BeautySalonView/BeautySalonDatabaseImplement/Models/Order_.cs b/BeautySalonView/BeautySalonDatabaseImplement/Models/Order_.cs index df37af5..92cb7b5 100644 --- a/BeautySalonView/BeautySalonDatabaseImplement/Models/Order_.cs +++ b/BeautySalonView/BeautySalonDatabaseImplement/Models/Order_.cs @@ -84,17 +84,17 @@ namespace BeautySalonDatabaseImplement.Models Id = model.Id, OrderDate = model.OrderDate, OrderAmount = model.OrderAmount, - Services = model.OrderServices.Select(x => new OrderService() + Services = model.OrderService.Select(x => new OrderService() { Service = context.Services.First(y => y.Id == x.Service.Id), OrderServiceCount = x.Count }).ToList(), - Procedures = model.OrderProcedures.Select(x => new OrderProcedure() + Procedures = model.OrderProcedure.Select(x => new OrderProcedure() { Procedure = context.Procedures.First(y => y.Id == x.Procedure.Id), OrderProcedureCount = x.Count }).ToList(), - Cosmetics= model.OrderCosmetics.Select(x => new OrderCosmetic() + Cosmetics= model.OrderCosmetic.Select(x => new OrderCosmetic() { Cosmetic = context.Cosmetics.First(y => y.Id == x.Cosmetic.Id), }).ToList(), @@ -127,7 +127,7 @@ namespace BeautySalonDatabaseImplement.Models context.OrderServices .RemoveRange(orderServices); var order = context.Orders.First(x => x.Id == Id); - foreach (var record in model.OrderServices) + foreach (var record in model.OrderService) { context.OrderServices.Add(new OrderService { @@ -148,7 +148,7 @@ namespace BeautySalonDatabaseImplement.Models context.OrderProcedures .RemoveRange(orderProcedures); var order = context.Orders.First(x => x.Id == Id); - foreach (var record in model.OrderProcedures) + foreach (var record in model.OrderProcedure) { context.OrderProcedures.Add(new OrderProcedure { @@ -169,7 +169,7 @@ namespace BeautySalonDatabaseImplement.Models context.OrderCosmetics .RemoveRange(orderCosmetic); var order = context.Orders.First(x => x.Id == Id); - foreach (var record in model.OrderCosmetics) + foreach (var record in model.OrderCosmetic) { context.OrderCosmetics.Add(new OrderCosmetic { diff --git a/BeautySalonView/BeautySalonDatabaseImplement/Models/Procedure.cs b/BeautySalonView/BeautySalonDatabaseImplement/Models/Procedure.cs index 494bcbf..2157f5a 100644 --- a/BeautySalonView/BeautySalonDatabaseImplement/Models/Procedure.cs +++ b/BeautySalonView/BeautySalonDatabaseImplement/Models/Procedure.cs @@ -25,26 +25,11 @@ namespace BeautySalonDatabaseImplement.Models public double ProcedureDuration { get; set; } public int ClientId { get; set; } - public virtual Client Client { get; set; } = null!; - private List? _cosmeticProcedures = null; - - [NotMapped] - public List CosmeticProcedures - { - get - { - _cosmeticProcedures ??= Cosmetics - .Select(pc => new CosmeticProcedureViewModel(pc.Cosmetic.GetViewModel, pc.ProcedureCosmeticCount)) - .ToList(); - return _cosmeticProcedures; - } - } // связь процедуры и оценок один - ко - многим [ForeignKey("ProcedureId")] public virtual List Evaluations { get; set; } = new(); - private List? _procedureEvaluations = null; [NotMapped] public List ProcedureEvaluations @@ -62,10 +47,28 @@ namespace BeautySalonDatabaseImplement.Models [ForeignKey("ProcedureId")] public virtual List Cosmetics { get; set; } = new(); + private List? _cosmeticProcedures = null; + + [NotMapped] + public List CosmeticProcedures + { + get + { + _cosmeticProcedures ??= Cosmetics + .Select(pc => new CosmeticProcedureViewModel(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(); + public static Procedure Create(BeautySalonDatabase context, ProcedureBindingModel model) { @@ -74,6 +77,7 @@ namespace BeautySalonDatabaseImplement.Models Id = model.Id, ProcedureName = model.ProcedureName, ProcedurePrice = model.ProcedurePrice, + ProcedureDuration = model.ProcedureDuration, Cosmetics = model.ProcedureCosmetics.Select(x => new CosmeticProcedure() { Cosmetic = context.Cosmetics.First(y => y.Id == x.Cosmetic.Id), @@ -87,6 +91,7 @@ namespace BeautySalonDatabaseImplement.Models { ProcedureName = model.ProcedureName; ProcedurePrice = model.ProcedurePrice; + ProcedureDuration = model.ProcedureDuration; } public ProcedureViewModel GetViewModel => new() @@ -94,8 +99,8 @@ namespace BeautySalonDatabaseImplement.Models Id = Id, ProcedureName = ProcedureName, ProcedurePrice = ProcedurePrice, + ProcedureDuration = ProcedureDuration, CosmeticProcedures = CosmeticProcedures, - ProcedureEvaluations = ProcedureEvaluations, ClientId = ClientId }; diff --git a/BeautySalonView/BeautySalonDatabaseImplement/Models/Service.cs b/BeautySalonView/BeautySalonDatabaseImplement/Models/Service.cs index ced60e9..5131dac 100644 --- a/BeautySalonView/BeautySalonDatabaseImplement/Models/Service.cs +++ b/BeautySalonView/BeautySalonDatabaseImplement/Models/Service.cs @@ -27,31 +27,44 @@ namespace BeautySalonDatabaseImplement.Models public int StaffMemberId { get; set; } public virtual StaffMember StaffMember { get; set; } + // связь услуги и заказов многие - ко - многим + [ForeignKey("ServiceId")] + public virtual List Orders { get; set; } = new(); + + // связь услуги и косметки многие - ко - многим + [ForeignKey("ServiceId")] + public virtual List Cosmetics { get; set; } = new(); + + // связь услуги и косметки многие - ко - многим + [ForeignKey("ServiceId")] + public virtual List Procedures { get; set; } = new(); + + private List? _serviceProcedures = null; + [NotMapped] + public List ServiceProcedures + { + get + { + _serviceProcedures ??= Procedures + .Select(pc => new ServiceProcedureViewModel(pc.Procedure.GetViewModel, pc.ServiceProcedureCount)) + .ToList(); + return _serviceProcedures; + } + } private List? _serviceCosmetics = null; - - private List? _serviceProcedure = null; - [NotMapped] public List ServiceCosmetics { get { _serviceCosmetics ??= Cosmetics - .Select(pc => new ServiceCosmeticViewModel(pc.Cosmetic.GetViewModel, pc.ServiceCosmeticCount)) + .Select(pc => new ServiceCosmeticViewModel(pc.Cosmetic.GetViewModel, pc.Service.GetViewModel, pc.ServiceCosmeticCount)) .ToList(); return _serviceCosmetics; } } - // связь услуги и косметки многие - ко - многим - [ForeignKey("ServiceId")] - public virtual List Cosmetics { get; set; } = new(); - - // связь услуги и заказов многие - ко - многим - [ForeignKey("ServiceId")] - public virtual List Orders { get; set; } = new(); - public static Service Create(BeautySalonDatabase context, ServiceBindingModel model) { return new Service() @@ -64,6 +77,11 @@ namespace BeautySalonDatabaseImplement.Models Cosmetic = context.Cosmetics.First(y => y.Id == x.Cosmetic.Id), ServiceCosmeticCount = x.Count }).ToList(), + Procedures = model.ServiceProcedure.Select(x => new ServiceProcedure() + { + Procedure = context.Procedures.First(y => y.Id == x.Procedure.Id), + ServiceProcedureCount = x.Count + }).ToList(), StaffMemberId = model.StaffMemberId }; } @@ -81,16 +99,17 @@ namespace BeautySalonDatabaseImplement.Models ServiceName = ServiceName, ServicePrice = ServicePrice, ServiceCosmetic = ServiceCosmetics, + ServiceProcedure = ServiceProcedures, StaffMemberId = StaffMemberId, }; public void UpdateCosmetics(BeautySalonDatabase context, ServiceBindingModel model) { - var serviceSosmetics = context.ServiceCosmetics + var serviceCosmetics = context.ServiceCosmetics .Where(x => x.ServiceId == model.Id) .ToList(); context.ServiceCosmetics - .RemoveRange(serviceSosmetics); + .RemoveRange(serviceCosmetics); var service = context.Services.First(x => x.Id == Id); foreach (var record in model.ServiceCosmetic) { @@ -104,5 +123,26 @@ namespace BeautySalonDatabaseImplement.Models } _serviceCosmetics = null; } + + public void UpdateProcedures(BeautySalonDatabase context, ServiceBindingModel model) + { + var serviceProcedures = context.ServiceProcedures + .Where(x => x.ServiceId == model.Id) + .ToList(); + context.ServiceProcedures + .RemoveRange(serviceProcedures); + var service = context.Services.First(x => x.Id == Id); + foreach (var record in model.ServiceProcedure) + { + context.ServiceProcedures.Add(new ServiceProcedure + { + Service = service, + Procedure = context.Procedures.First(x => x.Id == record.Procedure.Id), + ServiceProcedureCount = record.Count + }); + context.SaveChanges(); + } + _serviceProcedures = null; + } } } diff --git a/BeautySalonView/BeautySalonDatabaseImplement/Models/StaffMember.cs b/BeautySalonView/BeautySalonDatabaseImplement/Models/StaffMember.cs index 26a1d73..d0d0352 100644 --- a/BeautySalonView/BeautySalonDatabaseImplement/Models/StaffMember.cs +++ b/BeautySalonView/BeautySalonDatabaseImplement/Models/StaffMember.cs @@ -11,10 +11,7 @@ namespace BeautySalonDatabaseImplement.Models public int Id { get; set; } [Required] - public string StaffMemberName { get; set; } = string.Empty; - - [Required] - public string StaffMemberSurname { get; set; } = string.Empty; + public string StaffMemberFIO { get; set; } = string.Empty; [Required] public string StaffMemberSpecialty { get; set; } = string.Empty; @@ -47,8 +44,7 @@ namespace BeautySalonDatabaseImplement.Models return new StaffMember() { Id = model.Id, - StaffMemberName = model.StaffMemberName, - StaffMemberSurname = model.StaffMemberSurname, + StaffMemberFIO = model.StaffMemberFIO, StaffMemberSpecialty = model.StaffMemberSpecialty, StaffMemberLogin = model.StaffMemberLogin, StaffMemberEmail = model.StaffMemberEmail, @@ -63,8 +59,7 @@ namespace BeautySalonDatabaseImplement.Models { return; } - StaffMemberName = model.StaffMemberName; - StaffMemberSurname = model.StaffMemberSurname; + StaffMemberFIO = model.StaffMemberFIO; StaffMemberSpecialty = model.StaffMemberSpecialty; StaffMemberLogin = model.StaffMemberLogin; StaffMemberEmail = model.StaffMemberEmail; @@ -75,8 +70,7 @@ namespace BeautySalonDatabaseImplement.Models public StaffMemberViewModel GetViewModel => new() { Id = Id, - StaffMemberName = StaffMemberName, - StaffMemberSurname = StaffMemberSurname, + StaffMemberFIO = StaffMemberFIO, StaffMemberSpecialty = StaffMemberSpecialty, StaffMemberLogin = StaffMemberLogin, StaffMemberEmail = StaffMemberEmail,