create database
This commit is contained in:
parent
34a61279d1
commit
687e4a8e55
@ -10,7 +10,7 @@ namespace CarShowroomContracts.AbstractModels
|
||||
public interface ICar : IId
|
||||
{
|
||||
string Color { get; }
|
||||
DateTime RealiseDate { get; }
|
||||
DateTime ReleaseDate { get; }
|
||||
int ModelId { get; }
|
||||
}
|
||||
}
|
||||
|
@ -11,8 +11,8 @@ namespace CarShowroomContracts.AbstractModels
|
||||
{
|
||||
DateTime SaleTime { get; }
|
||||
int Cost { get; }
|
||||
int ClientId { get; }
|
||||
int EmployeeId { get; }
|
||||
int? ClientId { get; }
|
||||
int? EmployeeId { get; }
|
||||
List<int> CarIds { get; }
|
||||
List<int> ServiceIds { get; }
|
||||
}
|
||||
|
@ -11,13 +11,13 @@ namespace CarShowroomContracts.Dtos
|
||||
{
|
||||
public int Id { get; set; }
|
||||
public string Color { get; set; }
|
||||
public DateTime RealiseDate { get; set; }
|
||||
public DateTime ReleaseDate { get; set; }
|
||||
public int ModelId { get; set; }
|
||||
public CarDto(ICar model)
|
||||
{
|
||||
Id = model.Id;
|
||||
Color = model.Color;
|
||||
RealiseDate = model.RealiseDate;
|
||||
ReleaseDate = model.ReleaseDate;
|
||||
ModelId = model.ModelId;
|
||||
}
|
||||
}
|
||||
|
@ -12,8 +12,8 @@ namespace CarShowroomDataModels.Dtos
|
||||
public int Id { get; set; }
|
||||
public DateTime SaleTime { get; set; }
|
||||
public int Cost { get; set; }
|
||||
public int ClientId { get; set; }
|
||||
public int EmployeeId { get; set; }
|
||||
public int? ClientId { get; set; }
|
||||
public int? EmployeeId { get; set; }
|
||||
public List<int> CarIds { get; set; } = new();
|
||||
public List<int> ServiceIds { get; set; } = new();
|
||||
public SaleDto(ISale model)
|
||||
|
@ -6,7 +6,7 @@ using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace CarShowroomContracts.Dtos
|
||||
namespace CarShowroomContracts.Views
|
||||
{
|
||||
public class CarView : ICar
|
||||
{
|
||||
@ -15,7 +15,7 @@ namespace CarShowroomContracts.Dtos
|
||||
[DisplayName("Цвет")]
|
||||
public string Color { get; set; }
|
||||
[DisplayName("Дата производства")]
|
||||
public DateTime RealiseDate { get; set; }
|
||||
public DateTime ReleaseDate { get; set; }
|
||||
public int ModelId { get; set; }
|
||||
[DisplayName("Модель")]
|
||||
public string ModelName { get; set; } = string.Empty;
|
||||
@ -27,7 +27,7 @@ namespace CarShowroomContracts.Dtos
|
||||
{
|
||||
Id = model.Id;
|
||||
Color = model.Color;
|
||||
RealiseDate = model.RealiseDate;
|
||||
ReleaseDate = model.ReleaseDate;
|
||||
ModelId = model.ModelId;
|
||||
}
|
||||
}
|
||||
|
@ -6,7 +6,7 @@ using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace CarShowroomContracts.Dtos
|
||||
namespace CarShowroomContracts.Views
|
||||
{
|
||||
public class ClientView : IClient
|
||||
{
|
||||
|
@ -6,7 +6,7 @@ using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace CarShowroomContracts.Dtos
|
||||
namespace CarShowroomContracts.Views
|
||||
{
|
||||
public class EmployeeView : IEmployee
|
||||
{
|
||||
|
@ -6,7 +6,7 @@ using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace CarShowroomContracts.Dtos
|
||||
namespace CarShowroomContracts.Views
|
||||
{
|
||||
public class MakeView : IMake
|
||||
{
|
||||
|
@ -6,7 +6,7 @@ using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace CarShowroomContracts.Dtos
|
||||
namespace CarShowroomContracts.Views
|
||||
{
|
||||
public class ModelView : IModel
|
||||
{
|
||||
|
@ -1,5 +1,6 @@
|
||||
using CarShowroomContracts.AbstractModels;
|
||||
using CarShowroomContracts.Dtos;
|
||||
using CarShowroomContracts.Views;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
@ -7,9 +8,9 @@ using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace CarShowroomDataModels.Dtos
|
||||
namespace CarShowroomDataModels.Views
|
||||
{
|
||||
internal class SaleView : ISale
|
||||
public class SaleView : ISale
|
||||
{
|
||||
[DisplayName("Номер продажи")]
|
||||
public int Id { get; set; }
|
||||
@ -17,10 +18,10 @@ namespace CarShowroomDataModels.Dtos
|
||||
public DateTime SaleTime { get; set; }
|
||||
[DisplayName("Сумма")]
|
||||
public int Cost { get; set; }
|
||||
public int ClientId { get; set; }
|
||||
public int? ClientId { get; set; }
|
||||
[DisplayName("Клиент")]
|
||||
public string ClientName { get; set; } = string.Empty;
|
||||
public int EmployeeId { get; set; }
|
||||
public int? EmployeeId { get; set; }
|
||||
[DisplayName("Сотрудник")]
|
||||
public string EmployeeName { get; set; } = string.Empty;
|
||||
public List<int> CarIds
|
||||
|
@ -5,7 +5,7 @@ using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace CarShowroomContracts.Dtos
|
||||
namespace CarShowroomContracts.Views
|
||||
{
|
||||
public class ServiceView : IService
|
||||
{
|
||||
|
@ -0,0 +1,86 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Azure.Core;
|
||||
using Azure;
|
||||
using CarShowroomDatabaseStorage.Entities;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace CarShowroomDatabaseStorage
|
||||
{
|
||||
public class CarShowroomDatabase : DbContext
|
||||
{
|
||||
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
|
||||
{
|
||||
if (optionsBuilder.IsConfigured == false)
|
||||
{
|
||||
optionsBuilder.UseNpgsql("Host=localhost;Port=5433;Database=CarShowroomDatabase;Username=postgres;Password=postgres");
|
||||
//ptionsBuilder.UseSqlServer(@"Data Source=localhost\SQLEXPRESS;Initial Catalog=CarShowroomDatabase;Integrated Security=True;MultipleActiveResultSets=True;;TrustServerCertificate=True");
|
||||
}
|
||||
base.OnConfiguring(optionsBuilder);
|
||||
}
|
||||
|
||||
protected override void OnModelCreating(ModelBuilder modelBuilder)
|
||||
{
|
||||
//composite primary keys
|
||||
modelBuilder.Entity<SaleCar>().HasKey(sc => new { sc.SaleId, sc.CarId });
|
||||
modelBuilder.Entity<SaleService>().HasKey(sc => new { sc.SaleId, sc.ServiceId });
|
||||
//default values
|
||||
modelBuilder.Entity<Client>().Property(c => c.Name).HasDefaultValue("empty_string");
|
||||
modelBuilder.Entity<Client>().Property(c => c.Password).HasDefaultValue("empty_string");
|
||||
modelBuilder.Entity<Employee>().Property(e => e.Name).HasDefaultValue("empty_string");
|
||||
modelBuilder.Entity<Employee>().Property(e => e.Password).HasDefaultValue("empty_string");
|
||||
modelBuilder.Entity<Car>().Property(c => c.Color).HasDefaultValue("empty_string");
|
||||
modelBuilder.Entity<Service>().Property(c => c.Cost).HasDefaultValue(-1);
|
||||
modelBuilder.Entity<Model>().Property(c => c.Price).HasDefaultValue(-1);
|
||||
modelBuilder.Entity<Sale>().Property(c => c.Cost).HasDefaultValue(-1);
|
||||
//on delete actions
|
||||
modelBuilder.Entity<Model>()
|
||||
.HasOne(m => m.Make)
|
||||
.WithMany(m => m.Models)
|
||||
.OnDelete(DeleteBehavior.Restrict);
|
||||
modelBuilder.Entity<Car>()
|
||||
.HasOne(m => m.Model)
|
||||
.WithMany(m => m.Cars)
|
||||
.OnDelete(DeleteBehavior.Restrict);
|
||||
modelBuilder.Entity<Sale>()
|
||||
.HasOne(m => m.Client)
|
||||
.WithMany(m => m.Sales)
|
||||
.OnDelete(DeleteBehavior.SetNull);
|
||||
modelBuilder.Entity<Sale>()
|
||||
.HasOne(m => m.Employee)
|
||||
.WithMany(m => m.Sales)
|
||||
.OnDelete(DeleteBehavior.SetNull);
|
||||
modelBuilder.Entity<SaleService>()
|
||||
.HasOne(m => m.Sale)
|
||||
.WithMany(m => m.SaleServices)
|
||||
.OnDelete(DeleteBehavior.Restrict);
|
||||
modelBuilder.Entity<SaleCar>()
|
||||
.HasOne(m => m.Sale)
|
||||
.WithMany(m => m.SaleCars)
|
||||
.OnDelete(DeleteBehavior.Restrict);
|
||||
modelBuilder.Entity<SaleService>()
|
||||
.HasOne(m => m.Service)
|
||||
.WithMany(m => m.SaleServices)
|
||||
.OnDelete(DeleteBehavior.Cascade);
|
||||
modelBuilder.Entity<SaleCar>()
|
||||
.HasOne(m => m.Car)
|
||||
.WithMany(m => m.SaleCars)
|
||||
.OnDelete(DeleteBehavior.Cascade);
|
||||
base.OnModelCreating(modelBuilder);
|
||||
}
|
||||
|
||||
public virtual DbSet<Make> Makes { set; get; }
|
||||
public virtual DbSet<Model> Models { set; get; }
|
||||
public virtual DbSet<Car> Cars { set; get; }
|
||||
public virtual DbSet<Service> Services { set; get; }
|
||||
public virtual DbSet<Employee> Employees { set; get; }
|
||||
public virtual DbSet<Client> Clients { set; get; }
|
||||
public virtual DbSet<Sale> Sales { set; get; }
|
||||
public virtual DbSet<SaleCar> SaleCars { set; get; }
|
||||
public virtual DbSet<SaleService> SaleServices { set; get; }
|
||||
}
|
||||
}
|
@ -6,6 +6,16 @@
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="7.0.18" />
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="7.0.18" />
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="7.0.18">
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
</PackageReference>
|
||||
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="7.0.11" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\CarShowroomContracts\CarShowroomContracts.csproj" />
|
||||
<ProjectReference Include="..\CarShowroomDataModels\CarShowroomDataModels.csproj" />
|
||||
|
@ -1,7 +0,0 @@
|
||||
namespace CarShowroomDatabaseStorage
|
||||
{
|
||||
public class Class1
|
||||
{
|
||||
|
||||
}
|
||||
}
|
@ -1,24 +1,66 @@
|
||||
using CarShowroomContracts.AbstractModels;
|
||||
using CarShowroomContracts.Views;
|
||||
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 CarShowroomDatabaseStorage.Entities
|
||||
{
|
||||
[Table("car")]
|
||||
public class Car : ICar
|
||||
{
|
||||
public int Id { get; set; }
|
||||
public string Color { get; set; }
|
||||
public DateTime RealiseDate { get; set; }
|
||||
public int ModelId { get; set; }
|
||||
public Car(ICar car)
|
||||
[Column("car_id")]
|
||||
public int Id { get; private set; }
|
||||
[Required]
|
||||
[Column("car_color")]
|
||||
[MaxLength(50)]
|
||||
public string Color { get; private set; } = string.Empty;
|
||||
[Required]
|
||||
[Column("car_releasedate")]
|
||||
public DateTime ReleaseDate { get; private set; }
|
||||
[Required]
|
||||
[Column("car_model_id")]
|
||||
public int ModelId { get; private set; }
|
||||
public virtual Model? Model { get; set; }
|
||||
public virtual List<SaleCar> SaleCars { get; set; } = new();
|
||||
|
||||
private Car(){}
|
||||
|
||||
private Car(ICar car)
|
||||
{
|
||||
Id = car.Id;
|
||||
Color = car.Color;
|
||||
RealiseDate = DateTime.Now;
|
||||
ReleaseDate = DateTime.Now;
|
||||
ModelId = car.ModelId;
|
||||
}
|
||||
|
||||
public static Car? Create(ICar car)
|
||||
{
|
||||
if (car == null)
|
||||
return null;
|
||||
return new Car(car);
|
||||
}
|
||||
|
||||
public void Update(ICar car)
|
||||
{
|
||||
if (car == null)
|
||||
return;
|
||||
Color = car.Color;
|
||||
ReleaseDate = car.ReleaseDate;
|
||||
ModelId = car.ModelId;
|
||||
}
|
||||
|
||||
public CarView GetCarView()
|
||||
{
|
||||
CarView car = new CarView(this);
|
||||
car.ModelPrice = Model?.Price ?? 0;
|
||||
car.ModelName = Model?.Name ?? string.Empty;
|
||||
car.MakeName = Model?.Make?.Name ?? string.Empty;
|
||||
return car;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,24 +1,66 @@
|
||||
using CarShowroomDataModels.Models;
|
||||
using CarShowroomContracts.AbstractModels;
|
||||
using CarShowroomContracts.Views;
|
||||
using CarShowroomDataModels.Models;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
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 CarShowroomDatabaseStorage.Entities
|
||||
{
|
||||
[Table("client")]
|
||||
[Index(nameof(Email), IsUnique = true)]
|
||||
public class Client : IClient
|
||||
{
|
||||
public int Id { get; set; }
|
||||
public string Name { get; set; }
|
||||
public string Email { get; set; }
|
||||
public string Password { get; set; }
|
||||
public Client(IClient client)
|
||||
[Column("client_id")]
|
||||
public int Id { get; private set; }
|
||||
[Required]
|
||||
[Column("client_name")]
|
||||
[MaxLength(50)]
|
||||
public string Name { get; private set; } = string.Empty;
|
||||
[Required]
|
||||
[Column("client_email")]
|
||||
[MaxLength(40)]
|
||||
public string Email { get; private set; } = string.Empty;
|
||||
[Required]
|
||||
[Column("client_password")]
|
||||
[MaxLength(32)]
|
||||
public string Password { get; private set; } = string.Empty;
|
||||
public virtual List<Sale> Sales { get; set; } = new();
|
||||
|
||||
private Client() { }
|
||||
|
||||
private Client(IClient client)
|
||||
{
|
||||
Id = client.Id;
|
||||
Name = client.Name;
|
||||
Email = client.Email;
|
||||
Password = client.Password;
|
||||
}
|
||||
|
||||
public static Client? Create(IClient client)
|
||||
{
|
||||
if (client == null)
|
||||
return null;
|
||||
return new Client(client);
|
||||
}
|
||||
|
||||
public void Update(IClient client)
|
||||
{
|
||||
if (client == null)
|
||||
return;
|
||||
Name = client.Name;
|
||||
Email = client.Email;
|
||||
Password = client.Password;
|
||||
}
|
||||
|
||||
public ClientView GetClientView()
|
||||
{
|
||||
return new ClientView(this);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,24 +1,65 @@
|
||||
using CarShowroomDataModels.Models;
|
||||
using CarShowroomContracts.Views;
|
||||
using CarShowroomDataModels.Models;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
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 CarShowroomDatabaseStorage.Entities
|
||||
{
|
||||
[Table("employee")]
|
||||
[Index(nameof(Email), IsUnique = true)]
|
||||
public class Employee : IEmployee
|
||||
{
|
||||
public int Id { get; set; }
|
||||
public string Name { get; set; }
|
||||
public string Email { get; set; }
|
||||
public string Password { get; set; }
|
||||
public Employee(IEmployee employee)
|
||||
[Column("employee_id")]
|
||||
public int Id { get; private set; }
|
||||
[Required]
|
||||
[Column("employee_name")]
|
||||
[MaxLength(50)]
|
||||
public string Name { get; private set; } = string.Empty;
|
||||
[Required]
|
||||
[Column("employee_email")]
|
||||
[MaxLength(40)]
|
||||
public string Email { get; private set; } = string.Empty;
|
||||
[Required]
|
||||
[Column("employee_password")]
|
||||
[MaxLength(32)]
|
||||
public string Password { get; private set; } = string.Empty;
|
||||
public virtual List<Sale> Sales { get; set; } = new();
|
||||
|
||||
private Employee() { }
|
||||
|
||||
private Employee(IEmployee employee)
|
||||
{
|
||||
Id = employee.Id;
|
||||
Name = employee.Name;
|
||||
Email = employee.Email;
|
||||
Password = employee.Password;
|
||||
}
|
||||
|
||||
public static Employee? Create(IEmployee employee)
|
||||
{
|
||||
if (employee == null)
|
||||
return null;
|
||||
return new Employee(employee);
|
||||
}
|
||||
|
||||
public void Update(IEmployee employee)
|
||||
{
|
||||
if(employee == null)
|
||||
return;
|
||||
Name = employee.Name;
|
||||
Email = employee.Email;
|
||||
Password = employee.Password;
|
||||
}
|
||||
|
||||
public EmployeeView GetEmployeeView()
|
||||
{
|
||||
return new EmployeeView(this);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,20 +1,53 @@
|
||||
using CarShowroomContracts.AbstractModels;
|
||||
using CarShowroomContracts.Views;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
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 CarShowroomDatabaseStorage.Entities
|
||||
{
|
||||
[Table("make")]
|
||||
[Index(nameof(Name), IsUnique = true)]
|
||||
public class Make : IMake
|
||||
{
|
||||
public int Id { get; set; }
|
||||
public string Name { get; set; }
|
||||
public Make(IMake make)
|
||||
[Column("make_id")]
|
||||
public int Id { get; private set; }
|
||||
[Required]
|
||||
[Column("make_name")]
|
||||
[MaxLength(50)]
|
||||
public string Name { get; private set; } = string.Empty;
|
||||
public virtual List<Model> Models { get; set; } = new();
|
||||
|
||||
private Make() { }
|
||||
|
||||
private Make(IMake make)
|
||||
{
|
||||
Id = make.Id;
|
||||
Name = make.Name;
|
||||
}
|
||||
|
||||
public static Make? Create(IMake make)
|
||||
{
|
||||
if (make == null)
|
||||
return null;
|
||||
return new Make(make);
|
||||
}
|
||||
|
||||
public void Update(IMake make)
|
||||
{
|
||||
if (make == null)
|
||||
return;
|
||||
Name = make.Name;
|
||||
}
|
||||
|
||||
public MakeView GetView()
|
||||
{
|
||||
return new MakeView(this);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,24 +1,66 @@
|
||||
using CarShowroomContracts.AbstractModels;
|
||||
using CarShowroomContracts.Views;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
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 CarShowroomDatabaseStorage.Entities
|
||||
{
|
||||
[Table("model")]
|
||||
[Index(nameof(Name), IsUnique = true)]
|
||||
public class Model : IModel
|
||||
{
|
||||
public int Id { get; set; }
|
||||
public string Name { get; set; }
|
||||
public int Price { get; set; }
|
||||
public int MakeId { get; set; }
|
||||
public Model(IModel model)
|
||||
[Column("model_id")]
|
||||
public int Id { get; private set; }
|
||||
[Required]
|
||||
[Column("model_name")]
|
||||
[MaxLength(50)]
|
||||
public string Name { get; private set; } = string.Empty;
|
||||
[Required]
|
||||
[Column("model_price")]
|
||||
public int Price { get; private set; }
|
||||
[Required]
|
||||
[Column("model_make_id")]
|
||||
public int MakeId { get; private set; }
|
||||
public virtual Make? Make { get; set; }
|
||||
public virtual List<Car> Cars { get; set; } = new();
|
||||
|
||||
private Model() { }
|
||||
|
||||
private Model(IModel model)
|
||||
{
|
||||
Id = model.Id;
|
||||
Name = model.Name;
|
||||
Price = model.Price;
|
||||
MakeId = model.MakeId;
|
||||
}
|
||||
|
||||
public static Model? Create(IModel model)
|
||||
{
|
||||
if (model == null)
|
||||
return null;
|
||||
return new Model(model);
|
||||
}
|
||||
|
||||
public void Update(IModel model)
|
||||
{
|
||||
if (model == null)
|
||||
return;
|
||||
Name = model.Name;
|
||||
Price = model.Price;
|
||||
MakeId = model.MakeId;
|
||||
}
|
||||
|
||||
public ModelView GetModelView()
|
||||
{
|
||||
ModelView model = new ModelView(this);
|
||||
model.MakeName = Make?.Name ?? string.Empty;
|
||||
return model;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,30 +1,94 @@
|
||||
using CarShowroomContracts.AbstractModels;
|
||||
using CarShowroomContracts.Views;
|
||||
using CarShowroomDataModels.Views;
|
||||
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 CarShowroomDatabaseStorage.Entities
|
||||
{
|
||||
[Table("sale")]
|
||||
public class Sale : ISale
|
||||
{
|
||||
public int Id { get; set; }
|
||||
public DateTime SaleTime { get; set; }
|
||||
public int Cost { get; set; }
|
||||
public int ClientId { get; set; }
|
||||
public int EmployeeId { get; set; }
|
||||
public List<int> CarIds { get; set; }
|
||||
public List<int> ServiceIds { get; set; }
|
||||
public Sale(ISale sale)
|
||||
[Column("sale_id")]
|
||||
public int Id { get; private set; }
|
||||
[Required]
|
||||
[Column("sale_time")]
|
||||
public DateTime SaleTime { get; private set; }
|
||||
[Required]
|
||||
[Column("sale_cost")]
|
||||
public int Cost { get; private set; }
|
||||
[Column("sale_client_id")]
|
||||
public int? ClientId { get; private set; }
|
||||
public virtual Client? Client { get; set; }
|
||||
[Column("sale_employee_id")]
|
||||
public int? EmployeeId { get; private set; }
|
||||
public virtual Employee? Employee { get; set; }
|
||||
public virtual List<Car> Cars { get; set; } = new();
|
||||
public virtual List<SaleCar> SaleCars { get; set; } = new();
|
||||
[NotMapped]
|
||||
public List<int> CarIds
|
||||
{
|
||||
get
|
||||
{
|
||||
return Cars.Select(c => c.Id).ToList();
|
||||
}
|
||||
}
|
||||
public virtual List<Service> Services { get; set; } = new();
|
||||
public virtual List<SaleService> SaleServices { get; set; } = new();
|
||||
[NotMapped]
|
||||
public List<int> ServiceIds
|
||||
{
|
||||
get
|
||||
{
|
||||
return Services.Select(s => s.Id).ToList();
|
||||
}
|
||||
}
|
||||
|
||||
private Sale() { }
|
||||
|
||||
private Sale(ISale sale)
|
||||
{
|
||||
Id = sale.Id;
|
||||
SaleTime = sale.SaleTime;
|
||||
Cost = sale.Cost;
|
||||
ClientId = sale.ClientId;
|
||||
EmployeeId = sale.EmployeeId;
|
||||
CarIds = sale.CarIds;
|
||||
ServiceIds = sale.ServiceIds;
|
||||
}
|
||||
|
||||
public static Sale? Create(ISale sale)
|
||||
{
|
||||
if (sale == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return new Sale(sale);
|
||||
}
|
||||
|
||||
public void Update(ISale sale)
|
||||
{
|
||||
if (sale == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
SaleTime = sale.SaleTime;
|
||||
Cost = sale.Cost;
|
||||
ClientId = sale.ClientId;
|
||||
EmployeeId = sale.EmployeeId;
|
||||
}
|
||||
|
||||
public SaleView GetSaleView()
|
||||
{
|
||||
SaleView sale = new SaleView(this);
|
||||
sale.ClientName = Client?.Name ?? string.Empty;
|
||||
sale.EmployeeName = Employee?.Name ?? string.Empty;
|
||||
sale.Services = Services.Select(s => s.GetServiceView()).ToList();
|
||||
sale.Cars = Cars.Select(c => c.GetCarView()).ToList();
|
||||
return sale;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
20
CarShowroom/CarShowroomDatabaseStorage/Entities/SaleCar.cs
Normal file
20
CarShowroom/CarShowroomDatabaseStorage/Entities/SaleCar.cs
Normal file
@ -0,0 +1,20 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace CarShowroomDatabaseStorage.Entities
|
||||
{
|
||||
[Table("sale_car")]
|
||||
public class SaleCar
|
||||
{
|
||||
[Column("sale_id")]
|
||||
public int SaleId { get; set; }
|
||||
public virtual Sale? Sale { get; set; }
|
||||
[Column("car_id")]
|
||||
public int CarId { get; set; }
|
||||
public virtual Car? Car { get; set; }
|
||||
}
|
||||
}
|
@ -0,0 +1,21 @@
|
||||
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 CarShowroomDatabaseStorage.Entities
|
||||
{
|
||||
[Table("sale_service")]
|
||||
public class SaleService
|
||||
{
|
||||
[Column("sale_id")]
|
||||
public int SaleId { get; set; }
|
||||
public virtual Sale? Sale { get; set; }
|
||||
[Column("service_id")]
|
||||
public int ServiceId { get; set; }
|
||||
public virtual Service? Service { get; set; }
|
||||
}
|
||||
}
|
@ -1,22 +1,59 @@
|
||||
using CarShowroomContracts.AbstractModels;
|
||||
using CarShowroomContracts.Views;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
using System.Linq;
|
||||
using System.Runtime.ConstrainedExecution;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace CarShowroomDatabaseStorage.Entities
|
||||
{
|
||||
internal class Service : IService
|
||||
[Table("service")]
|
||||
[Index(nameof(Name), IsUnique = true)]
|
||||
public class Service : IService
|
||||
{
|
||||
public int Id { get; set; }
|
||||
public string Name { get; set; }
|
||||
public int Cost { get; set; }
|
||||
public Service(IService service)
|
||||
[Column("service_id")]
|
||||
public int Id { get; private set; }
|
||||
[Required]
|
||||
[Column("service_name")]
|
||||
[MaxLength(50)]
|
||||
public string Name { get; private set; } = string.Empty;
|
||||
[Required]
|
||||
[Column("service_cost")]
|
||||
public int Cost { get; private set; }
|
||||
public virtual List<SaleService> SaleServices { get; set; } = new();
|
||||
|
||||
private Service() { }
|
||||
|
||||
private Service(IService service)
|
||||
{
|
||||
Id = service.Id;
|
||||
Name = service.Name;
|
||||
Cost = service.Cost;
|
||||
}
|
||||
|
||||
public static Service? Create(IService service)
|
||||
{
|
||||
if (service == null)
|
||||
return null;
|
||||
return new Service(service);
|
||||
}
|
||||
|
||||
public void Update(IService service)
|
||||
{
|
||||
if (service == null)
|
||||
return;
|
||||
Name = service.Name;
|
||||
Cost = service.Cost;
|
||||
}
|
||||
|
||||
public ServiceView GetServiceView()
|
||||
{
|
||||
return new ServiceView(this);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
436
CarShowroom/CarShowroomDatabaseStorage/Migrations/20240505145552_InitialCreate.Designer.cs
generated
Normal file
436
CarShowroom/CarShowroomDatabaseStorage/Migrations/20240505145552_InitialCreate.Designer.cs
generated
Normal file
@ -0,0 +1,436 @@
|
||||
// <auto-generated />
|
||||
using System;
|
||||
using CarShowroomDatabaseStorage;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Infrastructure;
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
|
||||
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace CarShowroomDatabaseStorage.Migrations
|
||||
{
|
||||
[DbContext(typeof(CarShowroomDatabase))]
|
||||
[Migration("20240505145552_InitialCreate")]
|
||||
partial class InitialCreate
|
||||
{
|
||||
/// <inheritdoc />
|
||||
protected override void BuildTargetModel(ModelBuilder modelBuilder)
|
||||
{
|
||||
#pragma warning disable 612, 618
|
||||
modelBuilder
|
||||
.HasAnnotation("ProductVersion", "7.0.18")
|
||||
.HasAnnotation("Relational:MaxIdentifierLength", 63);
|
||||
|
||||
NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder);
|
||||
|
||||
modelBuilder.Entity("CarShowroomDatabaseStorage.Entities.Car", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("integer")
|
||||
.HasColumnName("car_id");
|
||||
|
||||
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<string>("Color")
|
||||
.IsRequired()
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasMaxLength(50)
|
||||
.HasColumnType("character varying(50)")
|
||||
.HasDefaultValue("empty_string")
|
||||
.HasColumnName("car_color");
|
||||
|
||||
b.Property<int>("ModelId")
|
||||
.HasColumnType("integer")
|
||||
.HasColumnName("car_model_id");
|
||||
|
||||
b.Property<DateTime>("ReleaseDate")
|
||||
.HasColumnType("timestamp with time zone")
|
||||
.HasColumnName("car_releasedate");
|
||||
|
||||
b.Property<int?>("SaleId")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("ModelId");
|
||||
|
||||
b.HasIndex("SaleId");
|
||||
|
||||
b.ToTable("car");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("CarShowroomDatabaseStorage.Entities.Client", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("integer")
|
||||
.HasColumnName("client_id");
|
||||
|
||||
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<string>("Email")
|
||||
.IsRequired()
|
||||
.HasMaxLength(40)
|
||||
.HasColumnType("character varying(40)")
|
||||
.HasColumnName("client_email");
|
||||
|
||||
b.Property<string>("Name")
|
||||
.IsRequired()
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasMaxLength(50)
|
||||
.HasColumnType("character varying(50)")
|
||||
.HasDefaultValue("empty_string")
|
||||
.HasColumnName("client_name");
|
||||
|
||||
b.Property<string>("Password")
|
||||
.IsRequired()
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasMaxLength(32)
|
||||
.HasColumnType("character varying(32)")
|
||||
.HasDefaultValue("empty_string")
|
||||
.HasColumnName("client_password");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("Email")
|
||||
.IsUnique();
|
||||
|
||||
b.ToTable("client");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("CarShowroomDatabaseStorage.Entities.Employee", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("integer")
|
||||
.HasColumnName("employee_id");
|
||||
|
||||
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<string>("Email")
|
||||
.IsRequired()
|
||||
.HasMaxLength(40)
|
||||
.HasColumnType("character varying(40)")
|
||||
.HasColumnName("employee_email");
|
||||
|
||||
b.Property<string>("Name")
|
||||
.IsRequired()
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasMaxLength(50)
|
||||
.HasColumnType("character varying(50)")
|
||||
.HasDefaultValue("empty_string")
|
||||
.HasColumnName("employee_name");
|
||||
|
||||
b.Property<string>("Password")
|
||||
.IsRequired()
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasMaxLength(32)
|
||||
.HasColumnType("character varying(32)")
|
||||
.HasDefaultValue("empty_string")
|
||||
.HasColumnName("employee_password");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("Email")
|
||||
.IsUnique();
|
||||
|
||||
b.ToTable("employee");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("CarShowroomDatabaseStorage.Entities.Make", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("integer")
|
||||
.HasColumnName("make_id");
|
||||
|
||||
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<string>("Name")
|
||||
.IsRequired()
|
||||
.HasMaxLength(50)
|
||||
.HasColumnType("character varying(50)")
|
||||
.HasColumnName("make_name");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("Name")
|
||||
.IsUnique();
|
||||
|
||||
b.ToTable("make");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("CarShowroomDatabaseStorage.Entities.Model", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("integer")
|
||||
.HasColumnName("model_id");
|
||||
|
||||
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<int>("MakeId")
|
||||
.HasColumnType("integer")
|
||||
.HasColumnName("model_make_id");
|
||||
|
||||
b.Property<string>("Name")
|
||||
.IsRequired()
|
||||
.HasMaxLength(50)
|
||||
.HasColumnType("character varying(50)")
|
||||
.HasColumnName("model_name");
|
||||
|
||||
b.Property<int>("Price")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("integer")
|
||||
.HasDefaultValue(-1)
|
||||
.HasColumnName("model_price");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("MakeId");
|
||||
|
||||
b.HasIndex("Name")
|
||||
.IsUnique();
|
||||
|
||||
b.ToTable("model");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("CarShowroomDatabaseStorage.Entities.Sale", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("integer")
|
||||
.HasColumnName("sale_id");
|
||||
|
||||
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<int?>("ClientId")
|
||||
.HasColumnType("integer")
|
||||
.HasColumnName("sale_client_id");
|
||||
|
||||
b.Property<int>("Cost")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("integer")
|
||||
.HasDefaultValue(-1)
|
||||
.HasColumnName("sale_cost");
|
||||
|
||||
b.Property<int?>("EmployeeId")
|
||||
.HasColumnType("integer")
|
||||
.HasColumnName("sale_employee_id");
|
||||
|
||||
b.Property<DateTime>("SaleTime")
|
||||
.HasColumnType("timestamp with time zone")
|
||||
.HasColumnName("sale_time");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("ClientId");
|
||||
|
||||
b.HasIndex("EmployeeId");
|
||||
|
||||
b.ToTable("sale");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("CarShowroomDatabaseStorage.Entities.SaleCar", b =>
|
||||
{
|
||||
b.Property<int>("SaleId")
|
||||
.HasColumnType("integer")
|
||||
.HasColumnName("sale_id");
|
||||
|
||||
b.Property<int>("CarId")
|
||||
.HasColumnType("integer")
|
||||
.HasColumnName("car_id");
|
||||
|
||||
b.HasKey("SaleId", "CarId");
|
||||
|
||||
b.HasIndex("CarId");
|
||||
|
||||
b.ToTable("sale_car");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("CarShowroomDatabaseStorage.Entities.SaleService", b =>
|
||||
{
|
||||
b.Property<int>("SaleId")
|
||||
.HasColumnType("integer")
|
||||
.HasColumnName("sale_id");
|
||||
|
||||
b.Property<int>("ServiceId")
|
||||
.HasColumnType("integer")
|
||||
.HasColumnName("service_id");
|
||||
|
||||
b.HasKey("SaleId", "ServiceId");
|
||||
|
||||
b.HasIndex("ServiceId");
|
||||
|
||||
b.ToTable("sale_service");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("CarShowroomDatabaseStorage.Entities.Service", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("integer")
|
||||
.HasColumnName("service_id");
|
||||
|
||||
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<int>("Cost")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("integer")
|
||||
.HasDefaultValue(-1)
|
||||
.HasColumnName("service_cost");
|
||||
|
||||
b.Property<string>("Name")
|
||||
.IsRequired()
|
||||
.HasMaxLength(50)
|
||||
.HasColumnType("character varying(50)")
|
||||
.HasColumnName("service_name");
|
||||
|
||||
b.Property<int?>("SaleId")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("Name")
|
||||
.IsUnique();
|
||||
|
||||
b.HasIndex("SaleId");
|
||||
|
||||
b.ToTable("service");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("CarShowroomDatabaseStorage.Entities.Car", b =>
|
||||
{
|
||||
b.HasOne("CarShowroomDatabaseStorage.Entities.Model", "Model")
|
||||
.WithMany("Cars")
|
||||
.HasForeignKey("ModelId")
|
||||
.OnDelete(DeleteBehavior.Restrict)
|
||||
.IsRequired();
|
||||
|
||||
b.HasOne("CarShowroomDatabaseStorage.Entities.Sale", null)
|
||||
.WithMany("Cars")
|
||||
.HasForeignKey("SaleId");
|
||||
|
||||
b.Navigation("Model");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("CarShowroomDatabaseStorage.Entities.Model", b =>
|
||||
{
|
||||
b.HasOne("CarShowroomDatabaseStorage.Entities.Make", "Make")
|
||||
.WithMany("Models")
|
||||
.HasForeignKey("MakeId")
|
||||
.OnDelete(DeleteBehavior.Restrict)
|
||||
.IsRequired();
|
||||
|
||||
b.Navigation("Make");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("CarShowroomDatabaseStorage.Entities.Sale", b =>
|
||||
{
|
||||
b.HasOne("CarShowroomDatabaseStorage.Entities.Client", "Client")
|
||||
.WithMany("Sales")
|
||||
.HasForeignKey("ClientId")
|
||||
.OnDelete(DeleteBehavior.SetNull);
|
||||
|
||||
b.HasOne("CarShowroomDatabaseStorage.Entities.Employee", "Employee")
|
||||
.WithMany("Sales")
|
||||
.HasForeignKey("EmployeeId")
|
||||
.OnDelete(DeleteBehavior.SetNull);
|
||||
|
||||
b.Navigation("Client");
|
||||
|
||||
b.Navigation("Employee");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("CarShowroomDatabaseStorage.Entities.SaleCar", b =>
|
||||
{
|
||||
b.HasOne("CarShowroomDatabaseStorage.Entities.Car", "Car")
|
||||
.WithMany("SaleCars")
|
||||
.HasForeignKey("CarId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.HasOne("CarShowroomDatabaseStorage.Entities.Sale", "Sale")
|
||||
.WithMany("SaleCars")
|
||||
.HasForeignKey("SaleId")
|
||||
.OnDelete(DeleteBehavior.Restrict)
|
||||
.IsRequired();
|
||||
|
||||
b.Navigation("Car");
|
||||
|
||||
b.Navigation("Sale");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("CarShowroomDatabaseStorage.Entities.SaleService", b =>
|
||||
{
|
||||
b.HasOne("CarShowroomDatabaseStorage.Entities.Sale", "Sale")
|
||||
.WithMany("SaleServices")
|
||||
.HasForeignKey("SaleId")
|
||||
.OnDelete(DeleteBehavior.Restrict)
|
||||
.IsRequired();
|
||||
|
||||
b.HasOne("CarShowroomDatabaseStorage.Entities.Service", "Service")
|
||||
.WithMany("SaleServices")
|
||||
.HasForeignKey("ServiceId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.Navigation("Sale");
|
||||
|
||||
b.Navigation("Service");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("CarShowroomDatabaseStorage.Entities.Service", b =>
|
||||
{
|
||||
b.HasOne("CarShowroomDatabaseStorage.Entities.Sale", null)
|
||||
.WithMany("Services")
|
||||
.HasForeignKey("SaleId");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("CarShowroomDatabaseStorage.Entities.Car", b =>
|
||||
{
|
||||
b.Navigation("SaleCars");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("CarShowroomDatabaseStorage.Entities.Client", b =>
|
||||
{
|
||||
b.Navigation("Sales");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("CarShowroomDatabaseStorage.Entities.Employee", b =>
|
||||
{
|
||||
b.Navigation("Sales");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("CarShowroomDatabaseStorage.Entities.Make", b =>
|
||||
{
|
||||
b.Navigation("Models");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("CarShowroomDatabaseStorage.Entities.Model", b =>
|
||||
{
|
||||
b.Navigation("Cars");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("CarShowroomDatabaseStorage.Entities.Sale", b =>
|
||||
{
|
||||
b.Navigation("Cars");
|
||||
|
||||
b.Navigation("SaleCars");
|
||||
|
||||
b.Navigation("SaleServices");
|
||||
|
||||
b.Navigation("Services");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("CarShowroomDatabaseStorage.Entities.Service", b =>
|
||||
{
|
||||
b.Navigation("SaleServices");
|
||||
});
|
||||
#pragma warning restore 612, 618
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,304 @@
|
||||
using System;
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace CarShowroomDatabaseStorage.Migrations
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public partial class InitialCreate : Migration
|
||||
{
|
||||
/// <inheritdoc />
|
||||
protected override void Up(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.CreateTable(
|
||||
name: "client",
|
||||
columns: table => new
|
||||
{
|
||||
client_id = table.Column<int>(type: "integer", nullable: false)
|
||||
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
|
||||
client_name = table.Column<string>(type: "character varying(50)", maxLength: 50, nullable: false, defaultValue: "empty_string"),
|
||||
client_email = table.Column<string>(type: "character varying(40)", maxLength: 40, nullable: false),
|
||||
client_password = table.Column<string>(type: "character varying(32)", maxLength: 32, nullable: false, defaultValue: "empty_string")
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_client", x => x.client_id);
|
||||
});
|
||||
|
||||
migrationBuilder.CreateTable(
|
||||
name: "employee",
|
||||
columns: table => new
|
||||
{
|
||||
employee_id = table.Column<int>(type: "integer", nullable: false)
|
||||
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
|
||||
employee_name = table.Column<string>(type: "character varying(50)", maxLength: 50, nullable: false, defaultValue: "empty_string"),
|
||||
employee_email = table.Column<string>(type: "character varying(40)", maxLength: 40, nullable: false),
|
||||
employee_password = table.Column<string>(type: "character varying(32)", maxLength: 32, nullable: false, defaultValue: "empty_string")
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_employee", x => x.employee_id);
|
||||
});
|
||||
|
||||
migrationBuilder.CreateTable(
|
||||
name: "make",
|
||||
columns: table => new
|
||||
{
|
||||
make_id = table.Column<int>(type: "integer", nullable: false)
|
||||
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
|
||||
make_name = table.Column<string>(type: "character varying(50)", maxLength: 50, nullable: false)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_make", x => x.make_id);
|
||||
});
|
||||
|
||||
migrationBuilder.CreateTable(
|
||||
name: "sale",
|
||||
columns: table => new
|
||||
{
|
||||
sale_id = table.Column<int>(type: "integer", nullable: false)
|
||||
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
|
||||
sale_time = table.Column<DateTime>(type: "timestamp with time zone", nullable: false),
|
||||
sale_cost = table.Column<int>(type: "integer", nullable: false, defaultValue: -1),
|
||||
sale_client_id = table.Column<int>(type: "integer", nullable: true),
|
||||
sale_employee_id = table.Column<int>(type: "integer", nullable: true)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_sale", x => x.sale_id);
|
||||
table.ForeignKey(
|
||||
name: "FK_sale_client_sale_client_id",
|
||||
column: x => x.sale_client_id,
|
||||
principalTable: "client",
|
||||
principalColumn: "client_id",
|
||||
onDelete: ReferentialAction.SetNull);
|
||||
table.ForeignKey(
|
||||
name: "FK_sale_employee_sale_employee_id",
|
||||
column: x => x.sale_employee_id,
|
||||
principalTable: "employee",
|
||||
principalColumn: "employee_id",
|
||||
onDelete: ReferentialAction.SetNull);
|
||||
});
|
||||
|
||||
migrationBuilder.CreateTable(
|
||||
name: "model",
|
||||
columns: table => new
|
||||
{
|
||||
model_id = table.Column<int>(type: "integer", nullable: false)
|
||||
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
|
||||
model_name = table.Column<string>(type: "character varying(50)", maxLength: 50, nullable: false),
|
||||
model_price = table.Column<int>(type: "integer", nullable: false, defaultValue: -1),
|
||||
model_make_id = table.Column<int>(type: "integer", nullable: false)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_model", x => x.model_id);
|
||||
table.ForeignKey(
|
||||
name: "FK_model_make_model_make_id",
|
||||
column: x => x.model_make_id,
|
||||
principalTable: "make",
|
||||
principalColumn: "make_id",
|
||||
onDelete: ReferentialAction.Restrict);
|
||||
});
|
||||
|
||||
migrationBuilder.CreateTable(
|
||||
name: "service",
|
||||
columns: table => new
|
||||
{
|
||||
service_id = table.Column<int>(type: "integer", nullable: false)
|
||||
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
|
||||
service_name = table.Column<string>(type: "character varying(50)", maxLength: 50, nullable: false),
|
||||
service_cost = table.Column<int>(type: "integer", nullable: false, defaultValue: -1),
|
||||
SaleId = table.Column<int>(type: "integer", nullable: true)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_service", x => x.service_id);
|
||||
table.ForeignKey(
|
||||
name: "FK_service_sale_SaleId",
|
||||
column: x => x.SaleId,
|
||||
principalTable: "sale",
|
||||
principalColumn: "sale_id");
|
||||
});
|
||||
|
||||
migrationBuilder.CreateTable(
|
||||
name: "car",
|
||||
columns: table => new
|
||||
{
|
||||
car_id = table.Column<int>(type: "integer", nullable: false)
|
||||
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
|
||||
car_color = table.Column<string>(type: "character varying(50)", maxLength: 50, nullable: false, defaultValue: "empty_string"),
|
||||
car_releasedate = table.Column<DateTime>(type: "timestamp with time zone", nullable: false),
|
||||
car_model_id = table.Column<int>(type: "integer", nullable: false),
|
||||
SaleId = table.Column<int>(type: "integer", nullable: true)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_car", x => x.car_id);
|
||||
table.ForeignKey(
|
||||
name: "FK_car_model_car_model_id",
|
||||
column: x => x.car_model_id,
|
||||
principalTable: "model",
|
||||
principalColumn: "model_id",
|
||||
onDelete: ReferentialAction.Restrict);
|
||||
table.ForeignKey(
|
||||
name: "FK_car_sale_SaleId",
|
||||
column: x => x.SaleId,
|
||||
principalTable: "sale",
|
||||
principalColumn: "sale_id");
|
||||
});
|
||||
|
||||
migrationBuilder.CreateTable(
|
||||
name: "sale_service",
|
||||
columns: table => new
|
||||
{
|
||||
sale_id = table.Column<int>(type: "integer", nullable: false),
|
||||
service_id = table.Column<int>(type: "integer", nullable: false)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_sale_service", x => new { x.sale_id, x.service_id });
|
||||
table.ForeignKey(
|
||||
name: "FK_sale_service_sale_sale_id",
|
||||
column: x => x.sale_id,
|
||||
principalTable: "sale",
|
||||
principalColumn: "sale_id",
|
||||
onDelete: ReferentialAction.Restrict);
|
||||
table.ForeignKey(
|
||||
name: "FK_sale_service_service_service_id",
|
||||
column: x => x.service_id,
|
||||
principalTable: "service",
|
||||
principalColumn: "service_id",
|
||||
onDelete: ReferentialAction.Cascade);
|
||||
});
|
||||
|
||||
migrationBuilder.CreateTable(
|
||||
name: "sale_car",
|
||||
columns: table => new
|
||||
{
|
||||
sale_id = table.Column<int>(type: "integer", nullable: false),
|
||||
car_id = table.Column<int>(type: "integer", nullable: false)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_sale_car", x => new { x.sale_id, x.car_id });
|
||||
table.ForeignKey(
|
||||
name: "FK_sale_car_car_car_id",
|
||||
column: x => x.car_id,
|
||||
principalTable: "car",
|
||||
principalColumn: "car_id",
|
||||
onDelete: ReferentialAction.Cascade);
|
||||
table.ForeignKey(
|
||||
name: "FK_sale_car_sale_sale_id",
|
||||
column: x => x.sale_id,
|
||||
principalTable: "sale",
|
||||
principalColumn: "sale_id",
|
||||
onDelete: ReferentialAction.Restrict);
|
||||
});
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_car_car_model_id",
|
||||
table: "car",
|
||||
column: "car_model_id");
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_car_SaleId",
|
||||
table: "car",
|
||||
column: "SaleId");
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_client_client_email",
|
||||
table: "client",
|
||||
column: "client_email",
|
||||
unique: true);
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_employee_employee_email",
|
||||
table: "employee",
|
||||
column: "employee_email",
|
||||
unique: true);
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_make_make_name",
|
||||
table: "make",
|
||||
column: "make_name",
|
||||
unique: true);
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_model_model_make_id",
|
||||
table: "model",
|
||||
column: "model_make_id");
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_model_model_name",
|
||||
table: "model",
|
||||
column: "model_name",
|
||||
unique: true);
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_sale_sale_client_id",
|
||||
table: "sale",
|
||||
column: "sale_client_id");
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_sale_sale_employee_id",
|
||||
table: "sale",
|
||||
column: "sale_employee_id");
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_sale_car_car_id",
|
||||
table: "sale_car",
|
||||
column: "car_id");
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_sale_service_service_id",
|
||||
table: "sale_service",
|
||||
column: "service_id");
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_service_SaleId",
|
||||
table: "service",
|
||||
column: "SaleId");
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_service_service_name",
|
||||
table: "service",
|
||||
column: "service_name",
|
||||
unique: true);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override void Down(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.DropTable(
|
||||
name: "sale_car");
|
||||
|
||||
migrationBuilder.DropTable(
|
||||
name: "sale_service");
|
||||
|
||||
migrationBuilder.DropTable(
|
||||
name: "car");
|
||||
|
||||
migrationBuilder.DropTable(
|
||||
name: "service");
|
||||
|
||||
migrationBuilder.DropTable(
|
||||
name: "model");
|
||||
|
||||
migrationBuilder.DropTable(
|
||||
name: "sale");
|
||||
|
||||
migrationBuilder.DropTable(
|
||||
name: "make");
|
||||
|
||||
migrationBuilder.DropTable(
|
||||
name: "client");
|
||||
|
||||
migrationBuilder.DropTable(
|
||||
name: "employee");
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,433 @@
|
||||
// <auto-generated />
|
||||
using System;
|
||||
using CarShowroomDatabaseStorage;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Infrastructure;
|
||||
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
|
||||
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace CarShowroomDatabaseStorage.Migrations
|
||||
{
|
||||
[DbContext(typeof(CarShowroomDatabase))]
|
||||
partial class CarShowroomDatabaseModelSnapshot : ModelSnapshot
|
||||
{
|
||||
protected override void BuildModel(ModelBuilder modelBuilder)
|
||||
{
|
||||
#pragma warning disable 612, 618
|
||||
modelBuilder
|
||||
.HasAnnotation("ProductVersion", "7.0.18")
|
||||
.HasAnnotation("Relational:MaxIdentifierLength", 63);
|
||||
|
||||
NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder);
|
||||
|
||||
modelBuilder.Entity("CarShowroomDatabaseStorage.Entities.Car", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("integer")
|
||||
.HasColumnName("car_id");
|
||||
|
||||
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<string>("Color")
|
||||
.IsRequired()
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasMaxLength(50)
|
||||
.HasColumnType("character varying(50)")
|
||||
.HasDefaultValue("empty_string")
|
||||
.HasColumnName("car_color");
|
||||
|
||||
b.Property<int>("ModelId")
|
||||
.HasColumnType("integer")
|
||||
.HasColumnName("car_model_id");
|
||||
|
||||
b.Property<DateTime>("ReleaseDate")
|
||||
.HasColumnType("timestamp with time zone")
|
||||
.HasColumnName("car_releasedate");
|
||||
|
||||
b.Property<int?>("SaleId")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("ModelId");
|
||||
|
||||
b.HasIndex("SaleId");
|
||||
|
||||
b.ToTable("car");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("CarShowroomDatabaseStorage.Entities.Client", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("integer")
|
||||
.HasColumnName("client_id");
|
||||
|
||||
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<string>("Email")
|
||||
.IsRequired()
|
||||
.HasMaxLength(40)
|
||||
.HasColumnType("character varying(40)")
|
||||
.HasColumnName("client_email");
|
||||
|
||||
b.Property<string>("Name")
|
||||
.IsRequired()
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasMaxLength(50)
|
||||
.HasColumnType("character varying(50)")
|
||||
.HasDefaultValue("empty_string")
|
||||
.HasColumnName("client_name");
|
||||
|
||||
b.Property<string>("Password")
|
||||
.IsRequired()
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasMaxLength(32)
|
||||
.HasColumnType("character varying(32)")
|
||||
.HasDefaultValue("empty_string")
|
||||
.HasColumnName("client_password");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("Email")
|
||||
.IsUnique();
|
||||
|
||||
b.ToTable("client");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("CarShowroomDatabaseStorage.Entities.Employee", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("integer")
|
||||
.HasColumnName("employee_id");
|
||||
|
||||
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<string>("Email")
|
||||
.IsRequired()
|
||||
.HasMaxLength(40)
|
||||
.HasColumnType("character varying(40)")
|
||||
.HasColumnName("employee_email");
|
||||
|
||||
b.Property<string>("Name")
|
||||
.IsRequired()
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasMaxLength(50)
|
||||
.HasColumnType("character varying(50)")
|
||||
.HasDefaultValue("empty_string")
|
||||
.HasColumnName("employee_name");
|
||||
|
||||
b.Property<string>("Password")
|
||||
.IsRequired()
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasMaxLength(32)
|
||||
.HasColumnType("character varying(32)")
|
||||
.HasDefaultValue("empty_string")
|
||||
.HasColumnName("employee_password");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("Email")
|
||||
.IsUnique();
|
||||
|
||||
b.ToTable("employee");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("CarShowroomDatabaseStorage.Entities.Make", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("integer")
|
||||
.HasColumnName("make_id");
|
||||
|
||||
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<string>("Name")
|
||||
.IsRequired()
|
||||
.HasMaxLength(50)
|
||||
.HasColumnType("character varying(50)")
|
||||
.HasColumnName("make_name");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("Name")
|
||||
.IsUnique();
|
||||
|
||||
b.ToTable("make");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("CarShowroomDatabaseStorage.Entities.Model", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("integer")
|
||||
.HasColumnName("model_id");
|
||||
|
||||
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<int>("MakeId")
|
||||
.HasColumnType("integer")
|
||||
.HasColumnName("model_make_id");
|
||||
|
||||
b.Property<string>("Name")
|
||||
.IsRequired()
|
||||
.HasMaxLength(50)
|
||||
.HasColumnType("character varying(50)")
|
||||
.HasColumnName("model_name");
|
||||
|
||||
b.Property<int>("Price")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("integer")
|
||||
.HasDefaultValue(-1)
|
||||
.HasColumnName("model_price");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("MakeId");
|
||||
|
||||
b.HasIndex("Name")
|
||||
.IsUnique();
|
||||
|
||||
b.ToTable("model");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("CarShowroomDatabaseStorage.Entities.Sale", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("integer")
|
||||
.HasColumnName("sale_id");
|
||||
|
||||
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<int?>("ClientId")
|
||||
.HasColumnType("integer")
|
||||
.HasColumnName("sale_client_id");
|
||||
|
||||
b.Property<int>("Cost")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("integer")
|
||||
.HasDefaultValue(-1)
|
||||
.HasColumnName("sale_cost");
|
||||
|
||||
b.Property<int?>("EmployeeId")
|
||||
.HasColumnType("integer")
|
||||
.HasColumnName("sale_employee_id");
|
||||
|
||||
b.Property<DateTime>("SaleTime")
|
||||
.HasColumnType("timestamp with time zone")
|
||||
.HasColumnName("sale_time");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("ClientId");
|
||||
|
||||
b.HasIndex("EmployeeId");
|
||||
|
||||
b.ToTable("sale");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("CarShowroomDatabaseStorage.Entities.SaleCar", b =>
|
||||
{
|
||||
b.Property<int>("SaleId")
|
||||
.HasColumnType("integer")
|
||||
.HasColumnName("sale_id");
|
||||
|
||||
b.Property<int>("CarId")
|
||||
.HasColumnType("integer")
|
||||
.HasColumnName("car_id");
|
||||
|
||||
b.HasKey("SaleId", "CarId");
|
||||
|
||||
b.HasIndex("CarId");
|
||||
|
||||
b.ToTable("sale_car");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("CarShowroomDatabaseStorage.Entities.SaleService", b =>
|
||||
{
|
||||
b.Property<int>("SaleId")
|
||||
.HasColumnType("integer")
|
||||
.HasColumnName("sale_id");
|
||||
|
||||
b.Property<int>("ServiceId")
|
||||
.HasColumnType("integer")
|
||||
.HasColumnName("service_id");
|
||||
|
||||
b.HasKey("SaleId", "ServiceId");
|
||||
|
||||
b.HasIndex("ServiceId");
|
||||
|
||||
b.ToTable("sale_service");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("CarShowroomDatabaseStorage.Entities.Service", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("integer")
|
||||
.HasColumnName("service_id");
|
||||
|
||||
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<int>("Cost")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("integer")
|
||||
.HasDefaultValue(-1)
|
||||
.HasColumnName("service_cost");
|
||||
|
||||
b.Property<string>("Name")
|
||||
.IsRequired()
|
||||
.HasMaxLength(50)
|
||||
.HasColumnType("character varying(50)")
|
||||
.HasColumnName("service_name");
|
||||
|
||||
b.Property<int?>("SaleId")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("Name")
|
||||
.IsUnique();
|
||||
|
||||
b.HasIndex("SaleId");
|
||||
|
||||
b.ToTable("service");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("CarShowroomDatabaseStorage.Entities.Car", b =>
|
||||
{
|
||||
b.HasOne("CarShowroomDatabaseStorage.Entities.Model", "Model")
|
||||
.WithMany("Cars")
|
||||
.HasForeignKey("ModelId")
|
||||
.OnDelete(DeleteBehavior.Restrict)
|
||||
.IsRequired();
|
||||
|
||||
b.HasOne("CarShowroomDatabaseStorage.Entities.Sale", null)
|
||||
.WithMany("Cars")
|
||||
.HasForeignKey("SaleId");
|
||||
|
||||
b.Navigation("Model");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("CarShowroomDatabaseStorage.Entities.Model", b =>
|
||||
{
|
||||
b.HasOne("CarShowroomDatabaseStorage.Entities.Make", "Make")
|
||||
.WithMany("Models")
|
||||
.HasForeignKey("MakeId")
|
||||
.OnDelete(DeleteBehavior.Restrict)
|
||||
.IsRequired();
|
||||
|
||||
b.Navigation("Make");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("CarShowroomDatabaseStorage.Entities.Sale", b =>
|
||||
{
|
||||
b.HasOne("CarShowroomDatabaseStorage.Entities.Client", "Client")
|
||||
.WithMany("Sales")
|
||||
.HasForeignKey("ClientId")
|
||||
.OnDelete(DeleteBehavior.SetNull);
|
||||
|
||||
b.HasOne("CarShowroomDatabaseStorage.Entities.Employee", "Employee")
|
||||
.WithMany("Sales")
|
||||
.HasForeignKey("EmployeeId")
|
||||
.OnDelete(DeleteBehavior.SetNull);
|
||||
|
||||
b.Navigation("Client");
|
||||
|
||||
b.Navigation("Employee");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("CarShowroomDatabaseStorage.Entities.SaleCar", b =>
|
||||
{
|
||||
b.HasOne("CarShowroomDatabaseStorage.Entities.Car", "Car")
|
||||
.WithMany("SaleCars")
|
||||
.HasForeignKey("CarId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.HasOne("CarShowroomDatabaseStorage.Entities.Sale", "Sale")
|
||||
.WithMany("SaleCars")
|
||||
.HasForeignKey("SaleId")
|
||||
.OnDelete(DeleteBehavior.Restrict)
|
||||
.IsRequired();
|
||||
|
||||
b.Navigation("Car");
|
||||
|
||||
b.Navigation("Sale");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("CarShowroomDatabaseStorage.Entities.SaleService", b =>
|
||||
{
|
||||
b.HasOne("CarShowroomDatabaseStorage.Entities.Sale", "Sale")
|
||||
.WithMany("SaleServices")
|
||||
.HasForeignKey("SaleId")
|
||||
.OnDelete(DeleteBehavior.Restrict)
|
||||
.IsRequired();
|
||||
|
||||
b.HasOne("CarShowroomDatabaseStorage.Entities.Service", "Service")
|
||||
.WithMany("SaleServices")
|
||||
.HasForeignKey("ServiceId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.Navigation("Sale");
|
||||
|
||||
b.Navigation("Service");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("CarShowroomDatabaseStorage.Entities.Service", b =>
|
||||
{
|
||||
b.HasOne("CarShowroomDatabaseStorage.Entities.Sale", null)
|
||||
.WithMany("Services")
|
||||
.HasForeignKey("SaleId");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("CarShowroomDatabaseStorage.Entities.Car", b =>
|
||||
{
|
||||
b.Navigation("SaleCars");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("CarShowroomDatabaseStorage.Entities.Client", b =>
|
||||
{
|
||||
b.Navigation("Sales");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("CarShowroomDatabaseStorage.Entities.Employee", b =>
|
||||
{
|
||||
b.Navigation("Sales");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("CarShowroomDatabaseStorage.Entities.Make", b =>
|
||||
{
|
||||
b.Navigation("Models");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("CarShowroomDatabaseStorage.Entities.Model", b =>
|
||||
{
|
||||
b.Navigation("Cars");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("CarShowroomDatabaseStorage.Entities.Sale", b =>
|
||||
{
|
||||
b.Navigation("Cars");
|
||||
|
||||
b.Navigation("SaleCars");
|
||||
|
||||
b.Navigation("SaleServices");
|
||||
|
||||
b.Navigation("Services");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("CarShowroomDatabaseStorage.Entities.Service", b =>
|
||||
{
|
||||
b.Navigation("SaleServices");
|
||||
});
|
||||
#pragma warning restore 612, 618
|
||||
}
|
||||
}
|
||||
}
|
Binary file not shown.
BIN
ERD/car-showroom_2.vpp.bak_004d
Normal file
BIN
ERD/car-showroom_2.vpp.bak_004d
Normal file
Binary file not shown.
BIN
ERD/car-showroom_2.vpp.bak_005d
Normal file
BIN
ERD/car-showroom_2.vpp.bak_005d
Normal file
Binary file not shown.
BIN
ERD/car-showroom_2.vpp.bak_006d
Normal file
BIN
ERD/car-showroom_2.vpp.bak_006d
Normal file
Binary file not shown.
Loading…
Reference in New Issue
Block a user