some changes
This commit is contained in:
parent
aa93c93775
commit
73c4800cad
@ -46,6 +46,7 @@ namespace CarShowroomBusinessLogic.BusinessLogic
|
|||||||
|
|
||||||
public bool Create(CarDto model)
|
public bool Create(CarDto model)
|
||||||
{
|
{
|
||||||
|
model.IsSaled = false;
|
||||||
CheckModel(model);
|
CheckModel(model);
|
||||||
if (_carStorage.Insert(model) == null)
|
if (_carStorage.Insert(model) == null)
|
||||||
{
|
{
|
||||||
|
@ -12,5 +12,6 @@ namespace CarShowroomContracts.AbstractModels
|
|||||||
string Color { get; }
|
string Color { get; }
|
||||||
DateTime ReleaseDate { get; }
|
DateTime ReleaseDate { get; }
|
||||||
int ModelId { get; }
|
int ModelId { get; }
|
||||||
|
bool IsSaled { get; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -13,12 +13,14 @@ namespace CarShowroomDataModels.Dtos
|
|||||||
public string Color { get; set; }
|
public string Color { get; set; }
|
||||||
public DateTime ReleaseDate { get; set; }
|
public DateTime ReleaseDate { get; set; }
|
||||||
public int ModelId { get; set; }
|
public int ModelId { get; set; }
|
||||||
|
public bool IsSaled { get; set; }
|
||||||
public CarDto(ICar model)
|
public CarDto(ICar model)
|
||||||
{
|
{
|
||||||
Id = model.Id;
|
Id = model.Id;
|
||||||
Color = model.Color;
|
Color = model.Color;
|
||||||
ReleaseDate = model.ReleaseDate;
|
ReleaseDate = model.ReleaseDate;
|
||||||
ModelId = model.ModelId;
|
ModelId = model.ModelId;
|
||||||
|
IsSaled = model.IsSaled;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -17,6 +17,7 @@ namespace CarShowroomDataModels.Dtos
|
|||||||
Id = model.Id;
|
Id = model.Id;
|
||||||
Name = model.Name;
|
Name = model.Name;
|
||||||
PhoneNumber = model.PhoneNumber;
|
PhoneNumber = model.PhoneNumber;
|
||||||
}
|
}
|
||||||
}
|
public ClientDto() {}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -25,6 +25,7 @@ namespace CarShowroomDataModels.Dtos
|
|||||||
EmployeeId = model.EmployeeId;
|
EmployeeId = model.EmployeeId;
|
||||||
CarIds = model.CarIds;
|
CarIds = model.CarIds;
|
||||||
ServiceIds = model.ServiceIds;
|
ServiceIds = model.ServiceIds;
|
||||||
}
|
}
|
||||||
}
|
public SaleDto() {}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -12,7 +12,9 @@ namespace CarShowroomDataModels.Views
|
|||||||
{
|
{
|
||||||
[DisplayName("Номер машины")]
|
[DisplayName("Номер машины")]
|
||||||
public int Id { get; set; }
|
public int Id { get; set; }
|
||||||
[DisplayName("Цвет")]
|
[DisplayName("Название машины")]
|
||||||
|
public string Name { get; set; } = string.Empty;
|
||||||
|
[DisplayName("Цвет")]
|
||||||
public string Color { get; set; }
|
public string Color { get; set; }
|
||||||
[DisplayName("Дата производства")]
|
[DisplayName("Дата производства")]
|
||||||
public DateTime ReleaseDate { get; set; }
|
public DateTime ReleaseDate { get; set; }
|
||||||
@ -23,12 +25,15 @@ namespace CarShowroomDataModels.Views
|
|||||||
public int ModelPrice { get; set; }
|
public int ModelPrice { get; set; }
|
||||||
[DisplayName("Марка")]
|
[DisplayName("Марка")]
|
||||||
public string MakeName { get; set; } = string.Empty;
|
public string MakeName { get; set; } = string.Empty;
|
||||||
|
[DisplayName("Продана")]
|
||||||
|
public bool IsSaled { get; set; }
|
||||||
public CarView(ICar model)
|
public CarView(ICar model)
|
||||||
{
|
{
|
||||||
Id = model.Id;
|
Id = model.Id;
|
||||||
Color = model.Color;
|
Color = model.Color;
|
||||||
ReleaseDate = model.ReleaseDate;
|
ReleaseDate = model.ReleaseDate;
|
||||||
ModelId = model.ModelId;
|
ModelId = model.ModelId;
|
||||||
|
IsSaled = model.IsSaled;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -33,6 +33,7 @@ namespace CarShowroomDatabaseStorage
|
|||||||
modelBuilder.Entity<Employee>().Property(e => e.Name).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<Employee>().Property(e => e.Password).HasDefaultValue("empty_string");
|
||||||
modelBuilder.Entity<Car>().Property(c => c.Color).HasDefaultValue("empty_string");
|
modelBuilder.Entity<Car>().Property(c => c.Color).HasDefaultValue("empty_string");
|
||||||
|
modelBuilder.Entity<Car>().Property(c => c.IsSaled).HasDefaultValue(false);
|
||||||
modelBuilder.Entity<Service>().Property(c => c.Cost).HasDefaultValue(-1);
|
modelBuilder.Entity<Service>().Property(c => c.Cost).HasDefaultValue(-1);
|
||||||
modelBuilder.Entity<Model>().Property(c => c.Price).HasDefaultValue(-1);
|
modelBuilder.Entity<Model>().Property(c => c.Price).HasDefaultValue(-1);
|
||||||
modelBuilder.Entity<Sale>().Property(c => c.Cost).HasDefaultValue(-1);
|
modelBuilder.Entity<Sale>().Property(c => c.Cost).HasDefaultValue(-1);
|
||||||
@ -56,11 +57,11 @@ namespace CarShowroomDatabaseStorage
|
|||||||
modelBuilder.Entity<SaleService>()
|
modelBuilder.Entity<SaleService>()
|
||||||
.HasOne(m => m.Sale)
|
.HasOne(m => m.Sale)
|
||||||
.WithMany(m => m.SaleServices)
|
.WithMany(m => m.SaleServices)
|
||||||
.OnDelete(DeleteBehavior.Restrict);
|
.OnDelete(DeleteBehavior.Cascade);
|
||||||
modelBuilder.Entity<SaleCar>()
|
modelBuilder.Entity<SaleCar>()
|
||||||
.HasOne(m => m.Sale)
|
.HasOne(m => m.Sale)
|
||||||
.WithMany(m => m.SaleCars)
|
.WithMany(m => m.SaleCars)
|
||||||
.OnDelete(DeleteBehavior.Restrict);
|
.OnDelete(DeleteBehavior.Cascade);
|
||||||
modelBuilder.Entity<SaleService>()
|
modelBuilder.Entity<SaleService>()
|
||||||
.HasOne(m => m.Service)
|
.HasOne(m => m.Service)
|
||||||
.WithMany(m => m.SaleServices)
|
.WithMany(m => m.SaleServices)
|
||||||
|
@ -23,6 +23,9 @@ namespace CarShowroomDatabaseStorage.Entities
|
|||||||
[Column("car_releasedate")]
|
[Column("car_releasedate")]
|
||||||
public DateTime ReleaseDate { get; private set; }
|
public DateTime ReleaseDate { get; private set; }
|
||||||
[Required]
|
[Required]
|
||||||
|
[Column("car_issaled")]
|
||||||
|
public bool IsSaled { get; private set; }
|
||||||
|
[Required]
|
||||||
[Column("car_model_id")]
|
[Column("car_model_id")]
|
||||||
public int ModelId { get; private set; }
|
public int ModelId { get; private set; }
|
||||||
public virtual Model? Model { get; set; }
|
public virtual Model? Model { get; set; }
|
||||||
@ -36,6 +39,7 @@ namespace CarShowroomDatabaseStorage.Entities
|
|||||||
Color = car.Color;
|
Color = car.Color;
|
||||||
ReleaseDate = DateTime.Now;
|
ReleaseDate = DateTime.Now;
|
||||||
ModelId = car.ModelId;
|
ModelId = car.ModelId;
|
||||||
|
IsSaled = car.IsSaled;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Car? Create(ICar car)
|
public static Car? Create(ICar car)
|
||||||
@ -60,6 +64,7 @@ namespace CarShowroomDatabaseStorage.Entities
|
|||||||
car.ModelPrice = Model?.Price ?? 0;
|
car.ModelPrice = Model?.Price ?? 0;
|
||||||
car.ModelName = Model?.Name ?? string.Empty;
|
car.ModelName = Model?.Name ?? string.Empty;
|
||||||
car.MakeName = Model?.Make?.Name ?? string.Empty;
|
car.MakeName = Model?.Make?.Name ?? string.Empty;
|
||||||
|
car.Name = car.Color + " " + car.MakeName + " " + car.ModelName;
|
||||||
return car;
|
return car;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
409
CarShowroom/CarShowroomDatabaseStorage/Migrations/20240512174258_changeCarsAndSale.Designer.cs
generated
Normal file
409
CarShowroom/CarShowroomDatabaseStorage/Migrations/20240512174258_changeCarsAndSale.Designer.cs
generated
Normal file
@ -0,0 +1,409 @@
|
|||||||
|
// <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("20240512174258_changeCarsAndSale")]
|
||||||
|
partial class changeCarsAndSale
|
||||||
|
{
|
||||||
|
/// <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<bool>("IsSaled")
|
||||||
|
.ValueGeneratedOnAdd()
|
||||||
|
.HasColumnType("boolean")
|
||||||
|
.HasDefaultValue(false)
|
||||||
|
.HasColumnName("car_issaled");
|
||||||
|
|
||||||
|
b.Property<int>("ModelId")
|
||||||
|
.HasColumnType("integer")
|
||||||
|
.HasColumnName("car_model_id");
|
||||||
|
|
||||||
|
b.Property<DateTime>("ReleaseDate")
|
||||||
|
.HasColumnType("timestamp with time zone")
|
||||||
|
.HasColumnName("car_releasedate");
|
||||||
|
|
||||||
|
b.HasKey("Id");
|
||||||
|
|
||||||
|
b.HasIndex("ModelId");
|
||||||
|
|
||||||
|
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>("Name")
|
||||||
|
.IsRequired()
|
||||||
|
.ValueGeneratedOnAdd()
|
||||||
|
.HasMaxLength(50)
|
||||||
|
.HasColumnType("character varying(50)")
|
||||||
|
.HasDefaultValue("empty_string")
|
||||||
|
.HasColumnName("client_name");
|
||||||
|
|
||||||
|
b.Property<string>("PhoneNumber")
|
||||||
|
.IsRequired()
|
||||||
|
.HasMaxLength(25)
|
||||||
|
.HasColumnType("character varying(25)")
|
||||||
|
.HasColumnName("client_phonenumber");
|
||||||
|
|
||||||
|
b.HasKey("Id");
|
||||||
|
|
||||||
|
b.HasIndex("PhoneNumber")
|
||||||
|
.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.HasKey("Id");
|
||||||
|
|
||||||
|
b.HasIndex("Name")
|
||||||
|
.IsUnique();
|
||||||
|
|
||||||
|
b.ToTable("service");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("CarShowroomDatabaseStorage.Entities.Car", b =>
|
||||||
|
{
|
||||||
|
b.HasOne("CarShowroomDatabaseStorage.Entities.Model", "Model")
|
||||||
|
.WithMany("Cars")
|
||||||
|
.HasForeignKey("ModelId")
|
||||||
|
.OnDelete(DeleteBehavior.Restrict)
|
||||||
|
.IsRequired();
|
||||||
|
|
||||||
|
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.Cascade)
|
||||||
|
.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.Cascade)
|
||||||
|
.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.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("SaleCars");
|
||||||
|
|
||||||
|
b.Navigation("SaleServices");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("CarShowroomDatabaseStorage.Entities.Service", b =>
|
||||||
|
{
|
||||||
|
b.Navigation("SaleServices");
|
||||||
|
});
|
||||||
|
#pragma warning restore 612, 618
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,77 @@
|
|||||||
|
using Microsoft.EntityFrameworkCore.Migrations;
|
||||||
|
|
||||||
|
#nullable disable
|
||||||
|
|
||||||
|
namespace CarShowroomDatabaseStorage.Migrations
|
||||||
|
{
|
||||||
|
/// <inheritdoc />
|
||||||
|
public partial class changeCarsAndSale : Migration
|
||||||
|
{
|
||||||
|
/// <inheritdoc />
|
||||||
|
protected override void Up(MigrationBuilder migrationBuilder)
|
||||||
|
{
|
||||||
|
migrationBuilder.DropForeignKey(
|
||||||
|
name: "FK_sale_car_sale_sale_id",
|
||||||
|
table: "sale_car");
|
||||||
|
|
||||||
|
migrationBuilder.DropForeignKey(
|
||||||
|
name: "FK_sale_service_sale_sale_id",
|
||||||
|
table: "sale_service");
|
||||||
|
|
||||||
|
migrationBuilder.AddColumn<bool>(
|
||||||
|
name: "car_issaled",
|
||||||
|
table: "car",
|
||||||
|
type: "boolean",
|
||||||
|
nullable: false,
|
||||||
|
defaultValue: false);
|
||||||
|
|
||||||
|
migrationBuilder.AddForeignKey(
|
||||||
|
name: "FK_sale_car_sale_sale_id",
|
||||||
|
table: "sale_car",
|
||||||
|
column: "sale_id",
|
||||||
|
principalTable: "sale",
|
||||||
|
principalColumn: "sale_id",
|
||||||
|
onDelete: ReferentialAction.Cascade);
|
||||||
|
|
||||||
|
migrationBuilder.AddForeignKey(
|
||||||
|
name: "FK_sale_service_sale_sale_id",
|
||||||
|
table: "sale_service",
|
||||||
|
column: "sale_id",
|
||||||
|
principalTable: "sale",
|
||||||
|
principalColumn: "sale_id",
|
||||||
|
onDelete: ReferentialAction.Cascade);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <inheritdoc />
|
||||||
|
protected override void Down(MigrationBuilder migrationBuilder)
|
||||||
|
{
|
||||||
|
migrationBuilder.DropForeignKey(
|
||||||
|
name: "FK_sale_car_sale_sale_id",
|
||||||
|
table: "sale_car");
|
||||||
|
|
||||||
|
migrationBuilder.DropForeignKey(
|
||||||
|
name: "FK_sale_service_sale_sale_id",
|
||||||
|
table: "sale_service");
|
||||||
|
|
||||||
|
migrationBuilder.DropColumn(
|
||||||
|
name: "car_issaled",
|
||||||
|
table: "car");
|
||||||
|
|
||||||
|
migrationBuilder.AddForeignKey(
|
||||||
|
name: "FK_sale_car_sale_sale_id",
|
||||||
|
table: "sale_car",
|
||||||
|
column: "sale_id",
|
||||||
|
principalTable: "sale",
|
||||||
|
principalColumn: "sale_id",
|
||||||
|
onDelete: ReferentialAction.Restrict);
|
||||||
|
|
||||||
|
migrationBuilder.AddForeignKey(
|
||||||
|
name: "FK_sale_service_sale_sale_id",
|
||||||
|
table: "sale_service",
|
||||||
|
column: "sale_id",
|
||||||
|
principalTable: "sale",
|
||||||
|
principalColumn: "sale_id",
|
||||||
|
onDelete: ReferentialAction.Restrict);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -39,6 +39,12 @@ namespace CarShowroomDatabaseStorage.Migrations
|
|||||||
.HasDefaultValue("empty_string")
|
.HasDefaultValue("empty_string")
|
||||||
.HasColumnName("car_color");
|
.HasColumnName("car_color");
|
||||||
|
|
||||||
|
b.Property<bool>("IsSaled")
|
||||||
|
.ValueGeneratedOnAdd()
|
||||||
|
.HasColumnType("boolean")
|
||||||
|
.HasDefaultValue(false)
|
||||||
|
.HasColumnName("car_issaled");
|
||||||
|
|
||||||
b.Property<int>("ModelId")
|
b.Property<int>("ModelId")
|
||||||
.HasColumnType("integer")
|
.HasColumnType("integer")
|
||||||
.HasColumnName("car_model_id");
|
.HasColumnName("car_model_id");
|
||||||
@ -331,7 +337,7 @@ namespace CarShowroomDatabaseStorage.Migrations
|
|||||||
b.HasOne("CarShowroomDatabaseStorage.Entities.Sale", "Sale")
|
b.HasOne("CarShowroomDatabaseStorage.Entities.Sale", "Sale")
|
||||||
.WithMany("SaleCars")
|
.WithMany("SaleCars")
|
||||||
.HasForeignKey("SaleId")
|
.HasForeignKey("SaleId")
|
||||||
.OnDelete(DeleteBehavior.Restrict)
|
.OnDelete(DeleteBehavior.Cascade)
|
||||||
.IsRequired();
|
.IsRequired();
|
||||||
|
|
||||||
b.Navigation("Car");
|
b.Navigation("Car");
|
||||||
@ -344,7 +350,7 @@ namespace CarShowroomDatabaseStorage.Migrations
|
|||||||
b.HasOne("CarShowroomDatabaseStorage.Entities.Sale", "Sale")
|
b.HasOne("CarShowroomDatabaseStorage.Entities.Sale", "Sale")
|
||||||
.WithMany("SaleServices")
|
.WithMany("SaleServices")
|
||||||
.HasForeignKey("SaleId")
|
.HasForeignKey("SaleId")
|
||||||
.OnDelete(DeleteBehavior.Restrict)
|
.OnDelete(DeleteBehavior.Cascade)
|
||||||
.IsRequired();
|
.IsRequired();
|
||||||
|
|
||||||
b.HasOne("CarShowroomDatabaseStorage.Entities.Service", "Service")
|
b.HasOne("CarShowroomDatabaseStorage.Entities.Service", "Service")
|
||||||
|
@ -6,7 +6,7 @@ using System.Xml;
|
|||||||
|
|
||||||
namespace CarShowroomManagerApp
|
namespace CarShowroomManagerApp
|
||||||
{
|
{
|
||||||
public static class APIClient
|
public static class ApiClient
|
||||||
{
|
{
|
||||||
private static readonly HttpClient _client = new();
|
private static readonly HttpClient _client = new();
|
||||||
public static EmployeeView? Client { get; set; } = null;
|
public static EmployeeView? Client { get; set; } = null;
|
||||||
|
@ -1,4 +1,7 @@
|
|||||||
using CarShowroomManagerApp.Models;
|
using CarShowroomDataModels.Dtos;
|
||||||
|
using CarShowroomDataModels.Models;
|
||||||
|
using CarShowroomDataModels.Views;
|
||||||
|
using CarShowroomManagerApp.Models;
|
||||||
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.AspNetCore.Mvc;
|
||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
|
|
||||||
@ -13,17 +16,173 @@ namespace CarShowroomManagerApp.Controllers
|
|||||||
_logger = logger;
|
_logger = logger;
|
||||||
}
|
}
|
||||||
|
|
||||||
public IActionResult Index()
|
public IActionResult Index()
|
||||||
{
|
{
|
||||||
return View();
|
if (ApiClient.Client == null)
|
||||||
}
|
{
|
||||||
|
return Redirect("~/Home/Enter");
|
||||||
|
}
|
||||||
|
return
|
||||||
|
View(ApiClient.GetRequest<List<SaleView>>($"api/sale/getsalelist"));
|
||||||
|
}
|
||||||
|
|
||||||
public IActionResult Privacy()
|
public IActionResult Clients()
|
||||||
{
|
{
|
||||||
return View();
|
if (ApiClient.Client == null)
|
||||||
}
|
{
|
||||||
|
return Redirect("~/Home/Enter");
|
||||||
|
}
|
||||||
|
return
|
||||||
|
View(ApiClient.GetRequest<List<ClientView>>($"api/client/getclientlist"));
|
||||||
|
}
|
||||||
|
|
||||||
[ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)]
|
[HttpGet]
|
||||||
|
public IActionResult Privacy()
|
||||||
|
{
|
||||||
|
if (ApiClient.Client == null)
|
||||||
|
{
|
||||||
|
return Redirect("~/Home/Enter");
|
||||||
|
}
|
||||||
|
return View(ApiClient.Client);
|
||||||
|
}
|
||||||
|
|
||||||
|
[HttpGet]
|
||||||
|
public IActionResult Enter()
|
||||||
|
{
|
||||||
|
return View();
|
||||||
|
}
|
||||||
|
|
||||||
|
[HttpPost]
|
||||||
|
public void Enter(string login, string password)
|
||||||
|
{
|
||||||
|
if (string.IsNullOrEmpty(login) ||
|
||||||
|
string.IsNullOrEmpty(password))
|
||||||
|
{
|
||||||
|
throw new Exception("Введите логин и пароль");
|
||||||
|
}
|
||||||
|
ApiClient.Client = ApiClient.GetRequest<EmployeeView>($"api/employee/login?login={login}&password={password}");
|
||||||
|
if (ApiClient.Client == null)
|
||||||
|
{
|
||||||
|
throw new Exception("Неверный логин/пароль");
|
||||||
|
}
|
||||||
|
Response.Redirect("Index");
|
||||||
|
}
|
||||||
|
|
||||||
|
public IActionResult SaleCreate()
|
||||||
|
{
|
||||||
|
if (ApiClient.Client == null)
|
||||||
|
{
|
||||||
|
return Redirect("~/Home/Enter");
|
||||||
|
}
|
||||||
|
ViewBag.Cars = ApiClient.GetRequest<List<CarView>>("api/car/getcarlist");
|
||||||
|
ViewBag.Clients = ApiClient.GetRequest<List<CarView>>("api/client/getclientlist");
|
||||||
|
ViewBag.Services = ApiClient.GetRequest<List<CarView>>("api/service/getservicelist");
|
||||||
|
return View();
|
||||||
|
}
|
||||||
|
|
||||||
|
//[HttpPost]
|
||||||
|
//public void SaleCreate(int manufacture, int count)
|
||||||
|
//{
|
||||||
|
// if (APIClient.Client == null)
|
||||||
|
// {
|
||||||
|
// throw new Exception("Вы как суда попали? Суда вход только авторизованным");
|
||||||
|
// }
|
||||||
|
// if (count <= 0)
|
||||||
|
// {
|
||||||
|
// throw new Exception("Количество и сумма должны быть больше 0");
|
||||||
|
// }
|
||||||
|
// APIClient.PostRequest("api/main/createorder", new
|
||||||
|
// OrderBindingModel
|
||||||
|
// {
|
||||||
|
// ClientId = APIClient.Client.Id,
|
||||||
|
// ManufactureId = manufacture,
|
||||||
|
// Count = count,
|
||||||
|
// Sum = Calc(count, manufacture)
|
||||||
|
// });
|
||||||
|
// Response.Redirect("Index");
|
||||||
|
//}
|
||||||
|
|
||||||
|
public IActionResult ClientCreate()
|
||||||
|
{
|
||||||
|
if (ApiClient.Client == null)
|
||||||
|
{
|
||||||
|
return Redirect("~/Home/Enter");
|
||||||
|
}
|
||||||
|
return View();
|
||||||
|
}
|
||||||
|
|
||||||
|
[HttpPost]
|
||||||
|
public void ClientCreate(string phonenumber, string name)
|
||||||
|
{
|
||||||
|
if (string.IsNullOrEmpty(phonenumber) ||
|
||||||
|
string.IsNullOrEmpty(name))
|
||||||
|
{
|
||||||
|
throw new Exception("Введите номер телефона и ФИО");
|
||||||
|
}
|
||||||
|
ApiClient.PostRequest("api/client/createclient", new ClientDto
|
||||||
|
{
|
||||||
|
Name = name,
|
||||||
|
PhoneNumber = phonenumber
|
||||||
|
});
|
||||||
|
Response.Redirect("Enter");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
public IActionResult ClientUpdate()
|
||||||
|
{
|
||||||
|
if (ApiClient.Client == null)
|
||||||
|
{
|
||||||
|
return Redirect("~/Home/Enter");
|
||||||
|
}
|
||||||
|
ViewBag.Shops = ApiClient.GetRequest<List<ClientView>>("api/client/getclientlist");
|
||||||
|
return View();
|
||||||
|
}
|
||||||
|
|
||||||
|
[HttpPost]
|
||||||
|
public void ClientUpdate(string phonenumber, string name)
|
||||||
|
{
|
||||||
|
if (ApiClient.Client == null)
|
||||||
|
{
|
||||||
|
throw new Exception("Вы как суда попали? Суда вход только авторизованным");
|
||||||
|
}
|
||||||
|
if (string.IsNullOrEmpty(phonenumber) ||
|
||||||
|
string.IsNullOrEmpty(name))
|
||||||
|
{
|
||||||
|
throw new Exception("Введите логин, пароль и ФИО");
|
||||||
|
}
|
||||||
|
ApiClient.PostRequest("api/client/updateclient", new ClientDto
|
||||||
|
{
|
||||||
|
Id = ApiClient.Client.Id,
|
||||||
|
Name = name,
|
||||||
|
PhoneNumber = phonenumber
|
||||||
|
});
|
||||||
|
Response.Redirect("Index");
|
||||||
|
}
|
||||||
|
|
||||||
|
public IActionResult SaleDelete()
|
||||||
|
{
|
||||||
|
if (ApiClient.Client == null)
|
||||||
|
{
|
||||||
|
return Redirect("~/Home/Enter");
|
||||||
|
}
|
||||||
|
ViewBag.Shops = ApiClient.GetRequest<List<SaleView>>("api/sale/getsalelist");
|
||||||
|
return View();
|
||||||
|
}
|
||||||
|
|
||||||
|
[HttpPost]
|
||||||
|
public void SaleDelete(int sale)
|
||||||
|
{
|
||||||
|
if (ApiClient.Client == null)
|
||||||
|
{
|
||||||
|
throw new Exception("Вы как сюда попали? Сюда вход только авторизованным");
|
||||||
|
}
|
||||||
|
ApiClient.PostRequest("api/sale/deletesale", new SaleDto
|
||||||
|
{
|
||||||
|
Id = sale
|
||||||
|
});
|
||||||
|
Response.Redirect("Index");
|
||||||
|
}
|
||||||
|
|
||||||
|
[ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)]
|
||||||
public IActionResult Error()
|
public IActionResult Error()
|
||||||
{
|
{
|
||||||
return View(new ErrorViewModel { RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier });
|
return View(new ErrorViewModel { RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier });
|
||||||
|
@ -11,6 +11,13 @@
|
|||||||
<input type="number" name="sum" id="sum" readonly/>
|
<input type="number" name="sum" id="sum" readonly/>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
<div class="row">
|
||||||
|
<div class="col-4">Клиент:</div>
|
||||||
|
<div class="col-8">
|
||||||
|
<select name="client" id="client" class="form-control"
|
||||||
|
asp-items="@(new SelectList(@ViewBag.Clients, "Id", "Name"))"></select>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="col-4">Автомобили:</div>
|
<div class="col-4">Автомобили:</div>
|
||||||
<div class="col-8">
|
<div class="col-8">
|
||||||
|
Binary file not shown.
BIN
ERD/car-showroom_2.vpp.bak_010d
Normal file
BIN
ERD/car-showroom_2.vpp.bak_010d
Normal file
Binary file not shown.
Loading…
Reference in New Issue
Block a user