diff --git a/BeautySaloon/BeautySaloon.sln b/BeautySaloon/BeautySaloon.sln index a62677b..aa3a7cb 100644 --- a/BeautySaloon/BeautySaloon.sln +++ b/BeautySaloon/BeautySaloon.sln @@ -11,6 +11,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BeautySaloonContracts", "Be EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BeautySaloonBusinessLogic", "BeautySaloonBusinessLogic\BeautySaloonBusinessLogic.csproj", "{E43A1394-BC9A-430B-B984-BCCD828FFF45}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BeautySaloonDatabaseImplement", "BeautySaloonDatabaseImplement\BeautySaloonDatabaseImplement.csproj", "{BB7AD640-FF4A-415B-A09B-BB802D64CE27}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -33,6 +35,10 @@ Global {E43A1394-BC9A-430B-B984-BCCD828FFF45}.Debug|Any CPU.Build.0 = Debug|Any CPU {E43A1394-BC9A-430B-B984-BCCD828FFF45}.Release|Any CPU.ActiveCfg = Release|Any CPU {E43A1394-BC9A-430B-B984-BCCD828FFF45}.Release|Any CPU.Build.0 = Release|Any CPU + {BB7AD640-FF4A-415B-A09B-BB802D64CE27}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {BB7AD640-FF4A-415B-A09B-BB802D64CE27}.Debug|Any CPU.Build.0 = Debug|Any CPU + {BB7AD640-FF4A-415B-A09B-BB802D64CE27}.Release|Any CPU.ActiveCfg = Release|Any CPU + {BB7AD640-FF4A-415B-A09B-BB802D64CE27}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/BeautySaloon/BeautySaloonContracts/SearchModels/OrderSearchModel.cs b/BeautySaloon/BeautySaloonContracts/SearchModels/OrderSearchModel.cs index a1b519c..b9d4838 100644 --- a/BeautySaloon/BeautySaloonContracts/SearchModels/OrderSearchModel.cs +++ b/BeautySaloon/BeautySaloonContracts/SearchModels/OrderSearchModel.cs @@ -4,7 +4,7 @@ { public int? Id { get; set; } public DateTime? Date { get; set; } - public int? Client_Id { get; set; } - public int? Employee_Id { get; set; } + public int? ClientId { get; set; } + public int? EmployeeId { get; set; } } } diff --git a/BeautySaloon/BeautySaloonDatabaseImplement/BeautySaloonDatabase.cs b/BeautySaloon/BeautySaloonDatabaseImplement/BeautySaloonDatabase.cs new file mode 100644 index 0000000..5401ded --- /dev/null +++ b/BeautySaloon/BeautySaloonDatabaseImplement/BeautySaloonDatabase.cs @@ -0,0 +1,29 @@ +using BeautySaloonDatabaseImplement.Models; +using Microsoft.EntityFrameworkCore; + +namespace BeautySaloonDatabaseImplement +{ + public class BeautySaloonDatabase : DbContext + { + protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) + { + if (optionsBuilder.IsConfigured == false) + { + optionsBuilder.UseSqlServer(@"Data Source=DESKTOP-D8KMQQU\SQLEXPRESS;Initial Catalog=SushiBarDatabase;Integrated Security=True;MultipleActiveResultSets=True;;TrustServerCertificate=True"); + } + base.OnConfiguring(optionsBuilder); + } + + public virtual DbSet Employees { set; get; } + + public virtual DbSet Positions { set; get; } + + public virtual DbSet Services { set; get; } + + public virtual DbSet Orders { set; get; } + + public virtual DbSet Clients { set; get; } + + public virtual DbSet OrderServices { set; get; } + } +} diff --git a/BeautySaloon/BeautySaloonDatabaseImplement/BeautySaloonDatabaseImplement.csproj b/BeautySaloon/BeautySaloonDatabaseImplement/BeautySaloonDatabaseImplement.csproj new file mode 100644 index 0000000..8f45690 --- /dev/null +++ b/BeautySaloon/BeautySaloonDatabaseImplement/BeautySaloonDatabaseImplement.csproj @@ -0,0 +1,26 @@ + + + + net6.0 + enable + enable + + + + + + + + + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + + + + + + + diff --git a/BeautySaloon/BeautySaloonDatabaseImplement/Models/Client.cs b/BeautySaloon/BeautySaloonDatabaseImplement/Models/Client.cs new file mode 100644 index 0000000..67047db --- /dev/null +++ b/BeautySaloon/BeautySaloonDatabaseImplement/Models/Client.cs @@ -0,0 +1,52 @@ +using BeautySaloonContracts.BindingModels; +using BeautySaloonContracts.ViewModels; +using BeautySaloonDataModels; +using System.ComponentModel.DataAnnotations; +using System.ComponentModel.DataAnnotations.Schema; +using System.Diagnostics; + +namespace BeautySaloonDatabaseImplement.Models +{ + public class Client : IClientModel + { + public int Id { get; set; } + [Required] + public string Name { get; set; } = string.Empty; + [Required] + public string Surname { get; set; } = string.Empty; + public string Patronymic { get; set; } = string.Empty; + [Required] + public string Phone { get; set; } = string.Empty; + [ForeignKey("ClientId")] + public virtual List Orders { get; set; } = new(); + + public static Client Create(ClientBindingModel model) + { + return new Client() + { + Id = model.Id, + Name = model.Name, + Surname = model.Surname, + Patronymic = model.Patronymic, + Phone = model.Phone + }; + } + + public void Update(ClientBindingModel model) + { + Name = model.Name; + Surname = model.Surname; + Patronymic = model.Patronymic; + Phone = model.Phone; + } + + public ClientViewModel GetViewModel => new() + { + Id = Id, + Name = Name, + Surname = Surname, + Patronymic = Patronymic, + Phone = Phone + }; + } +} diff --git a/BeautySaloon/BeautySaloonDatabaseImplement/Models/Employee.cs b/BeautySaloon/BeautySaloonDatabaseImplement/Models/Employee.cs new file mode 100644 index 0000000..68fc4d4 --- /dev/null +++ b/BeautySaloon/BeautySaloonDatabaseImplement/Models/Employee.cs @@ -0,0 +1,70 @@ +using BeautySaloonContracts.BindingModels; +using BeautySaloonContracts.ViewModels; +using BeautySaloonDataModels; +using System.ComponentModel.DataAnnotations; +using System.ComponentModel.DataAnnotations.Schema; + +namespace BeautySaloonDatabaseImplement.Models +{ + public class Employee : IEmployeeModel + { + public int Id { get; set; } + [Required] + public string Name { get; set; } = string.Empty; + [Required] + public string Surname { get; set; } = string.Empty; + + public string Patronymic { get; set; } = string.Empty; + [Required] + public string Phone { get; set; } = string.Empty; + [Required] + public int PositionId { get; set; } + public Position Position { get; set; } + + [ForeignKey("EmployeeId")] + public virtual List Orders { get; set; } = new(); + [ForeignKey("EmployeeId")] + public virtual List OrderServices { get; set; } = new(); + + public static Employee? Create(EmployeeBindingModel? model) + { + if (model == null) + { + return null; + } + return new Employee() + { + Id = model.Id, + Name = model.Name, + Surname = model.Surname, + Patronymic = model.Patronymic, + Phone = model.Phone, + PositionId = model.PositionId + }; + } + + public void Update(EmployeeBindingModel? model) + { + if (model == null) + { + return; + } + Name = model.Name; + Surname = model.Surname; + Patronymic = model.Patronymic; + Phone = model.Phone; + PositionId = model.PositionId; + } + + public EmployeeViewModel GetViewModel => new() + { + Id = Id, + Name = Name, + Surname = Surname, + Patronymic = Patronymic, + Phone = Phone, + PositionId = PositionId, + PositionName = Position.Name, + }; + } +} diff --git a/BeautySaloon/BeautySaloonDatabaseImplement/Models/Order.cs b/BeautySaloon/BeautySaloonDatabaseImplement/Models/Order.cs new file mode 100644 index 0000000..978573e --- /dev/null +++ b/BeautySaloon/BeautySaloonDatabaseImplement/Models/Order.cs @@ -0,0 +1,38 @@ +using BeautySaloonDataModels; +using System.ComponentModel.DataAnnotations; +using System.ComponentModel.DataAnnotations.Schema; + +namespace BeautySaloonDatabaseImplement.Models +{ + public class Order : IOrderModel + { + public int Id { get; set; } + [Required] + public DateTime Date { get; set; } + [Required] + public double Sum { get; set; } + [Required] + public int ClientId { get; set; } + [Required] + public int EmployeeId { get; set; } + + private Dictionary? _orderServices = null; + [ForeignKey("OrderId")] + public virtual List Services { get; set; } = new(); + + [NotMapped] + public Dictionary OrderServices + { + get + { + /*if (_orderServices == null) + { + _orderServices = Services + .ToDictionary(recPC => recPC.ServiceId, + recPC => (recPC.Service as IServiceModel, recPC.Count)); + }*/ + return _orderServices; + } + } + } +} diff --git a/BeautySaloon/BeautySaloonDatabaseImplement/Models/Position.cs b/BeautySaloon/BeautySaloonDatabaseImplement/Models/Position.cs new file mode 100644 index 0000000..ead7554 --- /dev/null +++ b/BeautySaloon/BeautySaloonDatabaseImplement/Models/Position.cs @@ -0,0 +1,36 @@ +using BeautySaloonContracts.BindingModels; +using BeautySaloonContracts.ViewModels; +using BeautySaloonDataModels; +using System.ComponentModel.DataAnnotations; +using System.ComponentModel.DataAnnotations.Schema; + +namespace BeautySaloonDatabaseImplement.Models +{ + public class Position : IPositionModel + { + public int Id { get; set; } + [Required] + public string Name { get; set; } = string.Empty; + [ForeignKey("PositionId")] + public virtual List Employees { get; set; } = new(); + + public static Position Create(PositionBindingModel model) + { + return new Position() + { + Id = model.Id, + Name = model.Name + }; + } + public void Update(PositionBindingModel model) + { + Name = model.Name; + } + + public PositionViewModel GetViewModel => new() + { + Id = Id, + Name = Name + }; + } +} diff --git a/BeautySaloon/BeautySaloonDatabaseImplement/Models/Service.cs b/BeautySaloon/BeautySaloonDatabaseImplement/Models/Service.cs new file mode 100644 index 0000000..8b607d8 --- /dev/null +++ b/BeautySaloon/BeautySaloonDatabaseImplement/Models/Service.cs @@ -0,0 +1,41 @@ +using BeautySaloonContracts.BindingModels; +using BeautySaloonDataModels; +using System.ComponentModel.DataAnnotations.Schema; +using System.ComponentModel.DataAnnotations; +using BeautySaloonContracts.ViewModels; + +namespace BeautySaloonDatabaseImplement.Models +{ + public class Service : IServiceModel + { + public int Id { get; set; } + [Required] + public string Name { get; set; } = string.Empty; + [Required] + public double Price { get; set; } + [ForeignKey("ServiceId")] + public virtual List OrderServices { get; set; } = new(); + + public static Service Create(ServiceBindingModel model) + { + return new Service() + { + Id = model.Id, + Name = model.Name, + Price = model.Price + }; + } + public void Update(ServiceBindingModel model) + { + Name = model.Name; + Price = model.Price; + } + + public ServiceViewModel GetViewModel => new() + { + Id = Id, + Name = Name, + Price = Price + }; + } +} diff --git a/BeautySaloon/BeautySaloonDatabaseImplement/Models/ServiceOrder.cs b/BeautySaloon/BeautySaloonDatabaseImplement/Models/ServiceOrder.cs new file mode 100644 index 0000000..87ecdfd --- /dev/null +++ b/BeautySaloon/BeautySaloonDatabaseImplement/Models/ServiceOrder.cs @@ -0,0 +1,24 @@ +using System.ComponentModel.DataAnnotations; + +namespace BeautySaloonDatabaseImplement.Models +{ + public class ServiceOrder + { + [Required] + public int ServiceId { get; set; } + + [Required] + public int OrderId { get; set; } + [Required] + public int EmployeeId { get; set; } + + [Required] + public DateTime Date { get; set; } + + public virtual Service Service { get; set; } = new(); + + public virtual Order Order { get; set; } = new(); + + public virtual Employee Employee { get; set; } = new(); + } +}