хранение данных

This commit is contained in:
Марат Заргаров 2023-04-09 13:59:29 +04:00
parent effd31dcb8
commit d192a45112
39 changed files with 3227 additions and 8 deletions

View File

@ -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

View File

@ -12,9 +12,9 @@ namespace CarCenterContracts.BindingModels
public String Name { get; set; }
public int Id { get; set; }
public Dictionary<int, IPresaleModel> CarPresales { get; set; } = new();
public Dictionary<int, IPresaleModel> PresaleCars { get; set; } = new();
public Dictionary<int, IConfigurationModel> CarConfigurations { get; set; } = new();
public Dictionary<int, IConfigurationModel> ConfigurationCars { get; set; } = new();
public int EmployeeId { get; set; }
}

View File

@ -13,6 +13,8 @@ namespace CarCenterContracts.BindingModels
public DateTime PresaleDate { get; set; } = DateTime.Now;
public int? TypeOfJobId { get; set; }
public int Id { get; set; }
}
}

View File

@ -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; }
}
}

View File

@ -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; }
}
}

View File

@ -15,8 +15,8 @@ namespace CarCenterContracts.ViewModels
[DisplayName("Название машины")]
public String Name { get; set; }
public Dictionary<int, IPresaleModel> CarPresales { get; set; } = new();
public Dictionary<int, IConfigurationModel> CarConfigurations { get; set; } = new();
public Dictionary<int, IPresaleModel> PresaleCars { get; set; } = new();
public Dictionary<int, IConfigurationModel> ConfigurationCars { get; set; } = new();
public int EmployeeId { get; set; }
[DisplayName("ФИО работника")]
public string EmployeeName { get; set; } = string.Empty;

View File

@ -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;}

View File

@ -6,4 +6,11 @@
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="7.0.4">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
</ItemGroup>
</Project>

View File

@ -9,8 +9,8 @@ namespace CarCenterDataModels.Models
public interface ICarModel : IId
{
string Name { get; }
Dictionary<int, IPresaleModel> CarPresales { get; }
Dictionary<int, IConfigurationModel> CarConfigurations { get; }
Dictionary<int, IPresaleModel> PresaleCars { get; }
Dictionary<int, IConfigurationModel> ConfigurationCars { get; }
int EmployeeId { get; }
}
}

View File

@ -10,5 +10,6 @@ namespace CarCenterDataModels.Models
{
DateTime PresaleDate { get; }
int EmployeeId { get; }
int? TypeOfJobId { get; }
}
}

View File

@ -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<Employee> Employees { set; get; }
public virtual DbSet<Presale> Presales { set; get; }
public virtual DbSet<Car> Cars { set; get; }
public virtual DbSet<Sale> Sales { set; get; }
public virtual DbSet<PresaleCar> PresaleCars { set; get; }
public virtual DbSet<ConfigurationCar> ConfigurationCars { set; get; }
public virtual DbSet<Configuration> Configurations { set; get; }
public virtual DbSet<Boss> Bosses { set; get; }
public virtual DbSet<TypeOfJob> TypeOfJobs { set; get; }
public virtual DbSet<Receipt> Receipts { set; get; }
public virtual DbSet<TypeOfJobConfiguration> TypeOfJobConfigurations { set; get; }
}
}

View File

@ -0,0 +1,22 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="7.0.4" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="7.0.4" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="7.0.4">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\CarCenterContracts\CarCenterContracts.csproj" />
</ItemGroup>
</Project>

View File

@ -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<BossViewModel> 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<BossViewModel> 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;
}
}
}

View File

@ -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<CarViewModel> GetFullList()
{
using var context = new CarCenterDatabase();
return context.Cars.Include(x => x.Employee)
.Select(x => x.GetViewModel)
.ToList();
}
public List<CarViewModel> 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;
}
}
}

View File

@ -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<ConfigurationViewModel> 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<ConfigurationViewModel> 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;
}
}
}

View File

@ -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<EmployeeViewModel> GetFullList()
{
using var context = new CarCenterDatabase();
return context.Employees
.Select(x => x.GetViewModel)
.ToList();
}
public List<EmployeeViewModel> 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;
}
}
}

View File

@ -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<PresaleViewModel> GetFullList()
{
using var context = new CarCenterDatabase();
return context.Presales.Include(x => x.Employee).Include(x => x.TypeOfJob)
.Select(x => x.GetViewModel)
.ToList();
}
public List<PresaleViewModel> 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;
}
}
}

View File

@ -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<ReceiptViewModel> 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<ReceiptViewModel> 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;
}
}
}

View File

@ -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<SaleViewModel> 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<SaleViewModel> 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;
}
}
}

View File

@ -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<TypeOfJobViewModel> 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<TypeOfJobViewModel> 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;
}
}
}

