diff --git a/ElectronicsShop/ElectronicsShopDataBaseImplement/DataBase.cs b/ElectronicsShop/ElectronicsShopDataBaseImplement/DataBase.cs index 23bfaec..e4868b2 100644 --- a/ElectronicsShop/ElectronicsShopDataBaseImplement/DataBase.cs +++ b/ElectronicsShop/ElectronicsShopDataBaseImplement/DataBase.cs @@ -12,7 +12,7 @@ namespace ElectronicsShopDataBaseImplement optionsBuilder) { if (optionsBuilder.IsConfigured == false) { - optionsBuilder.UseSqlServer(@"Data Source=DESKTOP-O0N00SH\SQLEXPRESS;Initial Catalog=ElectronicsShopDatabase;Integrated Security=True;MultipleActiveResultSets=True;;TrustServerCertificate=True"); + optionsBuilder.UseSqlServer(@"Data Source=DESKTOP-E2VPEN3\SQLEXPRESS;Initial Catalog=ElectronicsShopDatabase;Integrated Security=True;MultipleActiveResultSets=True;;TrustServerCertificate=True"); } base.OnConfiguring(optionsBuilder); } diff --git a/ElectronicsShop/ElectronicsShopDataBaseImplement/Migrations/20240528050446_Init.Designer.cs b/ElectronicsShop/ElectronicsShopDataBaseImplement/Migrations/20240529092847_Init.Designer.cs similarity index 89% rename from ElectronicsShop/ElectronicsShopDataBaseImplement/Migrations/20240528050446_Init.Designer.cs rename to ElectronicsShop/ElectronicsShopDataBaseImplement/Migrations/20240529092847_Init.Designer.cs index 0008c56..57b08ac 100644 --- a/ElectronicsShop/ElectronicsShopDataBaseImplement/Migrations/20240528050446_Init.Designer.cs +++ b/ElectronicsShop/ElectronicsShopDataBaseImplement/Migrations/20240529092847_Init.Designer.cs @@ -12,7 +12,7 @@ using Microsoft.EntityFrameworkCore.Storage.ValueConversion; namespace ElectronicsShopDataBaseImplement.Migrations { [DbContext(typeof(Database))] - [Migration("20240528050446_Init")] + [Migration("20240529092847_Init")] partial class Init { /// @@ -73,6 +73,8 @@ namespace ElectronicsShopDataBaseImplement.Migrations b.HasKey("ID"); + b.HasIndex("EmployeeID"); + b.ToTable("CostItems"); }); @@ -204,9 +206,22 @@ namespace ElectronicsShopDataBaseImplement.Migrations b.HasKey("ID"); + b.HasIndex("CostItemID"); + b.ToTable("Products"); }); + modelBuilder.Entity("ElectronicsShopDataBaseImplement.Models.CostItem", b => + { + b.HasOne("ElectronicsShopDataBaseImplement.Models.Employee", "Employee") + .WithMany() + .HasForeignKey("EmployeeID") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Employee"); + }); + modelBuilder.Entity("ElectronicsShopDataBaseImplement.Models.Order", b => { b.HasOne("ElectronicsShopDataBaseImplement.Models.Client", null) @@ -240,6 +255,17 @@ namespace ElectronicsShopDataBaseImplement.Migrations .HasForeignKey("PaymentID"); }); + modelBuilder.Entity("ElectronicsShopDataBaseImplement.Models.Product", b => + { + b.HasOne("ElectronicsShopDataBaseImplement.Models.CostItem", "CostItem") + .WithMany() + .HasForeignKey("CostItemID") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("CostItem"); + }); + modelBuilder.Entity("ElectronicsShopDataBaseImplement.Models.Client", b => { b.Navigation("Orders"); diff --git a/ElectronicsShop/ElectronicsShopDataBaseImplement/Migrations/20240528050446_Init.cs b/ElectronicsShop/ElectronicsShopDataBaseImplement/Migrations/20240529092847_Init.cs similarity index 89% rename from ElectronicsShop/ElectronicsShopDataBaseImplement/Migrations/20240528050446_Init.cs rename to ElectronicsShop/ElectronicsShopDataBaseImplement/Migrations/20240529092847_Init.cs index 8f70eb5..e164d84 100644 --- a/ElectronicsShop/ElectronicsShopDataBaseImplement/Migrations/20240528050446_Init.cs +++ b/ElectronicsShop/ElectronicsShopDataBaseImplement/Migrations/20240529092847_Init.cs @@ -26,22 +26,6 @@ namespace ElectronicsShopDataBaseImplement.Migrations table.PrimaryKey("PK_Clients", x => x.ID); }); - migrationBuilder.CreateTable( - name: "CostItems", - columns: table => new - { - ID = table.Column(type: "int", nullable: false) - .Annotation("SqlServer:Identity", "1, 1"), - EmployeeID = table.Column(type: "int", nullable: false), - Name = table.Column(type: "nvarchar(max)", nullable: false), - Price = table.Column(type: "float", nullable: false), - CostNum = table.Column(type: "int", nullable: false) - }, - constraints: table => - { - table.PrimaryKey("PK_CostItems", x => x.ID); - }); - migrationBuilder.CreateTable( name: "Employees", columns: table => new @@ -57,21 +41,6 @@ namespace ElectronicsShopDataBaseImplement.Migrations table.PrimaryKey("PK_Employees", x => x.ID); }); - migrationBuilder.CreateTable( - name: "Products", - columns: table => new - { - ID = table.Column(type: "int", nullable: false) - .Annotation("SqlServer:Identity", "1, 1"), - ProductName = table.Column(type: "nvarchar(max)", nullable: false), - Price = table.Column(type: "float", nullable: false), - CostItemID = table.Column(type: "int", nullable: false) - }, - constraints: table => - { - table.PrimaryKey("PK_Products", x => x.ID); - }); - migrationBuilder.CreateTable( name: "Orders", columns: table => new @@ -93,6 +62,71 @@ namespace ElectronicsShopDataBaseImplement.Migrations onDelete: ReferentialAction.Cascade); }); + migrationBuilder.CreateTable( + name: "CostItems", + columns: table => new + { + ID = table.Column(type: "int", nullable: false) + .Annotation("SqlServer:Identity", "1, 1"), + EmployeeID = table.Column(type: "int", nullable: false), + Name = table.Column(type: "nvarchar(max)", nullable: false), + Price = table.Column(type: "float", nullable: false), + CostNum = table.Column(type: "int", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_CostItems", x => x.ID); + table.ForeignKey( + name: "FK_CostItems_Employees_EmployeeID", + column: x => x.EmployeeID, + principalTable: "Employees", + principalColumn: "ID", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateTable( + name: "Paymeants", + columns: table => new + { + ID = table.Column(type: "int", nullable: false) + .Annotation("SqlServer:Identity", "1, 1"), + ProductID = table.Column(type: "int", nullable: false), + OrderID = table.Column(type: "int", nullable: false), + SumPayment = table.Column(type: "float", nullable: false), + PayOption = table.Column(type: "int", nullable: false), + PaymentID = table.Column(type: "int", nullable: true) + }, + constraints: table => + { + table.PrimaryKey("PK_Paymeants", x => x.ID); + table.ForeignKey( + name: "FK_Paymeants_Orders_PaymentID", + column: x => x.PaymentID, + principalTable: "Orders", + principalColumn: "ID"); + }); + + migrationBuilder.CreateTable( + name: "Products", + columns: table => new + { + ID = table.Column(type: "int", nullable: false) + .Annotation("SqlServer:Identity", "1, 1"), + ProductName = table.Column(type: "nvarchar(max)", nullable: false), + Price = table.Column(type: "float", nullable: false), + CostItemID = table.Column(type: "int", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Products", x => x.ID); + table.ForeignKey( + name: "FK_Products_CostItems_CostItemID", + column: x => x.CostItemID, + principalTable: "CostItems", + principalColumn: "ID", + onDelete: ReferentialAction.Cascade); + }); + migrationBuilder.CreateTable( name: "OrderProducts", columns: table => new @@ -120,27 +154,10 @@ namespace ElectronicsShopDataBaseImplement.Migrations principalColumn: "ID"); }); - migrationBuilder.CreateTable( - name: "Paymeants", - columns: table => new - { - ID = table.Column(type: "int", nullable: false) - .Annotation("SqlServer:Identity", "1, 1"), - ProductID = table.Column(type: "int", nullable: false), - OrderID = table.Column(type: "int", nullable: false), - SumPayment = table.Column(type: "float", nullable: false), - PayOption = table.Column(type: "int", nullable: false), - PaymentID = table.Column(type: "int", nullable: true) - }, - constraints: table => - { - table.PrimaryKey("PK_Paymeants", x => x.ID); - table.ForeignKey( - name: "FK_Paymeants_Orders_PaymentID", - column: x => x.PaymentID, - principalTable: "Orders", - principalColumn: "ID"); - }); + migrationBuilder.CreateIndex( + name: "IX_CostItems_EmployeeID", + table: "CostItems", + column: "EmployeeID"); migrationBuilder.CreateIndex( name: "IX_OrderProducts__productID", @@ -161,17 +178,16 @@ namespace ElectronicsShopDataBaseImplement.Migrations name: "IX_Paymeants_PaymentID", table: "Paymeants", column: "PaymentID"); + + migrationBuilder.CreateIndex( + name: "IX_Products_CostItemID", + table: "Products", + column: "CostItemID"); } /// protected override void Down(MigrationBuilder migrationBuilder) { - migrationBuilder.DropTable( - name: "CostItems"); - - migrationBuilder.DropTable( - name: "Employees"); - migrationBuilder.DropTable( name: "OrderProducts"); @@ -184,8 +200,14 @@ namespace ElectronicsShopDataBaseImplement.Migrations migrationBuilder.DropTable( name: "Orders"); + migrationBuilder.DropTable( + name: "CostItems"); + migrationBuilder.DropTable( name: "Clients"); + + migrationBuilder.DropTable( + name: "Employees"); } } } diff --git a/ElectronicsShop/ElectronicsShopDataBaseImplement/Migrations/DatabaseModelSnapshot.cs b/ElectronicsShop/ElectronicsShopDataBaseImplement/Migrations/DatabaseModelSnapshot.cs index fbdc60c..55e33e5 100644 --- a/ElectronicsShop/ElectronicsShopDataBaseImplement/Migrations/DatabaseModelSnapshot.cs +++ b/ElectronicsShop/ElectronicsShopDataBaseImplement/Migrations/DatabaseModelSnapshot.cs @@ -70,6 +70,8 @@ namespace ElectronicsShopDataBaseImplement.Migrations b.HasKey("ID"); + b.HasIndex("EmployeeID"); + b.ToTable("CostItems"); }); @@ -201,9 +203,22 @@ namespace ElectronicsShopDataBaseImplement.Migrations b.HasKey("ID"); + b.HasIndex("CostItemID"); + b.ToTable("Products"); }); + modelBuilder.Entity("ElectronicsShopDataBaseImplement.Models.CostItem", b => + { + b.HasOne("ElectronicsShopDataBaseImplement.Models.Employee", "Employee") + .WithMany() + .HasForeignKey("EmployeeID") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Employee"); + }); + modelBuilder.Entity("ElectronicsShopDataBaseImplement.Models.Order", b => { b.HasOne("ElectronicsShopDataBaseImplement.Models.Client", null) @@ -237,6 +252,17 @@ namespace ElectronicsShopDataBaseImplement.Migrations .HasForeignKey("PaymentID"); }); + modelBuilder.Entity("ElectronicsShopDataBaseImplement.Models.Product", b => + { + b.HasOne("ElectronicsShopDataBaseImplement.Models.CostItem", "CostItem") + .WithMany() + .HasForeignKey("CostItemID") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("CostItem"); + }); + modelBuilder.Entity("ElectronicsShopDataBaseImplement.Models.Client", b => { b.Navigation("Orders"); diff --git a/ElectronicsShop/ElectronicsShopRestAPI/Controllers/MainController.cs b/ElectronicsShop/ElectronicsShopRestAPI/Controllers/MainController.cs index 68848a2..fa385ec 100644 --- a/ElectronicsShop/ElectronicsShopRestAPI/Controllers/MainController.cs +++ b/ElectronicsShop/ElectronicsShopRestAPI/Controllers/MainController.cs @@ -33,8 +33,23 @@ namespace ElectronicsShopRestAPI.Controllers { throw; } } - - [HttpGet] + [HttpGet] + public ProductViewModel? GetPoduct(int productID) + { + try + { + return _product.ReadElement(new ProductSearchModel + { + ID = productID + }); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка получения суши по id={Id}", productID); + throw; + } + } + [HttpGet] public List? GetOrders(int _clientID) { try { diff --git a/ElectronicsShop/ElectronicsShopShopClientApp/Controllers/HomeController.cs b/ElectronicsShop/ElectronicsShopShopClientApp/Controllers/HomeController.cs index dc484fe..7541e9c 100644 --- a/ElectronicsShop/ElectronicsShopShopClientApp/Controllers/HomeController.cs +++ b/ElectronicsShop/ElectronicsShopShopClientApp/Controllers/HomeController.cs @@ -1,5 +1,6 @@ using ElectronicsShopContracts.BindingModels; using ElectronicsShopContracts.ViewModels; +using ElectronicsShopDataModels.Models; using ElectronicsShopUserApp.Models; using Microsoft.AspNetCore.Mvc; using System.Diagnostics; @@ -75,7 +76,7 @@ namespace ElectronicsShopUserApp.Controllers { public IActionResult Register() { return View(); } - + [HttpPost] public void Register(string email, string password, string fio) { if (string.IsNullOrEmpty(email) || string.IsNullOrEmpty(password) || string.IsNullOrEmpty(fio)) { throw new Exception(" , "); @@ -91,17 +92,37 @@ namespace ElectronicsShopUserApp.Controllers { [HttpGet] public IActionResult Create() { - ViewBag.Orders = APIClient.GetRequset>("api/main/getproductlist"); + ViewBag.Products = APIClient.GetRequset>("api/main/getproducts"); return View(); } - + [HttpPost] public void Create(OrderBindingModel order) { - throw new NotImplementedException(); - - } - - private double Calc() { - throw new NotImplementedException(); - } - } + if (APIClient.Client == null) + { + throw new Exception(" ? "); + } + if (order.ProductList.Count <= 0) + { + throw new Exception(" 0"); + } + APIClient.PostRequest("api/main/createorder", new OrderBindingModel + { + ClientID = APIClient.Client.ID, + Sum = Calc(order.ProductList), + ProductList = order.ProductList, + DateCreate = DateTime.Now, + }); + Response.Redirect("Index"); + } + [HttpPost] + private double Calc(Dictionary ProductList) + { + Double Sum = 0; + foreach (var ProductItem in ProductList) + { + Sum += (ProductItem.Value.Item1.Price * ProductItem.Value.Item2); + } + return Sum; + } + } } diff --git a/ElectronicsShop/ElectronicsShopShopClientApp/Views/Home/Create.cshtml b/ElectronicsShop/ElectronicsShopShopClientApp/Views/Home/Create.cshtml index 05a4a67..74521e8 100644 --- a/ElectronicsShop/ElectronicsShopShopClientApp/Views/Home/Create.cshtml +++ b/ElectronicsShop/ElectronicsShopShopClientApp/Views/Home/Create.cshtml @@ -1,3 +1,60 @@ @{ - ViewData["Title"] = "Create"; + ViewData["Title"] = "Create"; } + + Создание заказа + + + + Product: + + + @foreach (var product in ViewBag.Products) + { + @product.ProductName + } + + + + + Количество: + + + + + + Сумма: + + + + + + + + + + + + \ No newline at end of file