diff --git a/CarShowroom/CarShowroomBusinessLogic/BusinessLogic/CarLogic.cs b/CarShowroom/CarShowroomBusinessLogic/BusinessLogic/CarLogic.cs index df08933..0571a79 100644 --- a/CarShowroom/CarShowroomBusinessLogic/BusinessLogic/CarLogic.cs +++ b/CarShowroom/CarShowroomBusinessLogic/BusinessLogic/CarLogic.cs @@ -46,6 +46,7 @@ namespace CarShowroomBusinessLogic.BusinessLogic public bool Create(CarDto model) { + model.IsSaled = false; CheckModel(model); if (_carStorage.Insert(model) == null) { diff --git a/CarShowroom/CarShowroomDataModels/AbstractModels/ICar.cs b/CarShowroom/CarShowroomDataModels/AbstractModels/ICar.cs index b60ba59..0c95fda 100644 --- a/CarShowroom/CarShowroomDataModels/AbstractModels/ICar.cs +++ b/CarShowroom/CarShowroomDataModels/AbstractModels/ICar.cs @@ -12,5 +12,6 @@ namespace CarShowroomContracts.AbstractModels string Color { get; } DateTime ReleaseDate { get; } int ModelId { get; } + bool IsSaled { get; } } } diff --git a/CarShowroom/CarShowroomDataModels/Dtos/CarDto.cs b/CarShowroom/CarShowroomDataModels/Dtos/CarDto.cs index bd8c49d..82fa02f 100644 --- a/CarShowroom/CarShowroomDataModels/Dtos/CarDto.cs +++ b/CarShowroom/CarShowroomDataModels/Dtos/CarDto.cs @@ -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; } } } diff --git a/CarShowroom/CarShowroomDataModels/Dtos/ClientDto.cs b/CarShowroom/CarShowroomDataModels/Dtos/ClientDto.cs index 7cbef49..a39f566 100644 --- a/CarShowroom/CarShowroomDataModels/Dtos/ClientDto.cs +++ b/CarShowroom/CarShowroomDataModels/Dtos/ClientDto.cs @@ -17,6 +17,7 @@ namespace CarShowroomDataModels.Dtos Id = model.Id; Name = model.Name; PhoneNumber = model.PhoneNumber; - } - } + } + public ClientDto() {} + } } diff --git a/CarShowroom/CarShowroomDataModels/Dtos/SaleDto.cs b/CarShowroom/CarShowroomDataModels/Dtos/SaleDto.cs index 099837b..2e6347f 100644 --- a/CarShowroom/CarShowroomDataModels/Dtos/SaleDto.cs +++ b/CarShowroom/CarShowroomDataModels/Dtos/SaleDto.cs @@ -25,6 +25,7 @@ namespace CarShowroomDataModels.Dtos EmployeeId = model.EmployeeId; CarIds = model.CarIds; ServiceIds = model.ServiceIds; - } - } + } + public SaleDto() {} + } } diff --git a/CarShowroom/CarShowroomDataModels/Views/CarView.cs b/CarShowroom/CarShowroomDataModels/Views/CarView.cs index 91bee92..4536110 100644 --- a/CarShowroom/CarShowroomDataModels/Views/CarView.cs +++ b/CarShowroom/CarShowroomDataModels/Views/CarView.cs @@ -12,7 +12,9 @@ namespace CarShowroomDataModels.Views { [DisplayName("Номер машины")] public int Id { get; set; } - [DisplayName("Цвет")] + [DisplayName("Название машины")] + public string Name { get; set; } = string.Empty; + [DisplayName("Цвет")] public string Color { get; set; } [DisplayName("Дата производства")] public DateTime ReleaseDate { get; set; } @@ -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; } } } diff --git a/CarShowroom/CarShowroomDatabaseStorage/CarShowroomDatabase.cs b/CarShowroom/CarShowroomDatabaseStorage/CarShowroomDatabase.cs index e8cffcc..8201042 100644 --- a/CarShowroom/CarShowroomDatabaseStorage/CarShowroomDatabase.cs +++ b/CarShowroom/CarShowroomDatabaseStorage/CarShowroomDatabase.cs @@ -33,6 +33,7 @@ namespace CarShowroomDatabaseStorage modelBuilder.Entity().Property(e => e.Name).HasDefaultValue("empty_string"); modelBuilder.Entity().Property(e => e.Password).HasDefaultValue("empty_string"); modelBuilder.Entity().Property(c => c.Color).HasDefaultValue("empty_string"); + modelBuilder.Entity().Property(c => c.IsSaled).HasDefaultValue(false); modelBuilder.Entity().Property(c => c.Cost).HasDefaultValue(-1); modelBuilder.Entity().Property(c => c.Price).HasDefaultValue(-1); modelBuilder.Entity().Property(c => c.Cost).HasDefaultValue(-1); @@ -56,11 +57,11 @@ namespace CarShowroomDatabaseStorage modelBuilder.Entity() .HasOne(m => m.Sale) .WithMany(m => m.SaleServices) - .OnDelete(DeleteBehavior.Restrict); + .OnDelete(DeleteBehavior.Cascade); modelBuilder.Entity() .HasOne(m => m.Sale) .WithMany(m => m.SaleCars) - .OnDelete(DeleteBehavior.Restrict); + .OnDelete(DeleteBehavior.Cascade); modelBuilder.Entity() .HasOne(m => m.Service) .WithMany(m => m.SaleServices) diff --git a/CarShowroom/CarShowroomDatabaseStorage/Entities/Car.cs b/CarShowroom/CarShowroomDatabaseStorage/Entities/Car.cs index cd64a1c..8069ad6 100644 --- a/CarShowroom/CarShowroomDatabaseStorage/Entities/Car.cs +++ b/CarShowroom/CarShowroomDatabaseStorage/Entities/Car.cs @@ -23,6 +23,9 @@ namespace CarShowroomDatabaseStorage.Entities [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; } public virtual Model? Model { get; 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; } } diff --git a/CarShowroom/CarShowroomDatabaseStorage/Migrations/20240512174258_changeCarsAndSale.Designer.cs b/CarShowroom/CarShowroomDatabaseStorage/Migrations/20240512174258_changeCarsAndSale.Designer.cs new file mode 100644 index 0000000..563ab68 --- /dev/null +++ b/CarShowroom/CarShowroomDatabaseStorage/Migrations/20240512174258_changeCarsAndSale.Designer.cs @@ -0,0 +1,409 @@ +// +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 + { + /// + 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("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer") + .HasColumnName("car_id"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("Color") + .IsRequired() + .ValueGeneratedOnAdd() + .HasMaxLength(50) + .HasColumnType("character varying(50)") + .HasDefaultValue("empty_string") + .HasColumnName("car_color"); + + b.Property("IsSaled") + .ValueGeneratedOnAdd() + .HasColumnType("boolean") + .HasDefaultValue(false) + .HasColumnName("car_issaled"); + + b.Property("ModelId") + .HasColumnType("integer") + .HasColumnName("car_model_id"); + + b.Property("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("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer") + .HasColumnName("client_id"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("Name") + .IsRequired() + .ValueGeneratedOnAdd() + .HasMaxLength(50) + .HasColumnType("character varying(50)") + .HasDefaultValue("empty_string") + .HasColumnName("client_name"); + + b.Property("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("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer") + .HasColumnName("employee_id"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("Email") + .IsRequired() + .HasMaxLength(40) + .HasColumnType("character varying(40)") + .HasColumnName("employee_email"); + + b.Property("Name") + .IsRequired() + .ValueGeneratedOnAdd() + .HasMaxLength(50) + .HasColumnType("character varying(50)") + .HasDefaultValue("empty_string") + .HasColumnName("employee_name"); + + b.Property("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("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer") + .HasColumnName("make_id"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("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("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer") + .HasColumnName("model_id"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("MakeId") + .HasColumnType("integer") + .HasColumnName("model_make_id"); + + b.Property("Name") + .IsRequired() + .HasMaxLength(50) + .HasColumnType("character varying(50)") + .HasColumnName("model_name"); + + b.Property("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("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer") + .HasColumnName("sale_id"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("ClientId") + .HasColumnType("integer") + .HasColumnName("sale_client_id"); + + b.Property("Cost") + .ValueGeneratedOnAdd() + .HasColumnType("integer") + .HasDefaultValue(-1) + .HasColumnName("sale_cost"); + + b.Property("EmployeeId") + .HasColumnType("integer") + .HasColumnName("sale_employee_id"); + + b.Property("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("SaleId") + .HasColumnType("integer") + .HasColumnName("sale_id"); + + b.Property("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("SaleId") + .HasColumnType("integer") + .HasColumnName("sale_id"); + + b.Property("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("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer") + .HasColumnName("service_id"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("Cost") + .ValueGeneratedOnAdd() + .HasColumnType("integer") + .HasDefaultValue(-1) + .HasColumnName("service_cost"); + + b.Property("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 + } + } +} diff --git a/CarShowroom/CarShowroomDatabaseStorage/Migrations/20240512174258_changeCarsAndSale.cs b/CarShowroom/CarShowroomDatabaseStorage/Migrations/20240512174258_changeCarsAndSale.cs new file mode 100644 index 0000000..d81985c --- /dev/null +++ b/CarShowroom/CarShowroomDatabaseStorage/Migrations/20240512174258_changeCarsAndSale.cs @@ -0,0 +1,77 @@ +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +namespace CarShowroomDatabaseStorage.Migrations +{ + /// + public partial class changeCarsAndSale : Migration + { + /// + 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( + 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); + } + + /// + 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); + } + } +} diff --git a/CarShowroom/CarShowroomDatabaseStorage/Migrations/CarShowroomDatabaseModelSnapshot.cs b/CarShowroom/CarShowroomDatabaseStorage/Migrations/CarShowroomDatabaseModelSnapshot.cs index 49d2c2d..b654cbd 100644 --- a/CarShowroom/CarShowroomDatabaseStorage/Migrations/CarShowroomDatabaseModelSnapshot.cs +++ b/CarShowroom/CarShowroomDatabaseStorage/Migrations/CarShowroomDatabaseModelSnapshot.cs @@ -39,6 +39,12 @@ namespace CarShowroomDatabaseStorage.Migrations .HasDefaultValue("empty_string") .HasColumnName("car_color"); + b.Property("IsSaled") + .ValueGeneratedOnAdd() + .HasColumnType("boolean") + .HasDefaultValue(false) + .HasColumnName("car_issaled"); + b.Property("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") diff --git a/CarShowroom/CarShowroomManagerApp/APIClient.cs b/CarShowroom/CarShowroomManagerApp/APIClient.cs index 89e7f01..d1d15f3 100644 --- a/CarShowroom/CarShowroomManagerApp/APIClient.cs +++ b/CarShowroom/CarShowroomManagerApp/APIClient.cs @@ -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; diff --git a/CarShowroom/CarShowroomManagerApp/Controllers/HomeController.cs b/CarShowroom/CarShowroomManagerApp/Controllers/HomeController.cs index 2176493..6512309 100644 --- a/CarShowroom/CarShowroomManagerApp/Controllers/HomeController.cs +++ b/CarShowroom/CarShowroomManagerApp/Controllers/HomeController.cs @@ -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; @@ -13,17 +16,173 @@ namespace CarShowroomManagerApp.Controllers _logger = logger; } - public IActionResult Index() - { - return View(); - } + public IActionResult Index() + { + if (ApiClient.Client == null) + { + return Redirect("~/Home/Enter"); + } + return + View(ApiClient.GetRequest>($"api/sale/getsalelist")); + } - public IActionResult Privacy() - { - return View(); - } + public IActionResult Clients() + { + if (ApiClient.Client == null) + { + return Redirect("~/Home/Enter"); + } + return + View(ApiClient.GetRequest>($"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($"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>("api/car/getcarlist"); + ViewBag.Clients = ApiClient.GetRequest>("api/client/getclientlist"); + ViewBag.Services = ApiClient.GetRequest>("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>("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>("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() { return View(new ErrorViewModel { RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier }); diff --git a/CarShowroom/CarShowroomManagerApp/Views/Home/SaleCreate.cshtml b/CarShowroom/CarShowroomManagerApp/Views/Home/SaleCreate.cshtml index 927e3e6..3c272a9 100644 --- a/CarShowroom/CarShowroomManagerApp/Views/Home/SaleCreate.cshtml +++ b/CarShowroom/CarShowroomManagerApp/Views/Home/SaleCreate.cshtml @@ -11,6 +11,13 @@ +
+
Клиент:
+
+ +
+
Автомобили:
diff --git a/ERD/car-showroom_2.vpp b/ERD/car-showroom_2.vpp index 5319f3b..31be436 100644 Binary files a/ERD/car-showroom_2.vpp and b/ERD/car-showroom_2.vpp differ diff --git a/ERD/car-showroom_2.vpp.bak_010d b/ERD/car-showroom_2.vpp.bak_010d new file mode 100644 index 0000000..8f6f5d7 Binary files /dev/null and b/ERD/car-showroom_2.vpp.bak_010d differ