View File

@ -0,0 +1,501 @@
// <auto-generated />
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
{
/// <inheritdoc />
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<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<string>("Login")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<string>("Name")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<string>("Password")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<string>("Patronymic")
.HasColumnType("nvarchar(max)");
b.Property<string>("Surname")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.HasKey("Id");
b.ToTable("Bosses");
});
modelBuilder.Entity("CarCenterDatabaseImplement.Models.Car", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<int>("EmployeeId")
.HasColumnType("int");
b.Property<string>("Name")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.HasKey("Id");
b.HasIndex("EmployeeId");
b.ToTable("Cars");
});
modelBuilder.Entity("CarCenterDatabaseImplement.Models.Configuration", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<int>("BossId")
.HasColumnType("int");
b.Property<string>("Name")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.HasKey("Id");
b.HasIndex("BossId");
b.ToTable("Configurations");
});
modelBuilder.Entity("CarCenterDatabaseImplement.Models.ConfigurationCar", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<int>("CarId")
.HasColumnType("int");
b.Property<int>("ConfigurationId")
.HasColumnType("int");
b.HasKey("Id");
b.HasIndex("CarId");
b.HasIndex("ConfigurationId");
b.ToTable("ConfigurationCars");
});
modelBuilder.Entity("CarCenterDatabaseImplement.Models.Employee", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<string>("Login")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<string>("Name")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<string>("Password")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<string>("Patronymic")
.HasColumnType("nvarchar(max)");
b.Property<string>("Surname")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.HasKey("Id");
b.ToTable("Employees");
});
modelBuilder.Entity("CarCenterDatabaseImplement.Models.Presale", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<int>("EmployeeId")
.HasColumnType("int");
b.Property<DateTime>("PresaleDate")
.HasColumnType("datetime2");
b.Property<int?>("TypeOfJobId")
.HasColumnType("int");
b.HasKey("Id");
b.HasIndex("EmployeeId");
b.HasIndex("TypeOfJobId");
b.ToTable("Presales");
});
modelBuilder.Entity("CarCenterDatabaseImplement.Models.PresaleCar", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<int>("CarId")
.HasColumnType("int");
b.Property<int>("PresaleId")
.HasColumnType("int");
b.HasKey("Id");
b.HasIndex("CarId");
b.HasIndex("PresaleId");
b.ToTable("PresaleCars");
});
modelBuilder.Entity("CarCenterDatabaseImplement.Models.Receipt", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<int>("BossId")
.HasColumnType("int");
b.Property<int>("ConfigurationId")
.HasColumnType("int");
b.Property<DateTime>("ReceiptDate")
.HasColumnType("datetime2");
b.Property<float>("Sum")
.HasColumnType("real");
b.HasKey("Id");
b.HasIndex("BossId");
b.HasIndex("ConfigurationId");
b.ToTable("Receipts");
});
modelBuilder.Entity("CarCenterDatabaseImplement.Models.Sale", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<int>("CarId")
.HasColumnType("int");
b.Property<int>("ConfigurationId")
.HasColumnType("int");
b.Property<int>("EmployeeId")
.HasColumnType("int");
b.Property<int>("ReceiptId")
.HasColumnType("int");
b.Property<DateTime>("SaleDateTime")
.HasColumnType("datetime2");
b.Property<float>("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<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<int>("BossId")
.HasColumnType("int");
b.Property<string>("Name")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.HasKey("Id");
b.HasIndex("BossId");
b.ToTable("TypeOfJobs");
});
modelBuilder.Entity("CarCenterDatabaseImplement.Models.TypeOfJobConfiguration", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<int>("ConfigurationId")
.HasColumnType("int");
b.Property<int>("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
}
}
}

View File

