some changes

This commit is contained in:
Zakharov_Rostislav 2024-05-12 21:44:49 +04:00
parent aa93c93775
commit 73c4800cad
16 changed files with 695 additions and 20 deletions

View File

@ -46,6 +46,7 @@ namespace CarShowroomBusinessLogic.BusinessLogic
public bool Create(CarDto model)
{
model.IsSaled = false;
CheckModel(model);
if (_carStorage.Insert(model) == null)
{

View File

@ -12,5 +12,6 @@ namespace CarShowroomContracts.AbstractModels
string Color { get; }
DateTime ReleaseDate { get; }
int ModelId { get; }
bool IsSaled { get; }
}
}

View File

@ -13,12 +13,14 @@ namespace CarShowroomDataModels.Dtos
public string Color { get; set; }
public DateTime ReleaseDate { get; set; }
public int ModelId { get; set; }
public bool IsSaled { get; set; }
public CarDto(ICar model)
{
Id = model.Id;
Color = model.Color;
ReleaseDate = model.ReleaseDate;
ModelId = model.ModelId;
IsSaled = model.IsSaled;
}
}
}

View File

@ -18,5 +18,6 @@ namespace CarShowroomDataModels.Dtos
Name = model.Name;
PhoneNumber = model.PhoneNumber;
}
public ClientDto() {}
}
}

View File

@ -26,5 +26,6 @@ namespace CarShowroomDataModels.Dtos
CarIds = model.CarIds;
ServiceIds = model.ServiceIds;
}
public SaleDto() {}
}
}

View File

@ -12,6 +12,8 @@ namespace CarShowroomDataModels.Views
{
[DisplayName("Номер машины")]
public int Id { get; set; }
[DisplayName("Название машины")]
public string Name { get; set; } = string.Empty;
[DisplayName("Цвет")]
public string Color { get; set; }
[DisplayName("Дата производства")]
@ -23,12 +25,15 @@ namespace CarShowroomDataModels.Views
public int ModelPrice { get; set; }
[DisplayName("Марка")]
public string MakeName { get; set; } = string.Empty;
[DisplayName("Продана")]
public bool IsSaled { get; set; }
public CarView(ICar model)
{
Id = model.Id;
Color = model.Color;
ReleaseDate = model.ReleaseDate;
ModelId = model.ModelId;
IsSaled = model.IsSaled;
}
}
}

View File

@ -33,6 +33,7 @@ namespace CarShowroomDatabaseStorage
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<Car>().Property(c => c.IsSaled).HasDefaultValue(false);
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);
@ -56,11 +57,11 @@ namespace CarShowroomDatabaseStorage
modelBuilder.Entity<SaleService>()
.HasOne(m => m.Sale)
.WithMany(m => m.SaleServices)
.OnDelete(DeleteBehavior.Restrict);
.OnDelete(DeleteBehavior.Cascade);
modelBuilder.Entity<SaleCar>()
.HasOne(m => m.Sale)
.WithMany(m => m.SaleCars)
.OnDelete(DeleteBehavior.Restrict);
.OnDelete(DeleteBehavior.Cascade);
modelBuilder.Entity<SaleService>()
.HasOne(m => m.Service)
.WithMany(m => m.SaleServices)

View File

@ -22,6 +22,9 @@ namespace CarShowroomDatabaseStorage.Entities
[Required]
[Column("car_releasedate")]
public DateTime ReleaseDate { get; private set; }
[Required]
[Column("car_issaled")]
public bool IsSaled { get; private set; }
[Required]
[Column("car_model_id")]
public int ModelId { get; private set; }
@ -36,6 +39,7 @@ namespace CarShowroomDatabaseStorage.Entities
Color = car.Color;
ReleaseDate = DateTime.Now;
ModelId = car.ModelId;
IsSaled = car.IsSaled;
}
public static Car? Create(ICar car)
@ -60,6 +64,7 @@ namespace CarShowroomDatabaseStorage.Entities
car.ModelPrice = Model?.Price ?? 0;
car.ModelName = Model?.Name ?? string.Empty;
car.MakeName = Model?.Make?.Name ?? string.Empty;
car.Name = car.Color + " " + car.MakeName + " " + car.ModelName;
return car;
}
}

View 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
}
}
}

View File

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

View File

@ -39,6 +39,12 @@ namespace CarShowroomDatabaseStorage.Migrations
.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");
@ -331,7 +337,7 @@ namespace CarShowroomDatabaseStorage.Migrations
b.HasOne("CarShowroomDatabaseStorage.Entities.Sale", "Sale")
.WithMany("SaleCars")
.HasForeignKey("SaleId")
.OnDelete(DeleteBehavior.Restrict)
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Car");
@ -344,7 +350,7 @@ namespace CarShowroomDatabaseStorage.Migrations
b.HasOne("CarShowroomDatabaseStorage.Entities.Sale", "Sale")
.WithMany("SaleServices")
.HasForeignKey("SaleId")
.OnDelete(DeleteBehavior.Restrict)
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("CarShowroomDatabaseStorage.Entities.Service", "Service")

View File

@ -6,7 +6,7 @@ using System.Xml;
namespace CarShowroomManagerApp
{
public static class APIClient
public static class ApiClient
{
private static readonly HttpClient _client = new();
public static EmployeeView? Client { get; set; } = null;

View File

@ -1,4 +1,7 @@
using CarShowroomManagerApp.Models;
using CarShowroomDataModels.Dtos;
using CarShowroomDataModels.Models;
using CarShowroomDataModels.Views;
using CarShowroomManagerApp.Models;
using Microsoft.AspNetCore.Mvc;
using System.Diagnostics;
@ -14,15 +17,171 @@ namespace CarShowroomManagerApp.Controllers
}
public IActionResult Index()
{
if (ApiClient.Client == null)
{
return Redirect("~/Home/Enter");
}
return
View(ApiClient.GetRequest<List<SaleView>>($"api/sale/getsalelist"));
}
public IActionResult Clients()
{
if (ApiClient.Client == null)
{
return Redirect("~/Home/Enter");
}
return
View(ApiClient.GetRequest<List<ClientView>>($"api/client/getclientlist"));
}
[HttpGet]
public IActionResult Privacy()
{
if (ApiClient.Client == null)
{
return Redirect("~/Home/Enter");
}
return View(ApiClient.Client);
}
[HttpGet]
public IActionResult Enter()
{
return View();
}
public IActionResult Privacy()
[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()
{

View File

@ -11,6 +11,13 @@
<input type="number" name="sum" id="sum" readonly/>
</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="col-4">Автомобили:</div>
<div class="col-8">

Binary file not shown.

Binary file not shown.