diff --git a/CarCenter/CarCenter.sln b/CarCenter/CarCenter.sln index 16c9682..b486687 100644 --- a/CarCenter/CarCenter.sln +++ b/CarCenter/CarCenter.sln @@ -3,9 +3,13 @@ Microsoft Visual Studio Solution File, Format Version 12.00 # Visual Studio Version 17 VisualStudioVersion = 17.3.32929.385 MinimumVisualStudioVersion = 10.0.40219.1 -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CarCenterContracts", "CarCenterContracts\CarCenterContracts.csproj", "{AB1C6688-AF33-416D-9D4A-D8EDF252678B}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CarCenterContracts", "CarCenterContracts\CarCenterContracts.csproj", "{AB1C6688-AF33-416D-9D4A-D8EDF252678B}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CarCenterDataModels", "CarCenterDataModels\CarCenterDataModels.csproj", "{C924311C-ABF3-44A1-A006-8197A11FB29A}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CarCenterDataModels", "CarCenterDataModels\CarCenterDataModels.csproj", "{C924311C-ABF3-44A1-A006-8197A11FB29A}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CarCenterDatabaseImplement", "CarCenterDatabaseImplement\CarCenterDatabaseImplement.csproj", "{84503674-1555-4ED9-89C4-385C76F6B89C}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CarCenterView", "CarCenterView\CarCenterView.csproj", "{A9F57191-CEAF-4164-87A5-73C2C9245D75}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -21,6 +25,14 @@ Global {C924311C-ABF3-44A1-A006-8197A11FB29A}.Debug|Any CPU.Build.0 = Debug|Any CPU {C924311C-ABF3-44A1-A006-8197A11FB29A}.Release|Any CPU.ActiveCfg = Release|Any CPU {C924311C-ABF3-44A1-A006-8197A11FB29A}.Release|Any CPU.Build.0 = Release|Any CPU + {84503674-1555-4ED9-89C4-385C76F6B89C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {84503674-1555-4ED9-89C4-385C76F6B89C}.Debug|Any CPU.Build.0 = Debug|Any CPU + {84503674-1555-4ED9-89C4-385C76F6B89C}.Release|Any CPU.ActiveCfg = Release|Any CPU + {84503674-1555-4ED9-89C4-385C76F6B89C}.Release|Any CPU.Build.0 = Release|Any CPU + {A9F57191-CEAF-4164-87A5-73C2C9245D75}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {A9F57191-CEAF-4164-87A5-73C2C9245D75}.Debug|Any CPU.Build.0 = Debug|Any CPU + {A9F57191-CEAF-4164-87A5-73C2C9245D75}.Release|Any CPU.ActiveCfg = Release|Any CPU + {A9F57191-CEAF-4164-87A5-73C2C9245D75}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/CarCenter/CarCenterContracts/BindingModels/CarBindingModel.cs b/CarCenter/CarCenterContracts/BindingModels/CarBindingModel.cs index 0d4eaea..8e886e0 100644 --- a/CarCenter/CarCenterContracts/BindingModels/CarBindingModel.cs +++ b/CarCenter/CarCenterContracts/BindingModels/CarBindingModel.cs @@ -12,9 +12,9 @@ namespace CarCenterContracts.BindingModels public String Name { get; set; } public int Id { get; set; } - public Dictionary CarPresales { get; set; } = new(); + public Dictionary PresaleCars { get; set; } = new(); - public Dictionary CarConfigurations { get; set; } = new(); + public Dictionary ConfigurationCars { get; set; } = new(); public int EmployeeId { get; set; } } diff --git a/CarCenter/CarCenterContracts/BindingModels/PresaleBindingModel.cs b/CarCenter/CarCenterContracts/BindingModels/PresaleBindingModel.cs index ad773b9..847f236 100644 --- a/CarCenter/CarCenterContracts/BindingModels/PresaleBindingModel.cs +++ b/CarCenter/CarCenterContracts/BindingModels/PresaleBindingModel.cs @@ -13,6 +13,8 @@ namespace CarCenterContracts.BindingModels public DateTime PresaleDate { get; set; } = DateTime.Now; + public int? TypeOfJobId { get; set; } + public int Id { get; set; } } } diff --git a/CarCenter/CarCenterContracts/SearchModels/ReceiptSearchModel.cs b/CarCenter/CarCenterContracts/SearchModels/ReceiptSearchModel.cs index c9f1215..c5af799 100644 --- a/CarCenter/CarCenterContracts/SearchModels/ReceiptSearchModel.cs +++ b/CarCenter/CarCenterContracts/SearchModels/ReceiptSearchModel.cs @@ -10,5 +10,7 @@ namespace CarCenterContracts.SearchModels { public int? Id { get; set; } public int? BossId { get; set; } + public DateTime? DateFrom { get; set; } + public DateTime? DateTo { get; set; } } } diff --git a/CarCenter/CarCenterContracts/SearchModels/SaleSearchModel.cs b/CarCenter/CarCenterContracts/SearchModels/SaleSearchModel.cs index 2a5f36b..f3983be 100644 --- a/CarCenter/CarCenterContracts/SearchModels/SaleSearchModel.cs +++ b/CarCenter/CarCenterContracts/SearchModels/SaleSearchModel.cs @@ -10,5 +10,7 @@ namespace CarCenterContracts.SearchModels { public int? Id { get; set; } public int? EmployeeId { get; set; } + public DateTime? DateFrom { get; set; } + public DateTime? DateTo { get; set; } } } diff --git a/CarCenter/CarCenterContracts/ViewModels/CarViewModel.cs b/CarCenter/CarCenterContracts/ViewModels/CarViewModel.cs index 0ea2a8e..d9827f8 100644 --- a/CarCenter/CarCenterContracts/ViewModels/CarViewModel.cs +++ b/CarCenter/CarCenterContracts/ViewModels/CarViewModel.cs @@ -15,8 +15,8 @@ namespace CarCenterContracts.ViewModels [DisplayName("Название машины")] public String Name { get; set; } - public Dictionary CarPresales { get; set; } = new(); - public Dictionary CarConfigurations { get; set; } = new(); + public Dictionary PresaleCars { get; set; } = new(); + public Dictionary ConfigurationCars { get; set; } = new(); public int EmployeeId { get; set; } [DisplayName("ФИО работника")] public string EmployeeName { get; set; } = string.Empty; diff --git a/CarCenter/CarCenterContracts/ViewModels/PresaleViewModel.cs b/CarCenter/CarCenterContracts/ViewModels/PresaleViewModel.cs index 128b2e4..09e962c 100644 --- a/CarCenter/CarCenterContracts/ViewModels/PresaleViewModel.cs +++ b/CarCenter/CarCenterContracts/ViewModels/PresaleViewModel.cs @@ -17,6 +17,9 @@ namespace CarCenterContracts.ViewModels [DisplayName("Номер работника")] public int EmployeeId { get; set; } [DisplayName("ФИО работника")] + public int? TypeOfJobId { get; set; } + [DisplayName("Название кредитной программы")] + public string? TypeOfJobName { get; set; } = string.Empty; public string EmployeeName { get; set; } = string.Empty; [DisplayName("Номер предпродажи")] public int Id {get;set;} diff --git a/CarCenter/CarCenterDataModels/CarCenterDataModels.csproj b/CarCenter/CarCenterDataModels/CarCenterDataModels.csproj index 132c02c..5c34257 100644 --- a/CarCenter/CarCenterDataModels/CarCenterDataModels.csproj +++ b/CarCenter/CarCenterDataModels/CarCenterDataModels.csproj @@ -6,4 +6,11 @@ enable + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + + diff --git a/CarCenter/CarCenterDataModels/Models/ICarModel.cs b/CarCenter/CarCenterDataModels/Models/ICarModel.cs index b363974..f3c7917 100644 --- a/CarCenter/CarCenterDataModels/Models/ICarModel.cs +++ b/CarCenter/CarCenterDataModels/Models/ICarModel.cs @@ -9,8 +9,8 @@ namespace CarCenterDataModels.Models public interface ICarModel : IId { string Name { get; } - Dictionary CarPresales { get; } - Dictionary CarConfigurations { get; } + Dictionary PresaleCars { get; } + Dictionary ConfigurationCars { get; } int EmployeeId { get; } } } diff --git a/CarCenter/CarCenterDataModels/Models/IPresaleModel.cs b/CarCenter/CarCenterDataModels/Models/IPresaleModel.cs index ff369ce..bb03b51 100644 --- a/CarCenter/CarCenterDataModels/Models/IPresaleModel.cs +++ b/CarCenter/CarCenterDataModels/Models/IPresaleModel.cs @@ -10,5 +10,6 @@ namespace CarCenterDataModels.Models { DateTime PresaleDate { get; } int EmployeeId { get; } + int? TypeOfJobId { get; } } } diff --git a/CarCenter/CarCenterDatabaseImplement/CarCenterDatabase.cs b/CarCenter/CarCenterDatabaseImplement/CarCenterDatabase.cs new file mode 100644 index 0000000..274a400 --- /dev/null +++ b/CarCenter/CarCenterDatabaseImplement/CarCenterDatabase.cs @@ -0,0 +1,34 @@ +using CarCenterDatabaseImplement.Models; +using Microsoft.EntityFrameworkCore; +using System; +using System.Collections.Generic; +using System.ComponentModel.Design; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace CarCenterDatabaseImplement +{ + public class CarCenterDatabase : DbContext + { + protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) + { + if (optionsBuilder.IsConfigured == false) + { + optionsBuilder.UseSqlServer(@"Data Source=DESKTOP-18O8941\SQLEXPRESS;Initial Catalog=CarCenterDatabase;Integrated Security=True;MultipleActiveResultSets=True;;TrustServerCertificate=True"); + } + base.OnConfiguring(optionsBuilder); + } + public virtual DbSet Employees { set; get; } + public virtual DbSet Presales { set; get; } + public virtual DbSet Cars { set; get; } + public virtual DbSet Sales { set; get; } + public virtual DbSet PresaleCars { set; get; } + public virtual DbSet ConfigurationCars { set; get; } + public virtual DbSet Configurations { set; get; } + public virtual DbSet Bosses { set; get; } + public virtual DbSet TypeOfJobs { set; get; } + public virtual DbSet Receipts { set; get; } + public virtual DbSet TypeOfJobConfigurations { set; get; } + } +} diff --git a/CarCenter/CarCenterDatabaseImplement/CarCenterDatabaseImplement.csproj b/CarCenter/CarCenterDatabaseImplement/CarCenterDatabaseImplement.csproj new file mode 100644 index 0000000..712e4c6 --- /dev/null +++ b/CarCenter/CarCenterDatabaseImplement/CarCenterDatabaseImplement.csproj @@ -0,0 +1,22 @@ + + + + net6.0 + enable + enable + + + + + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + + + + + + + diff --git a/CarCenter/CarCenterDatabaseImplement/Implements/BossStorage.cs b/CarCenter/CarCenterDatabaseImplement/Implements/BossStorage.cs new file mode 100644 index 0000000..91f9a87 --- /dev/null +++ b/CarCenter/CarCenterDatabaseImplement/Implements/BossStorage.cs @@ -0,0 +1,98 @@ +using CarCenterContracts.BindingModels; +using CarCenterContracts.SearchModels; +using CarCenterContracts.StoragesContracts; +using CarCenterContracts.ViewModels; +using CarCenterDatabaseImplement.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace CarCenterDatabaseImplement.Implements +{ + public class BossStorage : IBossStorage + { + public BossViewModel? Delete(BossBindingModel model) + { + using var context = new CarCenterDatabase(); + var element = context.Bosses.FirstOrDefault(rec => rec.Id == model.Id); + if (element != null) + { + context.Bosses.Remove(element); + context.SaveChanges(); + return element.GetViewModel; + } + return null; + } + + public BossViewModel? GetElement(BossSearchModel model) + { + if (!model.Id.HasValue && string.IsNullOrEmpty(model.Login) && string.IsNullOrEmpty(model.Password)) + { + return null; + } + if (!string.IsNullOrEmpty(model.Login) && !string.IsNullOrEmpty(model.Password)) + { + using var context = new CarCenterDatabase(); + return context.Bosses + .FirstOrDefault(x => x.Login == model.Login && x.Password == model.Password) + ?.GetViewModel; + } + else + { + using var context = new CarCenterDatabase(); + return context.Bosses + .FirstOrDefault(x => x.Id == model.Id) + ?.GetViewModel; + } + } + + public List GetFilteredList(BossSearchModel model) + { + if (!model.Id.HasValue) + { + return new(); + } + using var context = new CarCenterDatabase(); + return context.Bosses + .Where(x => x.Id == model.Id) + .Select(x => x.GetViewModel) + .ToList(); + } + + public List GetFullList() + { + using var context = new CarCenterDatabase(); + return context.Bosses + .Select(x => x.GetViewModel) + .ToList(); + } + + public BossViewModel? Insert(BossBindingModel model) + { + using var context = new CarCenterDatabase(); + var newBoss = Boss.Create(model); + if (newBoss == null) + { + return null; + } + context.Bosses.Add(newBoss); + context.SaveChanges(); + return newBoss.GetViewModel; + } + + public BossViewModel? Update(BossBindingModel model) + { + using var context = new CarCenterDatabase(); + var boss = context.Bosses.FirstOrDefault(x => x.Id == model.Id); + if (boss == null) + { + return null; + } + boss.Update(model); + context.SaveChanges(); + return boss.GetViewModel; + } + } +} diff --git a/CarCenter/CarCenterDatabaseImplement/Implements/CarStorage.cs b/CarCenter/CarCenterDatabaseImplement/Implements/CarStorage.cs new file mode 100644 index 0000000..6deeba6 --- /dev/null +++ b/CarCenter/CarCenterDatabaseImplement/Implements/CarStorage.cs @@ -0,0 +1,98 @@ +using CarCenterContracts.BindingModels; +using CarCenterContracts.SearchModels; +using CarCenterContracts.StoragesContracts; +using CarCenterContracts.ViewModels; +using CarCenterDatabaseImplement.Models; +using Microsoft.EntityFrameworkCore; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace CarCenterDatabaseImplement.Implements +{ + public class CarStorage : ICarStorage + { + public List GetFullList() + { + using var context = new CarCenterDatabase(); + return context.Cars.Include(x => x.Employee) + .Select(x => x.GetViewModel) + .ToList(); + } + public List GetFilteredList(CarSearchModel model) + { + if (!model.Id.HasValue && !model.EmployeeId.HasValue) + { + return new(); + } + if (model.EmployeeId.HasValue) + { + using var context = new CarCenterDatabase(); + return context.Cars.Include(x => x.Employee) + .Where(x => x.EmployeeId == model.EmployeeId) + .Select(x => x.GetViewModel) + .ToList(); + } + else + { + using var context = new CarCenterDatabase(); + return context.Cars.Include(x => x.Employee) + .Where(x => x.Id == model.Id) + .Select(x => x.GetViewModel) + .ToList(); + } + + } + public CarViewModel? GetElement(CarSearchModel model) + { + if (!model.Id.HasValue) + { + return null; + } + using var context = new CarCenterDatabase(); + return context.Cars.Include(x => x.Employee) + .FirstOrDefault(x => x.Id == model.Id) + ?.GetViewModel; + } + public CarViewModel? Insert(CarBindingModel model) + { + using var context = new CarCenterDatabase(); + var newCar = Car.Create(context, model); + if (newCar == null) + { + return null; + } + context.Cars.Add(newCar); + context.SaveChanges(); + return newCar.GetViewModel; + } + public CarViewModel? Update(CarBindingModel model) + { + using var context = new CarCenterDatabase(); + var car = context.Cars.FirstOrDefault(x => x.Id == model.Id); + if (car == null) + { + return null; + } + car.Update(model); + car.UpdatePresales(context, model); + car.UpdateConfigurations(context, model); + context.SaveChanges(); + return car.GetViewModel; + } + public CarViewModel? Delete(CarBindingModel model) + { + using var context = new CarCenterDatabase(); + var element = context.Cars.FirstOrDefault(rec => rec.Id == model.Id); + if (element != null) + { + context.Cars.Remove(element); + context.SaveChanges(); + return element.GetViewModel; + } + return null; + } + } +} diff --git a/CarCenter/CarCenterDatabaseImplement/Implements/ConfigurationStorage.cs b/CarCenter/CarCenterDatabaseImplement/Implements/ConfigurationStorage.cs new file mode 100644 index 0000000..48f0063 --- /dev/null +++ b/CarCenter/CarCenterDatabaseImplement/Implements/ConfigurationStorage.cs @@ -0,0 +1,100 @@ +using CarCenterContracts.BindingModels; +using CarCenterContracts.SearchModels; +using CarCenterContracts.StoragesContracts; +using CarCenterContracts.ViewModels; +using CarCenterDatabaseImplement.Models; +using Microsoft.EntityFrameworkCore; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace CarCenterDatabaseImplement.Implements +{ + public class ConfigurationStorage : IConfigurationStorage + { + public ConfigurationViewModel? Delete(ConfigurationBindingModel model) + { + using var context = new CarCenterDatabase(); + var element = context.Configurations.FirstOrDefault(rec => rec.Id == model.Id); + if (element != null) + { + context.Configurations.Remove(element); + context.SaveChanges(); + return element.GetViewModel; + } + return null; + } + + public ConfigurationViewModel? GetElement(ConfigurationSearchModel model) + { + if (!model.Id.HasValue) + { + return null; + } + using var context = new CarCenterDatabase(); + return context.Configurations.Include(x => x.Boss) + .FirstOrDefault(x => x.Id == model.Id) + ?.GetViewModel; + } + + public List GetFilteredList(ConfigurationSearchModel model) + { + if (!model.Id.HasValue && !model.BossId.HasValue) + { + return new(); + } + if (model.BossId.HasValue) + { + using var context = new CarCenterDatabase(); + return context.Configurations.Include(x => x.Boss) + .Where(x => x.BossId == model.BossId) + .Select(x => x.GetViewModel) + .ToList(); + } + else + { + using var context = new CarCenterDatabase(); + return context.Configurations.Include(x => x.Boss) + .Where(x => x.Id == model.Id) + .Select(x => x.GetViewModel) + .ToList(); + } + } + + public List GetFullList() + { + using var context = new CarCenterDatabase(); + return context.Configurations.Include(x => x.Boss) + .Select(x => x.GetViewModel) + .ToList(); + } + + public ConfigurationViewModel? Insert(ConfigurationBindingModel model) + { + using var context = new CarCenterDatabase(); + var newConfiguration = Configuration.Create(context, model); + if (newConfiguration == null) + { + return null; + } + context.Configurations.Add(newConfiguration); + context.SaveChanges(); + return newConfiguration.GetViewModel; + } + + public ConfigurationViewModel? Update(ConfigurationBindingModel model) + { + using var context = new CarCenterDatabase(); + var configuration = context.Configurations.FirstOrDefault(x => x.Id == model.Id); + if (configuration == null) + { + return null; + } + configuration.Update(model); + context.SaveChanges(); + return configuration.GetViewModel; + } + } +} diff --git a/CarCenter/CarCenterDatabaseImplement/Implements/EmployeeStorage.cs b/CarCenter/CarCenterDatabaseImplement/Implements/EmployeeStorage.cs new file mode 100644 index 0000000..de0a13a --- /dev/null +++ b/CarCenter/CarCenterDatabaseImplement/Implements/EmployeeStorage.cs @@ -0,0 +1,104 @@ +using CarCenterContracts.BindingModels; +using CarCenterContracts.SearchModels; +using CarCenterContracts.StoragesContracts; +using CarCenterContracts.ViewModels; +using CarCenterDatabaseImplement.Models; +using Microsoft.EntityFrameworkCore; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace CarCenterDatabaseImplement.Implements +{ + public class EmployeeStorage : IEmployeeStorage + { + public List GetFullList() + { + using var context = new CarCenterDatabase(); + return context.Employees + .Select(x => x.GetViewModel) + .ToList(); + } + public List GetFilteredList(EmployeeSearchModel model) + { + if (!model.Id.HasValue && string.IsNullOrEmpty(model.Login) && string.IsNullOrEmpty(model.Password)) + { + return new(); + } + using var context = new CarCenterDatabase(); + if (!string.IsNullOrEmpty(model.Login) && !string.IsNullOrEmpty(model.Password)) + { + return context.Employees + .Where(x => x.Login == model.Login || x.Password == model.Password) + .Select(x => x.GetViewModel) + .ToList(); + } + else + { + return context.Employees + .Where(x => x.Id == model.Id) + .Select(x => x.GetViewModel) + .ToList(); + } + } + public EmployeeViewModel? GetElement(EmployeeSearchModel model) + { + if (!model.Id.HasValue && string.IsNullOrEmpty(model.Login) && string.IsNullOrEmpty(model.Password)) + { + return null; + } + if (!string.IsNullOrEmpty(model.Login) && !string.IsNullOrEmpty(model.Password)) + { + using var context = new CarCenterDatabase(); + return context.Employees + .FirstOrDefault(x => x.Login == model.Login && x.Password == model.Password) + ?.GetViewModel; + } + else + { + using var context = new CarCenterDatabase(); + return context.Employees + .FirstOrDefault(x => x.Id == model.Id) + ?.GetViewModel; + } + } + public EmployeeViewModel? Insert(EmployeeBindingModel model) + { + using var context = new CarCenterDatabase(); + var newEmployee = Employee.Create(model); + if (newEmployee == null) + { + return null; + } + context.Employees.Add(newEmployee); + context.SaveChanges(); + return newEmployee.GetViewModel; + } + public EmployeeViewModel? Update(EmployeeBindingModel model) + { + using var context = new CarCenterDatabase(); + var employeeUpdate = context.Employees.FirstOrDefault(x => x.Id == model.Id); + if (employeeUpdate == null) + { + return null; + } + employeeUpdate.Update(model); + context.SaveChanges(); + return employeeUpdate.GetViewModel; + } + public EmployeeViewModel? Delete(EmployeeBindingModel model) + { + using var context = new CarCenterDatabase(); + var element = context.Employees.FirstOrDefault(rec => rec.Id == model.Id); + if (element != null) + { + context.Employees.Remove(element); + context.SaveChanges(); + return element.GetViewModel; + } + return null; + } + } +} diff --git a/CarCenter/CarCenterDatabaseImplement/Implements/PresaleStorage.cs b/CarCenter/CarCenterDatabaseImplement/Implements/PresaleStorage.cs new file mode 100644 index 0000000..ee6afca --- /dev/null +++ b/CarCenter/CarCenterDatabaseImplement/Implements/PresaleStorage.cs @@ -0,0 +1,95 @@ +using CarCenterContracts.BindingModels; +using CarCenterContracts.SearchModels; +using CarCenterContracts.StoragesContracts; +using CarCenterContracts.ViewModels; +using CarCenterDatabaseImplement.Models; +using Microsoft.EntityFrameworkCore; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace CarCenterDatabaseImplement.Implements +{ + public class PresaleStorage : IPresaleStorage + { + public List GetFullList() + { + using var context = new CarCenterDatabase(); + return context.Presales.Include(x => x.Employee).Include(x => x.TypeOfJob) + .Select(x => x.GetViewModel) + .ToList(); + } + public List GetFilteredList(PresaleSearchModel model) + { + if (!model.Id.HasValue && !model.EmployeeId.HasValue) + { + return new(); + } + if (model.EmployeeId.HasValue) + { + using var context = new CarCenterDatabase(); + return context.Presales.Include(x => x.Employee).Include(x => x.TypeOfJob) + .Where(x => x.EmployeeId == model.EmployeeId) + .Select(x => x.GetViewModel) + .ToList(); + } + else + { + using var context = new CarCenterDatabase(); + return context.Presales.Include(x => x.Employee).Include(x => x.TypeOfJob) + .Where(x => x.Id == model.Id) + .Select(x => x.GetViewModel) + .ToList(); + } + } + public PresaleViewModel? GetElement(PresaleSearchModel model) + { + if (!model.Id.HasValue) + { + return null; + } + using var context = new CarCenterDatabase(); + return context.Presales.Include(x => x.Employee).Include(x => x.TypeOfJob) + .FirstOrDefault(x => x.Id == model.Id) + ?.GetViewModel; + } + public PresaleViewModel? Insert(PresaleBindingModel model) + { + using var context = new CarCenterDatabase(); + var newPresale = Presale.Create(context, model); + if (newPresale == null) + { + return null; + } + context.Presales.Add(newPresale); + context.SaveChanges(); + return newPresale.GetViewModel; + } + public PresaleViewModel? Update(PresaleBindingModel model) + { + using var context = new CarCenterDatabase(); + var presale = context.Presales.FirstOrDefault(x => x.Id == model.Id); + if (presale == null) + { + return null; + } + presale.Update(model); + context.SaveChanges(); + return presale.GetViewModel; + } + public PresaleViewModel? Delete(PresaleBindingModel model) + { + using var context = new CarCenterDatabase(); + var element = context.Presales.FirstOrDefault(rec => rec.Id == model.Id); + if (element != null) + { + context.Presales.Remove(element); + context.SaveChanges(); + return element.GetViewModel; + } + return null; + } + } +} diff --git a/CarCenter/CarCenterDatabaseImplement/Implements/ReceiptStorage.cs b/CarCenter/CarCenterDatabaseImplement/Implements/ReceiptStorage.cs new file mode 100644 index 0000000..70e3697 --- /dev/null +++ b/CarCenter/CarCenterDatabaseImplement/Implements/ReceiptStorage.cs @@ -0,0 +1,100 @@ +using CarCenterContracts.BindingModels; +using CarCenterContracts.SearchModels; +using CarCenterContracts.StoragesContracts; +using CarCenterContracts.ViewModels; +using CarCenterDatabaseImplement.Models; +using Microsoft.EntityFrameworkCore; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace CarCenterDatabaseImplement.Implements +{ + public class ReceiptStorage : IReceiptStorage + { + public ReceiptViewModel? Delete(ReceiptBindingModel model) + { + using var context = new CarCenterDatabase(); + var receipt = context.Receipts.FirstOrDefault(x => x.Id == model.Id); + if (receipt == null) + { + return null; + } + receipt.Update(model); + context.SaveChanges(); + return receipt.GetViewModel; + } + + public ReceiptViewModel? GetElement(ReceiptSearchModel model) + { + if (!model.Id.HasValue) + { + return null; + } + using var context = new CarCenterDatabase(); + return context.Receipts.Include(x => x.Boss).Include(x=>x.Configuration) + .FirstOrDefault(x => x.Id == model.Id) + ?.GetViewModel; + } + + public List GetFilteredList(ReceiptSearchModel model) + { + if (!model.Id.HasValue && !model.DateFrom.HasValue && !model.DateTo.HasValue) + { + return new(); + } + if (model.DateFrom.HasValue && model.DateTo.HasValue) + { + using var context = new CarCenterDatabase(); + return context.Receipts.Include(x => x.Boss).Include(x => x.Configuration) + .Where(x => x.ReceiptDate >= model.DateFrom && x.ReceiptDate <= model.DateTo) + .Select(x => x.GetViewModel) + .ToList(); + } + else + { + using var context = new CarCenterDatabase(); + return context.Receipts.Include(x => x.Boss).Include(x => x.Configuration) + .Where(x => x.Id == model.Id) + .Select(x => x.GetViewModel) + .ToList(); + } + } + + public List GetFullList() + { + using var context = new CarCenterDatabase(); + return context.Receipts.Include(x => x.Boss).Include(x=> x.Configuration) + .Select(x => x.GetViewModel) + .ToList(); + } + + public ReceiptViewModel? Insert(ReceiptBindingModel model) + { + using var context = new CarCenterDatabase(); + var newReceipt = Receipt.Create(context, model); + if (newReceipt == null) + { + return null; + } + context.Receipts.Add(newReceipt); + context.SaveChanges(); + return newReceipt.GetViewModel; + } + + public ReceiptViewModel? Update(ReceiptBindingModel model) + { + using var context = new CarCenterDatabase(); + var receipt = context.Receipts.FirstOrDefault(x => x.Id == model.Id); + if (receipt == null) + { + return null; + } + receipt.Update(model); + context.SaveChanges(); + return receipt.GetViewModel; + } + } +} diff --git a/CarCenter/CarCenterDatabaseImplement/Implements/SaleStorage.cs b/CarCenter/CarCenterDatabaseImplement/Implements/SaleStorage.cs new file mode 100644 index 0000000..d3d023c --- /dev/null +++ b/CarCenter/CarCenterDatabaseImplement/Implements/SaleStorage.cs @@ -0,0 +1,103 @@ +using CarCenterContracts.BindingModels; +using CarCenterContracts.SearchModels; +using CarCenterContracts.StoragesContracts; +using CarCenterContracts.ViewModels; +using CarCenterDatabaseImplement.Models; +using Microsoft.EntityFrameworkCore; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace CarCenterDatabaseImplement.Implements +{ + public class SaleStorage : ISaleStorage + { + public List GetFullList() + { + using var context = new CarCenterDatabase(); + return context.Sales.Include(x => x.Car).Include(x => x.Receipt).Include(x => x.Configuration).Include(x => x.EmployeeId) + .Select(x => x.GetViewModel) + .ToList(); + } + public List GetFilteredList(SaleSearchModel model) + { + if (!model.Id.HasValue && !model.EmployeeId.HasValue && !model.DateFrom.HasValue && !model.DateTo.HasValue) + { + return new(); + } + if (model.DateFrom.HasValue && model.DateTo.HasValue) + { + using var context = new CarCenterDatabase(); + return context.Sales.Include(x => x.Car).Include(x => x.Receipt).Include(x => x.Configuration).Include(x => x.EmployeeId) + .Where(x => x.SaleDateTime >= model.DateFrom && x.SaleDateTime <= model.DateTo) + .Select(x => x.GetViewModel) + .ToList(); + } + if (model.EmployeeId.HasValue) + { + using var context = new CarCenterDatabase(); + return context.Sales.Include(x => x.Car).Include(x => x.Receipt).Include(x => x.Configuration).Include(x => x.EmployeeId) + .Where(x => x.EmployeeId == model.EmployeeId) + .Select(x => x.GetViewModel) + .ToList(); + } + else + { + using var context = new CarCenterDatabase(); + return context.Sales.Include(x => x.Car).Include(x => x.Receipt).Include(x => x.Configuration).Include(x => x.EmployeeId) + .Where(x => x.Id == model.Id) + .Select(x => x.GetViewModel) + .ToList(); + } + } + public SaleViewModel? GetElement(SaleSearchModel model) + { + if (!model.Id.HasValue) + { + return null; + } + using var context = new CarCenterDatabase(); + return context.Sales.Include(x => x.Car).Include(x => x.Receipt).Include(x => x.Configuration).Include(x => x.EmployeeId) + .FirstOrDefault(x => x.Id == model.Id) + ?.GetViewModel; + } + public SaleViewModel? Insert(SaleBindingModel model) + { + using var context = new CarCenterDatabase(); + var newSale = Sale.Create(context, model); + if (newSale == null) + { + return null; + } + context.Sales.Add(newSale); + context.SaveChanges(); + return newSale.GetViewModel; + } + public SaleViewModel? Update(SaleBindingModel model) + { + using var context = new CarCenterDatabase(); + var sale = context.Sales.FirstOrDefault(x => x.Id == model.Id); + if (sale == null) + { + return null; + } + sale.Update(model); + context.SaveChanges(); + return sale.GetViewModel; + } + public SaleViewModel? Delete(SaleBindingModel model) + { + using var context = new CarCenterDatabase(); + var element = context.Sales.FirstOrDefault(rec => rec.Id == model.Id); + if (element != null) + { + context.Sales.Remove(element); + context.SaveChanges(); + return element.GetViewModel; + } + return null; + } + } +} diff --git a/CarCenter/CarCenterDatabaseImplement/Implements/TypeOfJobStorage.cs b/CarCenter/CarCenterDatabaseImplement/Implements/TypeOfJobStorage.cs new file mode 100644 index 0000000..894ecbd --- /dev/null +++ b/CarCenter/CarCenterDatabaseImplement/Implements/TypeOfJobStorage.cs @@ -0,0 +1,101 @@ +using CarCenterContracts.BindingModels; +using CarCenterContracts.SearchModels; +using CarCenterContracts.StoragesContracts; +using CarCenterContracts.ViewModels; +using CarCenterDatabaseImplement.Models; +using Microsoft.EntityFrameworkCore; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace CarCenterDatabaseImplement.Implements +{ + public class TypeOfJobStorage : ITypeOfJobStorage + { + public TypeOfJobViewModel? Delete(TypeOfJobBindingModel model) + { + using var context = new CarCenterDatabase(); + var element = context.TypeOfJobs.FirstOrDefault(rec => rec.Id == model.Id); + if (element != null) + { + context.TypeOfJobs.Remove(element); + context.SaveChanges(); + return element.GetViewModel; + } + return null; + } + + public TypeOfJobViewModel? GetElement(TypeOfJobSearchModel model) + { + if (!model.Id.HasValue) + { + return null; + } + using var context = new CarCenterDatabase(); + return context.TypeOfJobs.Include(x => x.Boss) + .FirstOrDefault(x => x.Id == model.Id) + ?.GetViewModel; + } + + public List GetFilteredList(TypeOfJobSearchModel model) + { + if (!model.Id.HasValue && !model.BossId.HasValue) + { + return new(); + } + if (model.BossId.HasValue) + { + using var context = new CarCenterDatabase(); + return context.TypeOfJobs.Include(x => x.Boss) + .Where(x => x.BossId == model.BossId) + .Select(x => x.GetViewModel) + .ToList(); + } + else + { + using var context = new CarCenterDatabase(); + return context.TypeOfJobs.Include(x => x.Boss) + .Where(x => x.Id == model.Id) + .Select(x => x.GetViewModel) + .ToList(); + } + } + + public List GetFullList() + { + using var context = new CarCenterDatabase(); + return context.TypeOfJobs.Include(x => x.Boss) + .Select(x => x.GetViewModel) + .ToList(); + } + + public TypeOfJobViewModel? Insert(TypeOfJobBindingModel model) + { + using var context = new CarCenterDatabase(); + var newTypeOfJob = TypeOfJob.Create(context, model); + if (newTypeOfJob == null) + { + return null; + } + context.TypeOfJobs.Add(newTypeOfJob); + context.SaveChanges(); + return newTypeOfJob.GetViewModel; + } + + public TypeOfJobViewModel? Update(TypeOfJobBindingModel model) + { + using var context = new CarCenterDatabase(); + var typeOfJob = context.TypeOfJobs.FirstOrDefault(x => x.Id == model.Id); + if (typeOfJob == null) + { + return null; + } + typeOfJob.Update(model); + typeOfJob.UpdateConfigurations(context, model); + context.SaveChanges(); + return typeOfJob.GetViewModel; + } + } +} diff --git a/CarCenter/CarCenterDatabaseImplement/Migrations/20230409095705_InitialCreate.Designer.cs b/CarCenter/CarCenterDatabaseImplement/Migrations/20230409095705_InitialCreate.Designer.cs new file mode 100644 index 0000000..acedc30 --- /dev/null +++ b/CarCenter/CarCenterDatabaseImplement/Migrations/20230409095705_InitialCreate.Designer.cs @@ -0,0 +1,501 @@ +// +using System; +using CarCenterDatabaseImplement; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Metadata; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; + +#nullable disable + +namespace CarCenterDatabaseImplement.Migrations +{ + [DbContext(typeof(CarCenterDatabase))] + [Migration("20230409095705_InitialCreate")] + partial class InitialCreate + { + /// + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "7.0.4") + .HasAnnotation("Relational:MaxIdentifierLength", 128); + + SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder); + + modelBuilder.Entity("CarCenterDatabaseImplement.Models.Boss", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("Login") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Name") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Password") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Patronymic") + .HasColumnType("nvarchar(max)"); + + b.Property("Surname") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.HasKey("Id"); + + b.ToTable("Bosses"); + }); + + modelBuilder.Entity("CarCenterDatabaseImplement.Models.Car", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("EmployeeId") + .HasColumnType("int"); + + b.Property("Name") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.HasKey("Id"); + + b.HasIndex("EmployeeId"); + + b.ToTable("Cars"); + }); + + modelBuilder.Entity("CarCenterDatabaseImplement.Models.Configuration", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("BossId") + .HasColumnType("int"); + + b.Property("Name") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.HasKey("Id"); + + b.HasIndex("BossId"); + + b.ToTable("Configurations"); + }); + + modelBuilder.Entity("CarCenterDatabaseImplement.Models.ConfigurationCar", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("CarId") + .HasColumnType("int"); + + b.Property("ConfigurationId") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.HasIndex("CarId"); + + b.HasIndex("ConfigurationId"); + + b.ToTable("ConfigurationCars"); + }); + + modelBuilder.Entity("CarCenterDatabaseImplement.Models.Employee", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("Login") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Name") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Password") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Patronymic") + .HasColumnType("nvarchar(max)"); + + b.Property("Surname") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.HasKey("Id"); + + b.ToTable("Employees"); + }); + + modelBuilder.Entity("CarCenterDatabaseImplement.Models.Presale", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("EmployeeId") + .HasColumnType("int"); + + b.Property("PresaleDate") + .HasColumnType("datetime2"); + + b.Property("TypeOfJobId") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.HasIndex("EmployeeId"); + + b.HasIndex("TypeOfJobId"); + + b.ToTable("Presales"); + }); + + modelBuilder.Entity("CarCenterDatabaseImplement.Models.PresaleCar", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("CarId") + .HasColumnType("int"); + + b.Property("PresaleId") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.HasIndex("CarId"); + + b.HasIndex("PresaleId"); + + b.ToTable("PresaleCars"); + }); + + modelBuilder.Entity("CarCenterDatabaseImplement.Models.Receipt", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("BossId") + .HasColumnType("int"); + + b.Property("ConfigurationId") + .HasColumnType("int"); + + b.Property("ReceiptDate") + .HasColumnType("datetime2"); + + b.Property("Sum") + .HasColumnType("real"); + + b.HasKey("Id"); + + b.HasIndex("BossId"); + + b.HasIndex("ConfigurationId"); + + b.ToTable("Receipts"); + }); + + modelBuilder.Entity("CarCenterDatabaseImplement.Models.Sale", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("CarId") + .HasColumnType("int"); + + b.Property("ConfigurationId") + .HasColumnType("int"); + + b.Property("EmployeeId") + .HasColumnType("int"); + + b.Property("ReceiptId") + .HasColumnType("int"); + + b.Property("SaleDateTime") + .HasColumnType("datetime2"); + + b.Property("Sum") + .HasColumnType("real"); + + b.HasKey("Id"); + + b.HasIndex("CarId"); + + b.HasIndex("ConfigurationId"); + + b.HasIndex("EmployeeId"); + + b.HasIndex("ReceiptId"); + + b.ToTable("Sales"); + }); + + modelBuilder.Entity("CarCenterDatabaseImplement.Models.TypeOfJob", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("BossId") + .HasColumnType("int"); + + b.Property("Name") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.HasKey("Id"); + + b.HasIndex("BossId"); + + b.ToTable("TypeOfJobs"); + }); + + modelBuilder.Entity("CarCenterDatabaseImplement.Models.TypeOfJobConfiguration", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("ConfigurationId") + .HasColumnType("int"); + + b.Property("TypeOfJobId") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.HasIndex("ConfigurationId"); + + b.HasIndex("TypeOfJobId"); + + b.ToTable("TypeOfJobConfigurations"); + }); + + modelBuilder.Entity("CarCenterDatabaseImplement.Models.Car", b => + { + b.HasOne("CarCenterDatabaseImplement.Models.Employee", "Employee") + .WithMany() + .HasForeignKey("EmployeeId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Employee"); + }); + + modelBuilder.Entity("CarCenterDatabaseImplement.Models.Configuration", b => + { + b.HasOne("CarCenterDatabaseImplement.Models.Boss", "Boss") + .WithMany() + .HasForeignKey("BossId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Boss"); + }); + + modelBuilder.Entity("CarCenterDatabaseImplement.Models.ConfigurationCar", b => + { + b.HasOne("CarCenterDatabaseImplement.Models.Car", "Car") + .WithMany("Configurations") + .HasForeignKey("CarId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("CarCenterDatabaseImplement.Models.Configuration", "Configuration") + .WithMany() + .HasForeignKey("ConfigurationId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Car"); + + b.Navigation("Configuration"); + }); + + modelBuilder.Entity("CarCenterDatabaseImplement.Models.Presale", b => + { + b.HasOne("CarCenterDatabaseImplement.Models.Employee", "Employee") + .WithMany() + .HasForeignKey("EmployeeId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("CarCenterDatabaseImplement.Models.TypeOfJob", "TypeOfJob") + .WithMany() + .HasForeignKey("TypeOfJobId"); + + b.Navigation("Employee"); + + b.Navigation("TypeOfJob"); + }); + + modelBuilder.Entity("CarCenterDatabaseImplement.Models.PresaleCar", b => + { + b.HasOne("CarCenterDatabaseImplement.Models.Car", "Car") + .WithMany("Presales") + .HasForeignKey("CarId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("CarCenterDatabaseImplement.Models.Presale", "Presale") + .WithMany("PresaleCars") + .HasForeignKey("PresaleId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Car"); + + b.Navigation("Presale"); + }); + + modelBuilder.Entity("CarCenterDatabaseImplement.Models.Receipt", b => + { + b.HasOne("CarCenterDatabaseImplement.Models.Boss", "Boss") + .WithMany() + .HasForeignKey("BossId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("CarCenterDatabaseImplement.Models.Configuration", "Configuration") + .WithMany() + .HasForeignKey("ConfigurationId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Boss"); + + b.Navigation("Configuration"); + }); + + modelBuilder.Entity("CarCenterDatabaseImplement.Models.Sale", b => + { + b.HasOne("CarCenterDatabaseImplement.Models.Car", "Car") + .WithMany() + .HasForeignKey("CarId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("CarCenterDatabaseImplement.Models.Configuration", "Configuration") + .WithMany() + .HasForeignKey("ConfigurationId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("CarCenterDatabaseImplement.Models.Employee", "Employee") + .WithMany() + .HasForeignKey("EmployeeId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("CarCenterDatabaseImplement.Models.Receipt", "Receipt") + .WithMany() + .HasForeignKey("ReceiptId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Car"); + + b.Navigation("Configuration"); + + b.Navigation("Employee"); + + b.Navigation("Receipt"); + }); + + modelBuilder.Entity("CarCenterDatabaseImplement.Models.TypeOfJob", b => + { + b.HasOne("CarCenterDatabaseImplement.Models.Boss", "Boss") + .WithMany() + .HasForeignKey("BossId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Boss"); + }); + + modelBuilder.Entity("CarCenterDatabaseImplement.Models.TypeOfJobConfiguration", b => + { + b.HasOne("CarCenterDatabaseImplement.Models.Configuration", "Configuration") + .WithMany() + .HasForeignKey("ConfigurationId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("CarCenterDatabaseImplement.Models.TypeOfJob", "TypeOfJob") + .WithMany("Configurations") + .HasForeignKey("TypeOfJobId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Configuration"); + + b.Navigation("TypeOfJob"); + }); + + modelBuilder.Entity("CarCenterDatabaseImplement.Models.Car", b => + { + b.Navigation("Configurations"); + + b.Navigation("Presales"); + }); + + modelBuilder.Entity("CarCenterDatabaseImplement.Models.Presale", b => + { + b.Navigation("PresaleCars"); + }); + + modelBuilder.Entity("CarCenterDatabaseImplement.Models.TypeOfJob", b => + { + b.Navigation("Configurations"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/CarCenter/CarCenterDatabaseImplement/Migrations/20230409095705_InitialCreate.cs b/CarCenter/CarCenterDatabaseImplement/Migrations/20230409095705_InitialCreate.cs new file mode 100644 index 0000000..f862876 --- /dev/null +++ b/CarCenter/CarCenterDatabaseImplement/Migrations/20230409095705_InitialCreate.cs @@ -0,0 +1,405 @@ +using System; +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +namespace CarCenterDatabaseImplement.Migrations +{ + /// + public partial class InitialCreate : Migration + { + /// + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.CreateTable( + name: "Bosses", + columns: table => new + { + Id = table.Column(type: "int", nullable: false) + .Annotation("SqlServer:Identity", "1, 1"), + Login = table.Column(type: "nvarchar(max)", nullable: false), + Password = table.Column(type: "nvarchar(max)", nullable: false), + Name = table.Column(type: "nvarchar(max)", nullable: false), + Surname = table.Column(type: "nvarchar(max)", nullable: false), + Patronymic = table.Column(type: "nvarchar(max)", nullable: true) + }, + constraints: table => + { + table.PrimaryKey("PK_Bosses", x => x.Id); + }); + + migrationBuilder.CreateTable( + name: "Employees", + columns: table => new + { + Id = table.Column(type: "int", nullable: false) + .Annotation("SqlServer:Identity", "1, 1"), + Login = table.Column(type: "nvarchar(max)", nullable: false), + Password = table.Column(type: "nvarchar(max)", nullable: false), + Surname = table.Column(type: "nvarchar(max)", nullable: false), + Name = table.Column(type: "nvarchar(max)", nullable: false), + Patronymic = table.Column(type: "nvarchar(max)", nullable: true) + }, + constraints: table => + { + table.PrimaryKey("PK_Employees", x => x.Id); + }); + + migrationBuilder.CreateTable( + name: "Configurations", + columns: table => new + { + Id = table.Column(type: "int", nullable: false) + .Annotation("SqlServer:Identity", "1, 1"), + Name = table.Column(type: "nvarchar(max)", nullable: false), + BossId = table.Column(type: "int", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Configurations", x => x.Id); + table.ForeignKey( + name: "FK_Configurations_Bosses_BossId", + column: x => x.BossId, + principalTable: "Bosses", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateTable( + name: "TypeOfJobs", + columns: table => new + { + Id = table.Column(type: "int", nullable: false) + .Annotation("SqlServer:Identity", "1, 1"), + Name = table.Column(type: "nvarchar(max)", nullable: false), + BossId = table.Column(type: "int", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_TypeOfJobs", x => x.Id); + table.ForeignKey( + name: "FK_TypeOfJobs_Bosses_BossId", + column: x => x.BossId, + principalTable: "Bosses", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateTable( + name: "Cars", + columns: table => new + { + Id = table.Column(type: "int", nullable: false) + .Annotation("SqlServer:Identity", "1, 1"), + Name = table.Column(type: "nvarchar(max)", nullable: false), + EmployeeId = table.Column(type: "int", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Cars", x => x.Id); + table.ForeignKey( + name: "FK_Cars_Employees_EmployeeId", + column: x => x.EmployeeId, + principalTable: "Employees", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateTable( + name: "Receipts", + columns: table => new + { + Id = table.Column(type: "int", nullable: false) + .Annotation("SqlServer:Identity", "1, 1"), + Sum = table.Column(type: "real", nullable: false), + ReceiptDate = table.Column(type: "datetime2", nullable: false), + BossId = table.Column(type: "int", nullable: false), + ConfigurationId = table.Column(type: "int", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Receipts", x => x.Id); + table.ForeignKey( + name: "FK_Receipts_Bosses_BossId", + column: x => x.BossId, + principalTable: "Bosses", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + table.ForeignKey( + name: "FK_Receipts_Configurations_ConfigurationId", + column: x => x.ConfigurationId, + principalTable: "Configurations", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateTable( + name: "Presales", + columns: table => new + { + Id = table.Column(type: "int", nullable: false) + .Annotation("SqlServer:Identity", "1, 1"), + PresaleDate = table.Column(type: "datetime2", nullable: false), + EmployeeId = table.Column(type: "int", nullable: false), + TypeOfJobId = table.Column(type: "int", nullable: true) + }, + constraints: table => + { + table.PrimaryKey("PK_Presales", x => x.Id); + table.ForeignKey( + name: "FK_Presales_Employees_EmployeeId", + column: x => x.EmployeeId, + principalTable: "Employees", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + table.ForeignKey( + name: "FK_Presales_TypeOfJobs_TypeOfJobId", + column: x => x.TypeOfJobId, + principalTable: "TypeOfJobs", + principalColumn: "Id"); + }); + + migrationBuilder.CreateTable( + name: "TypeOfJobConfigurations", + columns: table => new + { + Id = table.Column(type: "int", nullable: false) + .Annotation("SqlServer:Identity", "1, 1"), + ConfigurationId = table.Column(type: "int", nullable: false), + TypeOfJobId = table.Column(type: "int", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_TypeOfJobConfigurations", x => x.Id); + table.ForeignKey( + name: "FK_TypeOfJobConfigurations_Configurations_ConfigurationId", + column: x => x.ConfigurationId, + principalTable: "Configurations", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + table.ForeignKey( + name: "FK_TypeOfJobConfigurations_TypeOfJobs_TypeOfJobId", + column: x => x.TypeOfJobId, + principalTable: "TypeOfJobs", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateTable( + name: "ConfigurationCars", + columns: table => new + { + Id = table.Column(type: "int", nullable: false) + .Annotation("SqlServer:Identity", "1, 1"), + ConfigurationId = table.Column(type: "int", nullable: false), + CarId = table.Column(type: "int", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_ConfigurationCars", x => x.Id); + table.ForeignKey( + name: "FK_ConfigurationCars_Cars_CarId", + column: x => x.CarId, + principalTable: "Cars", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + table.ForeignKey( + name: "FK_ConfigurationCars_Configurations_ConfigurationId", + column: x => x.ConfigurationId, + principalTable: "Configurations", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateTable( + name: "Sales", + columns: table => new + { + Id = table.Column(type: "int", nullable: false) + .Annotation("SqlServer:Identity", "1, 1"), + Sum = table.Column(type: "real", nullable: false), + SaleDateTime = table.Column(type: "datetime2", nullable: false), + CarId = table.Column(type: "int", nullable: false), + ReceiptId = table.Column(type: "int", nullable: false), + ConfigurationId = table.Column(type: "int", nullable: false), + EmployeeId = table.Column(type: "int", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Sales", x => x.Id); + table.ForeignKey( + name: "FK_Sales_Cars_CarId", + column: x => x.CarId, + principalTable: "Cars", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + table.ForeignKey( + name: "FK_Sales_Configurations_ConfigurationId", + column: x => x.ConfigurationId, + principalTable: "Configurations", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + table.ForeignKey( + name: "FK_Sales_Employees_EmployeeId", + column: x => x.EmployeeId, + principalTable: "Employees", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + table.ForeignKey( + name: "FK_Sales_Receipts_ReceiptId", + column: x => x.ReceiptId, + principalTable: "Receipts", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateTable( + name: "PresaleCars", + columns: table => new + { + Id = table.Column(type: "int", nullable: false) + .Annotation("SqlServer:Identity", "1, 1"), + PresaleId = table.Column(type: "int", nullable: false), + CarId = table.Column(type: "int", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_PresaleCars", x => x.Id); + table.ForeignKey( + name: "FK_PresaleCars_Cars_CarId", + column: x => x.CarId, + principalTable: "Cars", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + table.ForeignKey( + name: "FK_PresaleCars_Presales_PresaleId", + column: x => x.PresaleId, + principalTable: "Presales", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateIndex( + name: "IX_Cars_EmployeeId", + table: "Cars", + column: "EmployeeId"); + + migrationBuilder.CreateIndex( + name: "IX_ConfigurationCars_CarId", + table: "ConfigurationCars", + column: "CarId"); + + migrationBuilder.CreateIndex( + name: "IX_ConfigurationCars_ConfigurationId", + table: "ConfigurationCars", + column: "ConfigurationId"); + + migrationBuilder.CreateIndex( + name: "IX_Configurations_BossId", + table: "Configurations", + column: "BossId"); + + migrationBuilder.CreateIndex( + name: "IX_PresaleCars_CarId", + table: "PresaleCars", + column: "CarId"); + + migrationBuilder.CreateIndex( + name: "IX_PresaleCars_PresaleId", + table: "PresaleCars", + column: "PresaleId"); + + migrationBuilder.CreateIndex( + name: "IX_Presales_EmployeeId", + table: "Presales", + column: "EmployeeId"); + + migrationBuilder.CreateIndex( + name: "IX_Presales_TypeOfJobId", + table: "Presales", + column: "TypeOfJobId"); + + migrationBuilder.CreateIndex( + name: "IX_Receipts_BossId", + table: "Receipts", + column: "BossId"); + + migrationBuilder.CreateIndex( + name: "IX_Receipts_ConfigurationId", + table: "Receipts", + column: "ConfigurationId"); + + migrationBuilder.CreateIndex( + name: "IX_Sales_CarId", + table: "Sales", + column: "CarId"); + + migrationBuilder.CreateIndex( + name: "IX_Sales_ConfigurationId", + table: "Sales", + column: "ConfigurationId"); + + migrationBuilder.CreateIndex( + name: "IX_Sales_EmployeeId", + table: "Sales", + column: "EmployeeId"); + + migrationBuilder.CreateIndex( + name: "IX_Sales_ReceiptId", + table: "Sales", + column: "ReceiptId"); + + migrationBuilder.CreateIndex( + name: "IX_TypeOfJobConfigurations_ConfigurationId", + table: "TypeOfJobConfigurations", + column: "ConfigurationId"); + + migrationBuilder.CreateIndex( + name: "IX_TypeOfJobConfigurations_TypeOfJobId", + table: "TypeOfJobConfigurations", + column: "TypeOfJobId"); + + migrationBuilder.CreateIndex( + name: "IX_TypeOfJobs_BossId", + table: "TypeOfJobs", + column: "BossId"); + } + + /// + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropTable( + name: "ConfigurationCars"); + + migrationBuilder.DropTable( + name: "PresaleCars"); + + migrationBuilder.DropTable( + name: "Sales"); + + migrationBuilder.DropTable( + name: "TypeOfJobConfigurations"); + + migrationBuilder.DropTable( + name: "Presales"); + + migrationBuilder.DropTable( + name: "Cars"); + + migrationBuilder.DropTable( + name: "Receipts"); + + migrationBuilder.DropTable( + name: "TypeOfJobs"); + + migrationBuilder.DropTable( + name: "Employees"); + + migrationBuilder.DropTable( + name: "Configurations"); + + migrationBuilder.DropTable( + name: "Bosses"); + } + } +} diff --git a/CarCenter/CarCenterDatabaseImplement/Migrations/CarCenterDatabaseModelSnapshot.cs b/CarCenter/CarCenterDatabaseImplement/Migrations/CarCenterDatabaseModelSnapshot.cs new file mode 100644 index 0000000..538c0b7 --- /dev/null +++ b/CarCenter/CarCenterDatabaseImplement/Migrations/CarCenterDatabaseModelSnapshot.cs @@ -0,0 +1,498 @@ +// +using System; +using CarCenterDatabaseImplement; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Metadata; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; + +#nullable disable + +namespace CarCenterDatabaseImplement.Migrations +{ + [DbContext(typeof(CarCenterDatabase))] + partial class CarCenterDatabaseModelSnapshot : ModelSnapshot + { + protected override void BuildModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "7.0.4") + .HasAnnotation("Relational:MaxIdentifierLength", 128); + + SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder); + + modelBuilder.Entity("CarCenterDatabaseImplement.Models.Boss", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("Login") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Name") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Password") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Patronymic") + .HasColumnType("nvarchar(max)"); + + b.Property("Surname") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.HasKey("Id"); + + b.ToTable("Bosses"); + }); + + modelBuilder.Entity("CarCenterDatabaseImplement.Models.Car", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("EmployeeId") + .HasColumnType("int"); + + b.Property("Name") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.HasKey("Id"); + + b.HasIndex("EmployeeId"); + + b.ToTable("Cars"); + }); + + modelBuilder.Entity("CarCenterDatabaseImplement.Models.Configuration", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("BossId") + .HasColumnType("int"); + + b.Property("Name") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.HasKey("Id"); + + b.HasIndex("BossId"); + + b.ToTable("Configurations"); + }); + + modelBuilder.Entity("CarCenterDatabaseImplement.Models.ConfigurationCar", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("CarId") + .HasColumnType("int"); + + b.Property("ConfigurationId") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.HasIndex("CarId"); + + b.HasIndex("ConfigurationId"); + + b.ToTable("ConfigurationCars"); + }); + + modelBuilder.Entity("CarCenterDatabaseImplement.Models.Employee", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("Login") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Name") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Password") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Patronymic") + .HasColumnType("nvarchar(max)"); + + b.Property("Surname") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.HasKey("Id"); + + b.ToTable("Employees"); + }); + + modelBuilder.Entity("CarCenterDatabaseImplement.Models.Presale", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("EmployeeId") + .HasColumnType("int"); + + b.Property("PresaleDate") + .HasColumnType("datetime2"); + + b.Property("TypeOfJobId") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.HasIndex("EmployeeId"); + + b.HasIndex("TypeOfJobId"); + + b.ToTable("Presales"); + }); + + modelBuilder.Entity("CarCenterDatabaseImplement.Models.PresaleCar", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("CarId") + .HasColumnType("int"); + + b.Property("PresaleId") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.HasIndex("CarId"); + + b.HasIndex("PresaleId"); + + b.ToTable("PresaleCars"); + }); + + modelBuilder.Entity("CarCenterDatabaseImplement.Models.Receipt", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("BossId") + .HasColumnType("int"); + + b.Property("ConfigurationId") + .HasColumnType("int"); + + b.Property("ReceiptDate") + .HasColumnType("datetime2"); + + b.Property("Sum") + .HasColumnType("real"); + + b.HasKey("Id"); + + b.HasIndex("BossId"); + + b.HasIndex("ConfigurationId"); + + b.ToTable("Receipts"); + }); + + modelBuilder.Entity("CarCenterDatabaseImplement.Models.Sale", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("CarId") + .HasColumnType("int"); + + b.Property("ConfigurationId") + .HasColumnType("int"); + + b.Property("EmployeeId") + .HasColumnType("int"); + + b.Property("ReceiptId") + .HasColumnType("int"); + + b.Property("SaleDateTime") + .HasColumnType("datetime2"); + + b.Property("Sum") + .HasColumnType("real"); + + b.HasKey("Id"); + + b.HasIndex("CarId"); + + b.HasIndex("ConfigurationId"); + + b.HasIndex("EmployeeId"); + + b.HasIndex("ReceiptId"); + + b.ToTable("Sales"); + }); + + modelBuilder.Entity("CarCenterDatabaseImplement.Models.TypeOfJob", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("BossId") + .HasColumnType("int"); + + b.Property("Name") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.HasKey("Id"); + + b.HasIndex("BossId"); + + b.ToTable("TypeOfJobs"); + }); + + modelBuilder.Entity("CarCenterDatabaseImplement.Models.TypeOfJobConfiguration", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("ConfigurationId") + .HasColumnType("int"); + + b.Property("TypeOfJobId") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.HasIndex("ConfigurationId"); + + b.HasIndex("TypeOfJobId"); + + b.ToTable("TypeOfJobConfigurations"); + }); + + modelBuilder.Entity("CarCenterDatabaseImplement.Models.Car", b => + { + b.HasOne("CarCenterDatabaseImplement.Models.Employee", "Employee") + .WithMany() + .HasForeignKey("EmployeeId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Employee"); + }); + + modelBuilder.Entity("CarCenterDatabaseImplement.Models.Configuration", b => + { + b.HasOne("CarCenterDatabaseImplement.Models.Boss", "Boss") + .WithMany() + .HasForeignKey("BossId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Boss"); + }); + + modelBuilder.Entity("CarCenterDatabaseImplement.Models.ConfigurationCar", b => + { + b.HasOne("CarCenterDatabaseImplement.Models.Car", "Car") + .WithMany("Configurations") + .HasForeignKey("CarId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("CarCenterDatabaseImplement.Models.Configuration", "Configuration") + .WithMany() + .HasForeignKey("ConfigurationId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Car"); + + b.Navigation("Configuration"); + }); + + modelBuilder.Entity("CarCenterDatabaseImplement.Models.Presale", b => + { + b.HasOne("CarCenterDatabaseImplement.Models.Employee", "Employee") + .WithMany() + .HasForeignKey("EmployeeId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("CarCenterDatabaseImplement.Models.TypeOfJob", "TypeOfJob") + .WithMany() + .HasForeignKey("TypeOfJobId"); + + b.Navigation("Employee"); + + b.Navigation("TypeOfJob"); + }); + + modelBuilder.Entity("CarCenterDatabaseImplement.Models.PresaleCar", b => + { + b.HasOne("CarCenterDatabaseImplement.Models.Car", "Car") + .WithMany("Presales") + .HasForeignKey("CarId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("CarCenterDatabaseImplement.Models.Presale", "Presale") + .WithMany("PresaleCars") + .HasForeignKey("PresaleId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Car"); + + b.Navigation("Presale"); + }); + + modelBuilder.Entity("CarCenterDatabaseImplement.Models.Receipt", b => + { + b.HasOne("CarCenterDatabaseImplement.Models.Boss", "Boss") + .WithMany() + .HasForeignKey("BossId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("CarCenterDatabaseImplement.Models.Configuration", "Configuration") + .WithMany() + .HasForeignKey("ConfigurationId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Boss"); + + b.Navigation("Configuration"); + }); + + modelBuilder.Entity("CarCenterDatabaseImplement.Models.Sale", b => + { + b.HasOne("CarCenterDatabaseImplement.Models.Car", "Car") + .WithMany() + .HasForeignKey("CarId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("CarCenterDatabaseImplement.Models.Configuration", "Configuration") + .WithMany() + .HasForeignKey("ConfigurationId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("CarCenterDatabaseImplement.Models.Employee", "Employee") + .WithMany() + .HasForeignKey("EmployeeId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("CarCenterDatabaseImplement.Models.Receipt", "Receipt") + .WithMany() + .HasForeignKey("ReceiptId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Car"); + + b.Navigation("Configuration"); + + b.Navigation("Employee"); + + b.Navigation("Receipt"); + }); + + modelBuilder.Entity("CarCenterDatabaseImplement.Models.TypeOfJob", b => + { + b.HasOne("CarCenterDatabaseImplement.Models.Boss", "Boss") + .WithMany() + .HasForeignKey("BossId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Boss"); + }); + + modelBuilder.Entity("CarCenterDatabaseImplement.Models.TypeOfJobConfiguration", b => + { + b.HasOne("CarCenterDatabaseImplement.Models.Configuration", "Configuration") + .WithMany() + .HasForeignKey("ConfigurationId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("CarCenterDatabaseImplement.Models.TypeOfJob", "TypeOfJob") + .WithMany("Configurations") + .HasForeignKey("TypeOfJobId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Configuration"); + + b.Navigation("TypeOfJob"); + }); + + modelBuilder.Entity("CarCenterDatabaseImplement.Models.Car", b => + { + b.Navigation("Configurations"); + + b.Navigation("Presales"); + }); + + modelBuilder.Entity("CarCenterDatabaseImplement.Models.Presale", b => + { + b.Navigation("PresaleCars"); + }); + + modelBuilder.Entity("CarCenterDatabaseImplement.Models.TypeOfJob", b => + { + b.Navigation("Configurations"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/CarCenter/CarCenterDatabaseImplement/Models/Boss.cs b/CarCenter/CarCenterDatabaseImplement/Models/Boss.cs new file mode 100644 index 0000000..09db039 --- /dev/null +++ b/CarCenter/CarCenterDatabaseImplement/Models/Boss.cs @@ -0,0 +1,74 @@ +using CarCenterContracts.BindingModels; +using CarCenterContracts.ViewModels; +using CarCenterDataModels.Models; +using System; +using System.Collections.Generic; +using System.ComponentModel.DataAnnotations; +using System.Linq; +using System.Reflection; +using System.Text; +using System.Threading.Tasks; + +namespace CarCenterDatabaseImplement.Models +{ + public class Boss : IBossModel + { + public int Id { get; set; } + public string Login { get; set; } = string.Empty; + public string Password { get; set; } = string.Empty; + public string Name { get; set; } = string.Empty; + public string Surname { get; set; } = string.Empty; + public string? Patronymic {get; set; } + + public static Boss? Create(BossBindingModel model) + { + if (model == null) + { + return null; + } + return new Boss() + { + Id = model.Id, + Login = model.Login, + Password = model.Password, + Surname = model.Surname, + Name = model.Name, + Patronymic = model.Patronymic, + }; + } + public static Boss? Create(BossViewModel model) + { + return new Boss() + { + Id = model.Id, + Login = model.Login, + Password = model.Password, + Surname = model.Surname, + Name = model.Name, + Patronymic = model.Patronymic, + }; + } + public void Update(BossBindingModel? model) + { + if (model == null) + { + return; + } + Password = model.Password; + Login = model.Login; + Surname = model.Surname; + Name = model.Name; + Patronymic = model.Patronymic; + } + public BossViewModel GetViewModel => new() + { + Id = Id, + Login = Login, + Password = Password, + Surname = Surname, + Name = Name, + Patronymic = Patronymic, + }; + + } +} diff --git a/CarCenter/CarCenterDatabaseImplement/Models/Car.cs b/CarCenter/CarCenterDatabaseImplement/Models/Car.cs new file mode 100644 index 0000000..c77544f --- /dev/null +++ b/CarCenter/CarCenterDatabaseImplement/Models/Car.cs @@ -0,0 +1,134 @@ +using CarCenterContracts.BindingModels; +using CarCenterContracts.ViewModels; +using CarCenterDataModels.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 CarCenterDatabaseImplement.Models +{ + public class Car : ICarModel + { + public int Id { get; set; } + [Required] + public string Name { get; set; } + private Dictionary? _presaleCars = null; + [NotMapped] + public Dictionary PresaleCars { + get + { + if (_presaleCars == null) + { + _presaleCars = Presales.ToDictionary(recDP => recDP.PresaleId, recDP => recDP.Presale as IPresaleModel); + } + return _presaleCars; + } + } + [ForeignKey("CarId")] + public virtual List Presales { get; set; } = new(); + private Dictionary? _configurationCars = null; + [NotMapped] + public Dictionary ConfigurationCars + { + get + { + if (_configurationCars == null) + { + _configurationCars = Configurations.ToDictionary(recCP => recCP.ConfigurationId, recCP => recCP.Configuration as IConfigurationModel); + } + return _configurationCars; + } + } + public virtual List Configurations { get; set; } = new(); + + public int EmployeeId { get; set; } + public virtual Employee Employee { get; set; } = new(); + + public static Car? Create(CarCenterDatabase context, CarBindingModel model) + { + if (model == null) + { + return null; + } + return new Car() + { + Id = model.Id, + Configurations = model.ConfigurationCars.Select(x => new ConfigurationCar + { + Configuration = context.Configurations.First(y => y.Id == x.Key) + }).ToList(), + EmployeeId = model.EmployeeId, + Employee = context.Employees.First(x => x.Id == model.EmployeeId) + }; + } + public void Update(CarBindingModel? model) + { + if (model == null) + { + return; + } + Name = model.Name; + } + public CarViewModel GetViewModel => new() + { + Id = Id, + Name = Name, + PresaleCars = PresaleCars, + ConfigurationCars = ConfigurationCars, + EmployeeId = EmployeeId, + EmployeeName = Employee.Surname + " " + Employee.Name + " " + Employee.Patronymic, + }; + public void UpdatePresales(CarCenterDatabase context, CarBindingModel model) + { + var presaleCars = context.PresaleCars.Where(rec => rec.CarId == model.Id).ToList(); + if (presaleCars != null) + { + context.PresaleCars.RemoveRange(presaleCars.Where(rec => !model.PresaleCars.ContainsKey(rec.PresaleId))); + context.SaveChanges(); + var car = context.Cars.First(x => x.Id == Id); + foreach (var updatePresale in presaleCars) + { + model.PresaleCars.Remove(updatePresale.PresaleId); + } + foreach (var pc in model.PresaleCars) + { + context.PresaleCars.Add(new PresaleCar + { + Car = car, + Presale = context.Presales.First(x => x.Id == pc.Key), + }); + context.SaveChanges(); + } + _presaleCars = null; + } + } + public void UpdateConfigurations(CarCenterDatabase context, CarBindingModel model) + { + var configurationCars = context.ConfigurationCars.Where(rec => rec.CarId == model.Id).ToList(); + if (configurationCars != null && configurationCars.Count > 0) + { + context.ConfigurationCars.RemoveRange(configurationCars.Where(rec => !model.ConfigurationCars.ContainsKey(rec.ConfigurationId))); + context.SaveChanges(); + var car = context.Cars.First(x => x.Id == Id); + foreach (var updateConfiguration in configurationCars) + { + model.ConfigurationCars.Remove(updateConfiguration.ConfigurationId); + } + foreach (var cc in model.ConfigurationCars) + { + context.ConfigurationCars.Add(new ConfigurationCar + { + Car = car, + Configuration = context.Configurations.First(x => x.Id == cc.Key), + }); + context.SaveChanges(); + } + _configurationCars = null; + } + } + } +} diff --git a/CarCenter/CarCenterDatabaseImplement/Models/Configuration.cs b/CarCenter/CarCenterDatabaseImplement/Models/Configuration.cs new file mode 100644 index 0000000..4817b6f --- /dev/null +++ b/CarCenter/CarCenterDatabaseImplement/Models/Configuration.cs @@ -0,0 +1,61 @@ +using CarCenterDataModels.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.ComponentModel.DataAnnotations; +using System.ComponentModel.DataAnnotations.Schema; +using CarCenterContracts.BindingModels; +using CarCenterContracts.ViewModels; + +namespace CarCenterDatabaseImplement.Models +{ + public class Configuration : IConfigurationModel + { + public int Id { get; set; } + [Required] + public string Name { get; set; } + public int BossId { get; set; } + public virtual Boss Boss { get; set; } = new(); + public static Configuration? Create(CarCenterDatabase context, ConfigurationBindingModel model) + { + if (model == null) + { + return null; + } + return new Configuration() + { + Id = model.Id, + Name = model.Name, + BossId = model.BossId, + Boss = context.Bosses.First(x => x.Id == model.BossId), + }; + + } + public static Configuration? Create(CarCenterDatabase context, ConfigurationViewModel model) + { + return new Configuration() + { + Id = model.Id, + Name = model.Name, + BossId = model.BossId, + Boss = context.Bosses.First(x => x.Id == model.BossId), + }; + } + + public void Update(ConfigurationBindingModel? model) + { + if (model == null) + { + return; + } + Name = model.Name; + } + public ConfigurationViewModel GetViewModel => new() + { + Id = Id, + Name = Name, + }; + } +} diff --git a/CarCenter/CarCenterDatabaseImplement/Models/ConfigurationCar.cs b/CarCenter/CarCenterDatabaseImplement/Models/ConfigurationCar.cs new file mode 100644 index 0000000..c508ad6 --- /dev/null +++ b/CarCenter/CarCenterDatabaseImplement/Models/ConfigurationCar.cs @@ -0,0 +1,20 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel.DataAnnotations; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace CarCenterDatabaseImplement.Models +{ + public class ConfigurationCar + { + public int Id { get; set; } + [Required] + public int ConfigurationId { get; set; } + [Required] + public int CarId { get; set; } + public virtual Configuration Configuration { get; set; } = new(); + public virtual Car Car { get; set; } = new(); + } +} diff --git a/CarCenter/CarCenterDatabaseImplement/Models/Employee.cs b/CarCenter/CarCenterDatabaseImplement/Models/Employee.cs new file mode 100644 index 0000000..f2744ff --- /dev/null +++ b/CarCenter/CarCenterDatabaseImplement/Models/Employee.cs @@ -0,0 +1,73 @@ +using CarCenterContracts.BindingModels; +using CarCenterContracts.ViewModels; +using CarCenterDataModels.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace CarCenterDatabaseImplement.Models +{ + public class Employee : IEmployeeModel + { + public int Id { get; set; } + public string Login {get; set;} = string.Empty; + + public string Password { get; set; } = string.Empty; + + public string Surname { get; set; } = string.Empty; + + public string Name { get; set; } = string.Empty; + + public string? Patronymic { get; set; } + public static Employee? Create(EmployeeBindingModel model) + { + if (model == null) + { + return null; + } + return new Employee() + { + Id = model.Id, + Login = model.Login, + Password = model.Password, + Surname = model.Surname, + Name = model.Name, + Patronymic = model.Patronymic, + }; + } + public static Employee? Create(EmployeeViewModel model) + { + return new Employee() + { + Id = model.Id, + Login = model.Login, + Password = model.Password, + Surname = model.Surname, + Name = model.Name, + Patronymic = model.Patronymic, + }; + } + public void Update(EmployeeBindingModel? model) + { + if (model == null) + { + return; + } + Password = model.Password; + Surname = model.Surname; + Name = model.Name; + Patronymic = model.Patronymic; + } + public EmployeeViewModel GetViewModel => new() + { + Id = Id, + Login = Login, + Password = Password, + Surname = Surname, + Name = Name, + Patronymic = Patronymic, + }; + } +} diff --git a/CarCenter/CarCenterDatabaseImplement/Models/Presale.cs b/CarCenter/CarCenterDatabaseImplement/Models/Presale.cs new file mode 100644 index 0000000..8d10773 --- /dev/null +++ b/CarCenter/CarCenterDatabaseImplement/Models/Presale.cs @@ -0,0 +1,67 @@ +using CarCenterContracts.BindingModels; +using CarCenterContracts.ViewModels; +using CarCenterDataModels.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 CarCenterDatabaseImplement.Models +{ + public class Presale : IPresaleModel + { + public int Id { get; set; } + [Required] + public DateTime PresaleDate { get; set; } = DateTime.Now; + [Required] + public int EmployeeId { get; set; } + public virtual Employee Employee { get; set; } = new(); + public int? TypeOfJobId {get; set; } + public virtual TypeOfJob? TypeOfJob { get; set; } + [ForeignKey("PresaleId")] + public virtual List PresaleCars { get; set; } = new(); + public static Presale? Create(CarCenterDatabase context, PresaleBindingModel model) + { + if (model == null) + { + return null; + } + return new Presale() + { + Id = model.Id, + PresaleDate = model.PresaleDate, + EmployeeId = model.EmployeeId, + Employee = context.Employees.First(x => x.Id == model.EmployeeId) + }; + } + public static Presale? Create(CarCenterDatabase context, PresaleViewModel model) + { + return new Presale() + { + Id = model.Id, + PresaleDate = model.PresaleDate, + EmployeeId = model.EmployeeId, + Employee = context.Employees.First(x => x.Id == model.EmployeeId) + }; + } + public void Update(PresaleBindingModel? model) + { + if (model == null) + { + return; + } + if (model.TypeOfJobId.HasValue) TypeOfJobId = TypeOfJobId; + } + public PresaleViewModel GetViewModel => new() + { + Id = Id, + TypeOfJobId = TypeOfJobId, + PresaleDate = PresaleDate, + EmployeeId = EmployeeId, + EmployeeName = Employee.Surname + " " + Employee.Name + " " + Employee.Patronymic, + }; + } +} diff --git a/CarCenter/CarCenterDatabaseImplement/Models/PresaleCar.cs b/CarCenter/CarCenterDatabaseImplement/Models/PresaleCar.cs new file mode 100644 index 0000000..0044dc4 --- /dev/null +++ b/CarCenter/CarCenterDatabaseImplement/Models/PresaleCar.cs @@ -0,0 +1,20 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel.DataAnnotations; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace CarCenterDatabaseImplement.Models +{ + public class PresaleCar + { + public int Id { get; set; } + [Required] + public int PresaleId { get; set; } + [Required] + public int CarId { get; set; } + public virtual Presale Presale { get; set; } = new(); + public virtual Car Car { get; set; } = new(); + } +} diff --git a/CarCenter/CarCenterDatabaseImplement/Models/Receipt.cs b/CarCenter/CarCenterDatabaseImplement/Models/Receipt.cs new file mode 100644 index 0000000..0aa5cf4 --- /dev/null +++ b/CarCenter/CarCenterDatabaseImplement/Models/Receipt.cs @@ -0,0 +1,76 @@ +using CarCenterContracts.BindingModels; +using CarCenterContracts.ViewModels; +using CarCenterDataModels.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 CarCenterDatabaseImplement.Models +{ + public class Receipt : IReceiptModel + { + public int Id { get; set; } + [Required] + public float Sum { get; set; } + [Required] + public DateTime ReceiptDate { get; set; } = DateTime.Now; + [Required] + public int BossId { get; set; } + public virtual Boss Boss { get; set; } = new(); + public int ConfigurationId { get; set; } + public virtual Configuration Configuration { get; set; } = new(); + + public static Receipt? Create(CarCenterDatabase context, ReceiptBindingModel model) + { + if (model == null) + { + return null; + } + return new Receipt() + { + Id = model.Id, + Sum = model.Sum, + ReceiptDate = model.ReceiptDate, + BossId = model.BossId, + Boss = context.Bosses.First(x => x.Id == model.BossId), + ConfigurationId = model.ConfigurationId, + Configuration = context.Configurations.First(x => x.Id == model.ConfigurationId), + }; + } + public static Receipt? Create(CarCenterDatabase context, ReceiptViewModel model) + { + return new Receipt() + { + Id = model.Id, + Sum = model.Sum, + ReceiptDate = model.ReceiptDate, + BossId = model.BossId, + Boss = context.Bosses.First(x => x.Id == model.BossId), + ConfigurationId = model.ConfigurationId, + Configuration = context.Configurations.First(x => x.Id == model.ConfigurationId), + }; + } + public void Update(ReceiptBindingModel? model) + { + if (model == null) + { + return; + } + ReceiptDate = model.ReceiptDate; + } + public ReceiptViewModel GetViewModel => new() + { + Id = Id, + Sum = Sum, + ReceiptDate = ReceiptDate, + BossId = BossId, + BossName = Boss.Surname + " " + Boss.Name + " " + Boss.Patronymic, + ConfigurationId = ConfigurationId, + ConfigurationName = Configuration.Name, + }; + } +} diff --git a/CarCenter/CarCenterDatabaseImplement/Models/Sale.cs b/CarCenter/CarCenterDatabaseImplement/Models/Sale.cs new file mode 100644 index 0000000..9165ff7 --- /dev/null +++ b/CarCenter/CarCenterDatabaseImplement/Models/Sale.cs @@ -0,0 +1,83 @@ +using CarCenterContracts.BindingModels; +using CarCenterContracts.ViewModels; +using CarCenterDataModels.Models; +using System; +using System.Collections.Generic; +using System.ComponentModel.DataAnnotations; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace CarCenterDatabaseImplement.Models +{ + public class Sale : ISaleModel + { + public int Id {get; set;} + [Required] + public float Sum { get; set; } + [Required] + public DateTime SaleDateTime { get; set; } = DateTime.Now; + [Required] + public int CarId { get; set; } + public virtual Car Car { get; set; } = new(); + public int ReceiptId { get; set; } + public virtual Receipt Receipt { get; set; } = new(); + public int ConfigurationId { get; set; } + public virtual Configuration Configuration { get; set; } = new(); + public int EmployeeId { get; set; } + public virtual Employee Employee { get; set; } = new(); + public static Sale? Create(CarCenterDatabase context, SaleBindingModel model) + { + if (model == null) + { + return null; + } + return new Sale() + { + Id = model.Id, + Sum = model.Sum, + SaleDateTime = model.SaleDateTime, + CarId = model.CarId, + Car = context.Cars.First(x => x.Id == model.CarId), + ReceiptId = model.ReceiptId, + Receipt = context.Receipts.First(x => x.Id == model.ReceiptId), + ConfigurationId = model.ConfigurationId, + Configuration = context.Configurations.First(x => x.Id == model.ConfigurationId), + EmployeeId = model.EmployeeId, + Employee = context.Employees.First(x => x.Id == model.EmployeeId) + }; + } + public static Sale? Create(CarCenterDatabase context, SaleViewModel model) + { + return new Sale() + { + Id = model.Id, + Sum = model.Sum, + SaleDateTime = model.SaleDateTime, + CarId = model.CarId, + Car = context.Cars.First(x => x.Id == model.CarId), + ReceiptId = model.ReceiptId, + Receipt = context.Receipts.First(x => x.Id == model.ReceiptId), + ConfigurationId = model.ConfigurationId, + Configuration = context.Configurations.First(x => x.Id == model.ConfigurationId) + }; + } + public void Update(SaleBindingModel? model) + { + if (model == null) + { + return; + } + Sum = model.Sum; + } + public SaleViewModel GetViewModel => new() + { + Id = Id, + SaleDateTime = SaleDateTime, + Sum = Sum, + CarId = CarId, + EmployeeId = EmployeeId, + EmployeeName = Employee.Surname + " " + Employee.Name + " " + Employee.Patronymic, + }; + } +} diff --git a/CarCenter/CarCenterDatabaseImplement/Models/TypeOfJob.cs b/CarCenter/CarCenterDatabaseImplement/Models/TypeOfJob.cs new file mode 100644 index 0000000..cc7ac8f --- /dev/null +++ b/CarCenter/CarCenterDatabaseImplement/Models/TypeOfJob.cs @@ -0,0 +1,95 @@ +using CarCenterContracts.BindingModels; +using CarCenterContracts.ViewModels; +using CarCenterDataModels.Models; +using System; +using System.Collections.Generic; +using System.ComponentModel.DataAnnotations.Schema; +using System.ComponentModel.DataAnnotations; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace CarCenterDatabaseImplement.Models +{ + public class TypeOfJob : ITypeOfJobModel + { + public int Id { get; set; } + [Required] + public string Name { get; set; } + public int BossId { get; set; } + public virtual Boss Boss { get; set; } = new(); + + private Dictionary? _typeOfJobConfigurations = null; + [NotMapped] + public Dictionary TypeOfJobConfigurations + { + get + { + if (_typeOfJobConfigurations == null) + { + _typeOfJobConfigurations = Configurations.ToDictionary(recDP => recDP.ConfigurationId, recDP => recDP.Configuration as IConfigurationModel); + } + return _typeOfJobConfigurations; + } + } + [ForeignKey("TypeOfJobId")] + public virtual List Configurations { get; set; } = new(); + + public static TypeOfJob? Create(CarCenterDatabase context, TypeOfJobBindingModel model) + { + if (model == null) + { + return null; + } + return new TypeOfJob() + { + Id = model.Id, + Name = model.Name, + Configurations = model.TypeOfJobConfigurations.Select(x => new TypeOfJobConfiguration + { + Configuration = context.Configurations.First(y => y.Id == x.Key) + }).ToList(), + BossId = model.BossId, + Boss = context.Bosses.First(x => x.Id == model.BossId), + }; + } + public void Update(TypeOfJobBindingModel? model) + { + if (model == null) + { + return; + } + Name = model.Name; + } + public TypeOfJobViewModel GetViewModel => new() + { + Id = Id, + Name = Name, + TypeOfJobConfigurations = TypeOfJobConfigurations, + }; + public void UpdateConfigurations(CarCenterDatabase context, TypeOfJobBindingModel model) + { + var typeOfJobConfigurations = context.TypeOfJobConfigurations.Where(rec => rec.TypeOfJobId == model.Id).ToList(); + if (typeOfJobConfigurations != null && typeOfJobConfigurations.Count > 0) + { + context.TypeOfJobConfigurations.RemoveRange(typeOfJobConfigurations.Where(rec => !model.TypeOfJobConfigurations.ContainsKey(rec.TypeOfJobId))); + context.SaveChanges(); + var typeOfJob = context.TypeOfJobs.First(x => x.Id == Id); + foreach (var updateConfiguration in typeOfJobConfigurations) + { + model.TypeOfJobConfigurations.Remove(updateConfiguration.ConfigurationId); + } + foreach (var dp in model.TypeOfJobConfigurations) + { + context.TypeOfJobConfigurations.Add(new TypeOfJobConfiguration + { + TypeOfJob = typeOfJob, + Configuration = context.Configurations.First(x => x.Id == dp.Key), + }); + context.SaveChanges(); + } + _typeOfJobConfigurations = null; + } + } + } +} diff --git a/CarCenter/CarCenterDatabaseImplement/Models/TypeOfJobConfiguration.cs b/CarCenter/CarCenterDatabaseImplement/Models/TypeOfJobConfiguration.cs new file mode 100644 index 0000000..e7f8db8 --- /dev/null +++ b/CarCenter/CarCenterDatabaseImplement/Models/TypeOfJobConfiguration.cs @@ -0,0 +1,20 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel.DataAnnotations; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace CarCenterDatabaseImplement.Models +{ + public class TypeOfJobConfiguration + { + public int Id { get; set; } + [Required] + public int ConfigurationId { get; set; } + [Required] + public int TypeOfJobId { get; set; } + public virtual Configuration Configuration { get; set; } = new(); + public virtual TypeOfJob TypeOfJob { get; set; } = new(); + } +} diff --git a/CarCenter/CarCenterView/CarCenterView.csproj b/CarCenter/CarCenterView/CarCenterView.csproj new file mode 100644 index 0000000..661fd7c --- /dev/null +++ b/CarCenter/CarCenterView/CarCenterView.csproj @@ -0,0 +1,22 @@ + + + + WinExe + net6.0-windows + enable + true + enable + + + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + + + + + + + \ No newline at end of file diff --git a/CarCenter/CarCenterView/Form1.Designer.cs b/CarCenter/CarCenterView/Form1.Designer.cs new file mode 100644 index 0000000..0ab5402 --- /dev/null +++ b/CarCenter/CarCenterView/Form1.Designer.cs @@ -0,0 +1,39 @@ +namespace CarCenterView +{ + partial class Form1 + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + this.components = new System.ComponentModel.Container(); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(800, 450); + this.Text = "Form1"; + } + + #endregion + } +} \ No newline at end of file diff --git a/CarCenter/CarCenterView/Form1.cs b/CarCenter/CarCenterView/Form1.cs new file mode 100644 index 0000000..b0b401e --- /dev/null +++ b/CarCenter/CarCenterView/Form1.cs @@ -0,0 +1,10 @@ +namespace CarCenterView +{ + public partial class Form1 : Form + { + public Form1() + { + InitializeComponent(); + } + } +} \ No newline at end of file diff --git a/CarCenter/CarCenterView/Form1.resx b/CarCenter/CarCenterView/Form1.resx new file mode 100644 index 0000000..1af7de1 --- /dev/null +++ b/CarCenter/CarCenterView/Form1.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/CarCenter/CarCenterView/Program.cs b/CarCenter/CarCenterView/Program.cs new file mode 100644 index 0000000..07b7e63 --- /dev/null +++ b/CarCenter/CarCenterView/Program.cs @@ -0,0 +1,17 @@ +namespace CarCenterView +{ + internal static class Program + { + /// + /// The main entry point for the application. + /// + [STAThread] + static void Main() + { + // To customize application configuration such as set high DPI settings or default font, + // see https://aka.ms/applicationconfiguration. + ApplicationConfiguration.Initialize(); + Application.Run(new Form1()); + } + } +} \ No newline at end of file