@ -0,0 +1,405 @@
using System;
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace CarCenterDatabaseImplement.Migrations
{
/// <inheritdoc />
public partial class InitialCreate : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.CreateTable(
name: "Bosses",
columns: table => new
{
Id = table.Column<int>(type: "int", nullable: false)
.Annotation("SqlServer:Identity", "1, 1"),
Login = table.Column<string>(type: "nvarchar(max)", nullable: false),
Password = table.Column<string>(type: "nvarchar(max)", nullable: false),
Name = table.Column<string>(type: "nvarchar(max)", nullable: false),
Surname = table.Column<string>(type: "nvarchar(max)", nullable: false),
Patronymic = table.Column<string>(type: "nvarchar(max)", nullable: true)
},
constraints: table =>
{
table.PrimaryKey("PK_Bosses", x => x.Id);
});
migrationBuilder.CreateTable(
name: "Employees",
columns: table => new
{
Id = table.Column<int>(type: "int", nullable: false)
.Annotation("SqlServer:Identity", "1, 1"),
Login = table.Column<string>(type: "nvarchar(max)", nullable: false),
Password = table.Column<string>(type: "nvarchar(max)", nullable: false),
Surname = table.Column<string>(type: "nvarchar(max)", nullable: false),
Name = table.Column<string>(type: "nvarchar(max)", nullable: false),
Patronymic = table.Column<string>(type: "nvarchar(max)", nullable: true)
},
constraints: table =>
{
table.PrimaryKey("PK_Employees", x => x.Id);
});
migrationBuilder.CreateTable(
name: "Configurations",
columns: table => new
{
Id = table.Column<int>(type: "int", nullable: false)
.Annotation("SqlServer:Identity", "1, 1"),
Name = table.Column<string>(type: "nvarchar(max)", nullable: false),
BossId = table.Column<int>(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<int>(type: "int", nullable: false)
.Annotation("SqlServer:Identity", "1, 1"),
Name = table.Column<string>(type: "nvarchar(max)", nullable: false),
BossId = table.Column<int>(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<int>(type: "int", nullable: false)
.Annotation("SqlServer:Identity", "1, 1"),
Name = table.Column<string>(type: "nvarchar(max)", nullable: false),
EmployeeId = table.Column<int>(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<int>(type: "int", nullable: false)
.Annotation("SqlServer:Identity", "1, 1"),
Sum = table.Column<float>(type: "real", nullable: false),
ReceiptDate = table.Column<DateTime>(type: "datetime2", nullable: false),
BossId = table.Column<int>(type: "int", nullable: false),
ConfigurationId = table.Column<int>(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<int>(type: "int", nullable: false)
.Annotation("SqlServer:Identity", "1, 1"),
PresaleDate = table.Column<DateTime>(type: "datetime2", nullable: false),
EmployeeId = table.Column<int>(type: "int", nullable: false),
TypeOfJobId = table.Column<int>(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<int>(type: "int", nullable: false)
.Annotation("SqlServer:Identity", "1, 1"),
ConfigurationId = table.Column<int>(type: "int", nullable: false),
TypeOfJobId = table.Column<int>(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<int>(type: "int", nullable: false)
.Annotation("SqlServer:Identity", "1, 1"),
ConfigurationId = table.Column<int>(type: "int", nullable: false),
CarId = table.Column<int>(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<int>(type: "int", nullable: false)
.Annotation("SqlServer:Identity", "1, 1"),
Sum = table.Column<float>(type: "real", nullable: false),
SaleDateTime = table.Column<DateTime>(type: "datetime2", nullable: false),
CarId = table.Column<int>(type: "int", nullable: false),
ReceiptId = table.Column<int>(type: "int", nullable: false),
ConfigurationId = table.Column<int>(type: "int", nullable: false),
EmployeeId = table.Column<int>(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<int>(type: "int", nullable: false)
.Annotation("SqlServer:Identity", "1, 1"),
PresaleId = table.Column<int>(type: "int", nullable: false),
CarId = table.Column<int>(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");
}
/// <inheritdoc />
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");
}
}
}

View File

@ -0,0 +1,498 @@
// <auto-generated />
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<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<string>("Login")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<string>("Name")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<string>("Password")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<string>("Patronymic")
.HasColumnType("nvarchar(max)");
b.Property<string>("Surname")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.HasKey("Id");
b.ToTable("Bosses");
});
modelBuilder.Entity("CarCenterDatabaseImplement.Models.Car", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<int>("EmployeeId")
.HasColumnType("int");
b.Property<string>("Name")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.HasKey("Id");
b.HasIndex("EmployeeId");
b.ToTable("Cars");
});
modelBuilder.Entity("CarCenterDatabaseImplement.Models.Configuration", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<int>("BossId")
.HasColumnType("int");
b.Property<string>("Name")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.HasKey("Id");
b.HasIndex("BossId");
b.ToTable("Configurations");
});
modelBuilder.Entity("CarCenterDatabaseImplement.Models.ConfigurationCar", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<int>("CarId")
.HasColumnType("int");
b.Property<int>("ConfigurationId")
.HasColumnType("int");
b.HasKey("Id");
b.HasIndex("CarId");
b.HasIndex("ConfigurationId");
b.ToTable("ConfigurationCars");
});
modelBuilder.Entity("CarCenterDatabaseImplement.Models.Employee", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<string>("Login")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<string>("Name")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<string>("Password")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<string>("Patronymic")
.HasColumnType("nvarchar(max)");
b.Property<string>("Surname")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.HasKey("Id");
b.ToTable("Employees");
});
modelBuilder.Entity("CarCenterDatabaseImplement.Models.Presale", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<int>("EmployeeId")
.HasColumnType("int");
b.Property<DateTime>("PresaleDate")
.HasColumnType("datetime2");
b.Property<int?>("TypeOfJobId")
.HasColumnType("int");
b.HasKey("Id");
b.HasIndex("EmployeeId");
b.HasIndex("TypeOfJobId");
b.ToTable("Presales");
});
modelBuilder.Entity("CarCenterDatabaseImplement.Models.PresaleCar", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<int>("CarId")
.HasColumnType("int");
b.Property<int>("PresaleId")
.HasColumnType("int");
b.HasKey("Id");
b.HasIndex("CarId");
b.HasIndex("PresaleId");
b.ToTable("PresaleCars");
});
modelBuilder.Entity("CarCenterDatabaseImplement.Models.Receipt", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<int>("BossId")
.HasColumnType("int");
b.Property<int>("ConfigurationId")
.HasColumnType("int");
b.Property<DateTime>("ReceiptDate")
.HasColumnType("datetime2");
b.Property<float>("Sum")
.HasColumnType("real");
b.HasKey("Id");
b.HasIndex("BossId");
b.HasIndex("ConfigurationId");
b.ToTable("Receipts");
});
modelBuilder.Entity("CarCenterDatabaseImplement.Models.Sale", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<int>("CarId")
.HasColumnType("int");
b.Property<int>("ConfigurationId")
.HasColumnType("int");
b.Property<int>("EmployeeId")
.HasColumnType("int");
b.Property<int>("ReceiptId")
.HasColumnType("int");
b.Property<DateTime>("SaleDateTime")
.HasColumnType("datetime2");
b.Property<float>("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<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<int>("BossId")
.HasColumnType("int");
b.Property<string>("Name")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.HasKey("Id");
b.HasIndex("BossId");
b.ToTable("TypeOfJobs");
});
modelBuilder.Entity("CarCenterDatabaseImplement.Models.TypeOfJobConfiguration", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<int>("ConfigurationId")
.HasColumnType("int");
b.Property<int>("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
}
}
}

View File

@ -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,
};
}
}

View File

@ -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<int, IPresaleModel>? _presaleCars = null;
[NotMapped]
public Dictionary<int, IPresaleModel> PresaleCars {
get
{
if (_presaleCars == null)
{
_presaleCars = Presales.ToDictionary(recDP => recDP.PresaleId, recDP => recDP.Presale as IPresaleModel);
}
return _presaleCars;
}
}
[ForeignKey("CarId")]
public virtual List<PresaleCar> Presales { get; set; } = new();
private Dictionary<int, IConfigurationModel>? _configurationCars = null;
[NotMapped]
public Dictionary<int, IConfigurationModel> ConfigurationCars
{
get
{
if (_configurationCars == null)
{
_configurationCars = Configurations.ToDictionary(recCP => recCP.ConfigurationId, recCP => recCP.Configuration as IConfigurationModel);
}
return _configurationCars;
}
}
public virtual List<ConfigurationCar> 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;
}
}
}
}

View File

@ -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,
};
}
}

View File

@ -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();
}
}

View File

@ -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,
};
}
}

View File

@ -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<PresaleCar> 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,
};
}
}

View File

@ -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();
}
}

View File

@ -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,
};
}
}

View File

@ -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,
};
}
}

View File

@ -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<int, IConfigurationModel>? _typeOfJobConfigurations = null;
[NotMapped]
public Dictionary<int, IConfigurationModel> TypeOfJobConfigurations
{
get
{
if (_typeOfJobConfigurations == null)
{
_typeOfJobConfigurations = Configurations.ToDictionary(recDP => recDP.ConfigurationId, recDP => recDP.Configuration as IConfigurationModel);
}
return _typeOfJobConfigurations;
}
}
[ForeignKey("TypeOfJobId")]
public virtual List<TypeOfJobConfiguration> 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;
}
}
}
}

View File

@ -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();
}
}

View File

@ -0,0 +1,22 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>WinExe</OutputType>
<TargetFramework>net6.0-windows</TargetFramework>
<Nullable>enable</Nullable>
<UseWindowsForms>true</UseWindowsForms>
<ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="7.0.4">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\CarCenterDatabaseImplement\CarCenterDatabaseImplement.csproj" />
</ItemGroup>
</Project>

View File

@ -0,0 +1,39 @@
namespace CarCenterView
{
partial class Form1
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
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
}
}

View File

@ -0,0 +1,10 @@
namespace CarCenterView
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
}
}

View File

@ -0,0 +1,120 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
Version 2.0
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.
Example:
... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
<value>[base64 mime encoded serialized .NET Framework object]</value>
</data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>
There are any number of "resheader" rows that contain simple
name/value pairs.
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.
mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
</root>

View File

@ -0,0 +1,17 @@
namespace CarCenterView
{
internal static class Program
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[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());
}
}
}