diff --git a/ComputerShopProvider/ComputerShopContracts/BindingModels/SupplyBindingModel.cs b/ComputerShopProvider/ComputerShopContracts/BindingModels/SupplyBindingModel.cs index 347f631..8caef6b 100644 --- a/ComputerShopProvider/ComputerShopContracts/BindingModels/SupplyBindingModel.cs +++ b/ComputerShopProvider/ComputerShopContracts/BindingModels/SupplyBindingModel.cs @@ -17,7 +17,7 @@ namespace ComputerShopContracts.BindingModels public DateTime? DateImplement { get; set; } - public Dictionary SupplyOrders + public Dictionary SupplyOrders { get; set; diff --git a/ComputerShopProvider/ComputerShopContracts/ViewModels/SupplyViewModel.cs b/ComputerShopProvider/ComputerShopContracts/ViewModels/SupplyViewModel.cs index 3687f9e..8a1d90f 100644 --- a/ComputerShopProvider/ComputerShopContracts/ViewModels/SupplyViewModel.cs +++ b/ComputerShopProvider/ComputerShopContracts/ViewModels/SupplyViewModel.cs @@ -22,7 +22,7 @@ namespace ComputerShopContracts.ViewModels [DisplayName("Номер")] public int Id { get; set; } - public Dictionary SupplyOrders + public Dictionary SupplyOrders { get; set; diff --git a/ComputerShopProvider/ComputerShopDataModels/Models/ISupplyModel.cs b/ComputerShopProvider/ComputerShopDataModels/Models/ISupplyModel.cs index 339413e..7c91b95 100644 --- a/ComputerShopProvider/ComputerShopDataModels/Models/ISupplyModel.cs +++ b/ComputerShopProvider/ComputerShopDataModels/Models/ISupplyModel.cs @@ -7,6 +7,6 @@ namespace ComputerShopDataModels.Models SupplyStatus Status { get; } DateTime DateCreate { get; } DateTime? DateImplement { get; } - Dictionary SupplyOrders { get; } + Dictionary SupplyOrders { get; } } } diff --git a/ComputerShopProvider/ComputerShopDatabaseImplement/ComputerShopDatabase.cs b/ComputerShopProvider/ComputerShopDatabaseImplement/ComputerShopDatabase.cs index 69a127f..5d393aa 100644 --- a/ComputerShopProvider/ComputerShopDatabaseImplement/ComputerShopDatabase.cs +++ b/ComputerShopProvider/ComputerShopDatabaseImplement/ComputerShopDatabase.cs @@ -15,7 +15,7 @@ namespace ComputerShopDatabaseImplement { if (optionsBuilder.IsConfigured == false) { - optionsBuilder.UseSqlServer(@"Data Source=DESKTOP-IRUVF5S\SQLEXPRESS;Initial Catalog=ComputerShopDatabaseCW;Integrated Security=True;MultipleActiveResultSets=True;;TrustServerCertificate=True"); + optionsBuilder.UseSqlServer(@"Data Source=DESKTOP-QA8P9OJ;Initial Catalog=ComputerShopDatabase;Integrated Security=True;MultipleActiveResultSets=True;;TrustServerCertificate=True"); } base.OnConfiguring(optionsBuilder); } diff --git a/ComputerShopProvider/ComputerShopDatabaseImplement/ComputerShopDatabaseImplement.csproj b/ComputerShopProvider/ComputerShopDatabaseImplement/ComputerShopDatabaseImplement.csproj index e970af9..4473c54 100644 --- a/ComputerShopProvider/ComputerShopDatabaseImplement/ComputerShopDatabaseImplement.csproj +++ b/ComputerShopProvider/ComputerShopDatabaseImplement/ComputerShopDatabaseImplement.csproj @@ -22,4 +22,8 @@ + + + + diff --git a/ComputerShopProvider/ComputerShopDatabaseImplement/Implements/OrderStorage.cs b/ComputerShopProvider/ComputerShopDatabaseImplement/Implements/OrderStorage.cs index af905a8..5f5807c 100644 --- a/ComputerShopProvider/ComputerShopDatabaseImplement/Implements/OrderStorage.cs +++ b/ComputerShopProvider/ComputerShopDatabaseImplement/Implements/OrderStorage.cs @@ -2,6 +2,7 @@ using ComputerShopContracts.SearchModels; using ComputerShopContracts.StorageContracts; using ComputerShopContracts.ViewModels; +using ComputerShopDatabaseImplement.Models; using Microsoft.EntityFrameworkCore; using System; using System.Collections.Generic; @@ -63,12 +64,29 @@ namespace ComputerShopDatabaseImplement.Implements public OrderViewModel? Insert(OrderBindingModel model) { - throw new NotImplementedException(); + var newOrder = Order.Create(model); + + if (newOrder == null) + { + return null; + } + using var context = new ComputerShopDatabase(); + context.Orders.Add(newOrder); + context.SaveChanges(); + return context.Orders.Include(x => x.Assemblies).Include(x => x.ClientId).FirstOrDefault(x => x.Id == newOrder.Id)?.GetViewModel; } public OrderViewModel? Update(OrderBindingModel model) { - throw new NotImplementedException(); + using var context = new ComputerShopDatabase(); + var order = context.Orders.FirstOrDefault(x => x.Id == model.Id); + if (order == null) + { + return null; + } + order.Update(model); + context.SaveChanges(); + return context.Orders.Include(x => x.Assemblies).FirstOrDefault(x => x.Id == order.Id)?.GetViewModel; } } } diff --git a/ComputerShopProvider/ComputerShopDatabaseImplement/Migrations/20230518181418_supplymig.cs b/ComputerShopProvider/ComputerShopDatabaseImplement/Migrations/20230518181418_supplymig.cs deleted file mode 100644 index 596c814..0000000 --- a/ComputerShopProvider/ComputerShopDatabaseImplement/Migrations/20230518181418_supplymig.cs +++ /dev/null @@ -1,95 +0,0 @@ -using Microsoft.EntityFrameworkCore.Migrations; - -#nullable disable - -namespace ComputerShopDatabaseImplement.Migrations -{ - /// - public partial class supplymig : Migration - { - /// - protected override void Up(MigrationBuilder migrationBuilder) - { - migrationBuilder.DropForeignKey( - name: "FK_EquipmentReceivings_Supplies_SupplyId", - table: "EquipmentReceivings"); - - migrationBuilder.DropIndex( - name: "IX_EquipmentReceivings_SupplyId", - table: "EquipmentReceivings"); - - migrationBuilder.DropColumn( - name: "SupplyId", - table: "EquipmentReceivings"); - - migrationBuilder.AlterColumn( - name: "ReceivingId", - table: "Supplies", - type: "int", - nullable: true, - oldClrType: typeof(int), - oldType: "int"); - - migrationBuilder.CreateIndex( - name: "IX_Supplies_ReceivingId", - table: "Supplies", - column: "ReceivingId"); - - migrationBuilder.AddForeignKey( - name: "FK_Supplies_EquipmentReceivings_ReceivingId", - table: "Supplies", - column: "ReceivingId", - principalTable: "EquipmentReceivings", - principalColumn: "Id"); - } - - /// - protected override void Down(MigrationBuilder migrationBuilder) - { - - migrationBuilder.DropForeignKey( - name: "FK_Supplies_EquipmentReceivings_ReceivingId", - table: "Supplies"); - - migrationBuilder.DropIndex( - name: "IX_Supplies_ReceivingId", - table: "Supplies"); - - migrationBuilder.AlterColumn( - name: "ReceivingId", - table: "Supplies", - type: "int", - nullable: false, - defaultValue: 0, - oldClrType: typeof(int), - oldType: "int", - oldNullable: true); - - migrationBuilder.AddColumn( - name: "SupplyId", - table: "EquipmentReceivings", - type: "int", - nullable: true); - - migrationBuilder.AlterColumn( - name: "ClientId", - table: "Assemblies", - type: "int", - nullable: true, - oldClrType: typeof(int), - oldType: "int"); - - migrationBuilder.CreateIndex( - name: "IX_EquipmentReceivings_SupplyId", - table: "EquipmentReceivings", - column: "SupplyId"); - - migrationBuilder.AddForeignKey( - name: "FK_EquipmentReceivings_Supplies_SupplyId", - table: "EquipmentReceivings", - column: "SupplyId", - principalTable: "Supplies", - principalColumn: "Id"); - } - } -} diff --git a/ComputerShopProvider/ComputerShopDatabaseImplement/Migrations/20230518181418_supplymig.Designer.cs b/ComputerShopProvider/ComputerShopDatabaseImplement/Migrations/20230519134438_Init.Designer.cs similarity index 98% rename from ComputerShopProvider/ComputerShopDatabaseImplement/Migrations/20230518181418_supplymig.Designer.cs rename to ComputerShopProvider/ComputerShopDatabaseImplement/Migrations/20230519134438_Init.Designer.cs index 6d124ea..e631eb1 100644 --- a/ComputerShopProvider/ComputerShopDatabaseImplement/Migrations/20230518181418_supplymig.Designer.cs +++ b/ComputerShopProvider/ComputerShopDatabaseImplement/Migrations/20230519134438_Init.Designer.cs @@ -12,8 +12,8 @@ using Microsoft.EntityFrameworkCore.Storage.ValueConversion; namespace ComputerShopDatabaseImplement.Migrations { [DbContext(typeof(ComputerShopDatabase))] - [Migration("20230518181418_supplymig")] - partial class supplymig + [Migration("20230519134438_Init")] + partial class Init { /// protected override void BuildTargetModel(ModelBuilder modelBuilder) @@ -294,7 +294,7 @@ namespace ComputerShopDatabaseImplement.Migrations b.Property("OrderId") .HasColumnType("int"); - b.Property("ReceivingId") + b.Property("ReceivingId") .HasColumnType("int"); b.Property("Status") @@ -453,7 +453,9 @@ namespace ComputerShopDatabaseImplement.Migrations b.HasOne("ComputerShopDatabaseImplement.Models.EquipmentReceiving", null) .WithMany("Supplies") - .HasForeignKey("ReceivingId"); + .HasForeignKey("ReceivingId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); }); modelBuilder.Entity("ComputerShopDatabaseImplement.Models.SupplyOrder", b => diff --git a/ComputerShopProvider/ComputerShopDatabaseImplement/Migrations/20230519134438_Init.cs b/ComputerShopProvider/ComputerShopDatabaseImplement/Migrations/20230519134438_Init.cs new file mode 100644 index 0000000..6e625e8 --- /dev/null +++ b/ComputerShopProvider/ComputerShopDatabaseImplement/Migrations/20230519134438_Init.cs @@ -0,0 +1,400 @@ +using System; +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +namespace ComputerShopDatabaseImplement.Migrations +{ + /// + public partial class Init : Migration + { + /// + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.CreateTable( + name: "Clients", + columns: table => new + { + Id = table.Column(type: "int", nullable: false) + .Annotation("SqlServer:Identity", "1, 1"), + ClientFIO = table.Column(type: "nvarchar(max)", nullable: false), + Email = table.Column(type: "nvarchar(max)", nullable: false), + Password = table.Column(type: "nvarchar(max)", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Clients", x => x.Id); + }); + + migrationBuilder.CreateTable( + name: "Assemblies", + columns: table => new + { + Id = table.Column(type: "int", nullable: false) + .Annotation("SqlServer:Identity", "1, 1"), + AssemblyName = table.Column(type: "nvarchar(max)", nullable: false), + Price = table.Column(type: "float", nullable: false), + ClientId = table.Column(type: "int", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Assemblies", x => x.Id); + table.ForeignKey( + name: "FK_Assemblies_Clients_ClientId", + column: x => x.ClientId, + principalTable: "Clients", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateTable( + name: "Components", + columns: table => new + { + Id = table.Column(type: "int", nullable: false) + .Annotation("SqlServer:Identity", "1, 1"), + ComponentName = table.Column(type: "nvarchar(max)", nullable: false), + Cost = table.Column(type: "float", nullable: false), + ClientId = table.Column(type: "int", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Components", x => x.Id); + table.ForeignKey( + name: "FK_Components_Clients_ClientId", + column: x => x.ClientId, + principalTable: "Clients", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateTable( + name: "EquipmentReceivings", + columns: table => new + { + Id = table.Column(type: "int", nullable: false) + .Annotation("SqlServer:Identity", "1, 1"), + DateImplement = table.Column(type: "datetime2", nullable: true), + Status = table.Column(type: "int", nullable: false), + ClientId = table.Column(type: "int", nullable: true) + }, + constraints: table => + { + table.PrimaryKey("PK_EquipmentReceivings", x => x.Id); + table.ForeignKey( + name: "FK_EquipmentReceivings_Clients_ClientId", + column: x => x.ClientId, + principalTable: "Clients", + principalColumn: "Id"); + }); + + migrationBuilder.CreateTable( + name: "Orders", + columns: table => new + { + Id = table.Column(type: "int", nullable: false) + .Annotation("SqlServer:Identity", "1, 1"), + Sum = table.Column(type: "float", nullable: false), + Status = table.Column(type: "int", nullable: false), + DateCreate = table.Column(type: "datetime2", nullable: false), + DateImplement = table.Column(type: "datetime2", nullable: true), + ClientId = table.Column(type: "int", nullable: true) + }, + constraints: table => + { + table.PrimaryKey("PK_Orders", x => x.Id); + table.ForeignKey( + name: "FK_Orders_Clients_ClientId", + column: x => x.ClientId, + principalTable: "Clients", + principalColumn: "Id"); + }); + + migrationBuilder.CreateTable( + name: "AssemblyComponents", + columns: table => new + { + Id = table.Column(type: "int", nullable: false) + .Annotation("SqlServer:Identity", "1, 1"), + AssemblyId = table.Column(type: "int", nullable: false), + ComponentId = table.Column(type: "int", nullable: false), + Count = table.Column(type: "int", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_AssemblyComponents", x => x.Id); + table.ForeignKey( + name: "FK_AssemblyComponents_Assemblies_AssemblyId", + column: x => x.AssemblyId, + principalTable: "Assemblies", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + table.ForeignKey( + name: "FK_AssemblyComponents_Components_ComponentId", + column: x => x.ComponentId, + principalTable: "Components", + principalColumn: "Id", + onDelete: ReferentialAction.NoAction); + }); + + migrationBuilder.CreateTable( + name: "Purchases", + columns: table => new + { + Id = table.Column(type: "int", nullable: false) + .Annotation("SqlServer:Identity", "1, 1"), + ComponentName = table.Column(type: "nvarchar(max)", nullable: false), + ComponentId = table.Column(type: "int", nullable: false), + ClientId = table.Column(type: "int", nullable: false), + Count = table.Column(type: "int", nullable: false), + Sum = table.Column(type: "float", nullable: false), + Status = table.Column(type: "int", nullable: false), + DateCreate = table.Column(type: "datetime2", nullable: false), + DateImplement = table.Column(type: "datetime2", nullable: true) + }, + constraints: table => + { + table.PrimaryKey("PK_Purchases", x => x.Id); + table.ForeignKey( + name: "FK_Purchases_Clients_ClientId", + column: x => x.ClientId, + principalTable: "Clients", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + table.ForeignKey( + name: "FK_Purchases_Components_ComponentId", + column: x => x.ComponentId, + principalTable: "Components", + principalColumn: "Id", + onDelete: ReferentialAction.NoAction); + }); + + migrationBuilder.CreateTable( + name: "Supplies", + columns: table => new + { + Id = table.Column(type: "int", nullable: false) + .Annotation("SqlServer:Identity", "1, 1"), + Status = table.Column(type: "int", nullable: false), + DateCreate = table.Column(type: "datetime2", nullable: false), + DateImplement = table.Column(type: "datetime2", nullable: true), + OrderId = table.Column(type: "int", nullable: false), + ReceivingId = table.Column(type: "int", nullable: false), + ClientId = table.Column(type: "int", nullable: true) + }, + constraints: table => + { + table.PrimaryKey("PK_Supplies", x => x.Id); + table.ForeignKey( + name: "FK_Supplies_Clients_ClientId", + column: x => x.ClientId, + principalTable: "Clients", + principalColumn: "Id"); + table.ForeignKey( + name: "FK_Supplies_EquipmentReceivings_ReceivingId", + column: x => x.ReceivingId, + principalTable: "EquipmentReceivings", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateTable( + name: "AssemblyOrders", + columns: table => new + { + Id = table.Column(type: "int", nullable: false) + .Annotation("SqlServer:Identity", "1, 1"), + AssemblyId = table.Column(type: "int", nullable: false), + OrderId = table.Column(type: "int", nullable: false), + Count = table.Column(type: "int", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_AssemblyOrders", x => x.Id); + table.ForeignKey( + name: "FK_AssemblyOrders_Assemblies_AssemblyId", + column: x => x.AssemblyId, + principalTable: "Assemblies", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + table.ForeignKey( + name: "FK_AssemblyOrders_Orders_OrderId", + column: x => x.OrderId, + principalTable: "Orders", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateTable( + name: "ComponentSupplies", + columns: table => new + { + Id = table.Column(type: "int", nullable: false) + .Annotation("SqlServer:Identity", "1, 1"), + SupplyId = table.Column(type: "int", nullable: false), + ComponentId = table.Column(type: "int", nullable: false), + Count = table.Column(type: "int", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_ComponentSupplies", x => x.Id); + table.ForeignKey( + name: "FK_ComponentSupplies_Components_ComponentId", + column: x => x.ComponentId, + principalTable: "Components", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + table.ForeignKey( + name: "FK_ComponentSupplies_Supplies_SupplyId", + column: x => x.SupplyId, + principalTable: "Supplies", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateTable( + name: "SupplyOrders", + columns: table => new + { + Id = table.Column(type: "int", nullable: false) + .Annotation("SqlServer:Identity", "1, 1"), + OrderId = table.Column(type: "int", nullable: false), + SupplyId = table.Column(type: "int", nullable: false), + Count = table.Column(type: "int", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_SupplyOrders", x => x.Id); + table.ForeignKey( + name: "FK_SupplyOrders_Orders_OrderId", + column: x => x.OrderId, + principalTable: "Orders", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + table.ForeignKey( + name: "FK_SupplyOrders_Supplies_SupplyId", + column: x => x.SupplyId, + principalTable: "Supplies", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateIndex( + name: "IX_Assemblies_ClientId", + table: "Assemblies", + column: "ClientId"); + + migrationBuilder.CreateIndex( + name: "IX_AssemblyComponents_AssemblyId", + table: "AssemblyComponents", + column: "AssemblyId"); + + migrationBuilder.CreateIndex( + name: "IX_AssemblyComponents_ComponentId", + table: "AssemblyComponents", + column: "ComponentId"); + + migrationBuilder.CreateIndex( + name: "IX_AssemblyOrders_AssemblyId", + table: "AssemblyOrders", + column: "AssemblyId"); + + migrationBuilder.CreateIndex( + name: "IX_AssemblyOrders_OrderId", + table: "AssemblyOrders", + column: "OrderId"); + + migrationBuilder.CreateIndex( + name: "IX_Components_ClientId", + table: "Components", + column: "ClientId"); + + migrationBuilder.CreateIndex( + name: "IX_ComponentSupplies_ComponentId", + table: "ComponentSupplies", + column: "ComponentId"); + + migrationBuilder.CreateIndex( + name: "IX_ComponentSupplies_SupplyId", + table: "ComponentSupplies", + column: "SupplyId"); + + migrationBuilder.CreateIndex( + name: "IX_EquipmentReceivings_ClientId", + table: "EquipmentReceivings", + column: "ClientId"); + + migrationBuilder.CreateIndex( + name: "IX_Orders_ClientId", + table: "Orders", + column: "ClientId"); + + migrationBuilder.CreateIndex( + name: "IX_Purchases_ClientId", + table: "Purchases", + column: "ClientId"); + + migrationBuilder.CreateIndex( + name: "IX_Purchases_ComponentId", + table: "Purchases", + column: "ComponentId"); + + migrationBuilder.CreateIndex( + name: "IX_Supplies_ClientId", + table: "Supplies", + column: "ClientId"); + + migrationBuilder.CreateIndex( + name: "IX_Supplies_ReceivingId", + table: "Supplies", + column: "ReceivingId"); + + migrationBuilder.CreateIndex( + name: "IX_SupplyOrders_OrderId", + table: "SupplyOrders", + column: "OrderId"); + + migrationBuilder.CreateIndex( + name: "IX_SupplyOrders_SupplyId", + table: "SupplyOrders", + column: "SupplyId"); + } + + /// + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropTable( + name: "AssemblyComponents"); + + migrationBuilder.DropTable( + name: "AssemblyOrders"); + + migrationBuilder.DropTable( + name: "ComponentSupplies"); + + migrationBuilder.DropTable( + name: "Purchases"); + + migrationBuilder.DropTable( + name: "SupplyOrders"); + + migrationBuilder.DropTable( + name: "Assemblies"); + + migrationBuilder.DropTable( + name: "Components"); + + migrationBuilder.DropTable( + name: "Orders"); + + migrationBuilder.DropTable( + name: "Supplies"); + + migrationBuilder.DropTable( + name: "EquipmentReceivings"); + + migrationBuilder.DropTable( + name: "Clients"); + } + } +} diff --git a/ComputerShopProvider/ComputerShopDatabaseImplement/Migrations/ComputerShopDatabaseModelSnapshot.cs b/ComputerShopProvider/ComputerShopDatabaseImplement/Migrations/ComputerShopDatabaseModelSnapshot.cs index b85e8f6..a1ed3ab 100644 --- a/ComputerShopProvider/ComputerShopDatabaseImplement/Migrations/ComputerShopDatabaseModelSnapshot.cs +++ b/ComputerShopProvider/ComputerShopDatabaseImplement/Migrations/ComputerShopDatabaseModelSnapshot.cs @@ -291,7 +291,7 @@ namespace ComputerShopDatabaseImplement.Migrations b.Property("OrderId") .HasColumnType("int"); - b.Property("ReceivingId") + b.Property("ReceivingId") .HasColumnType("int"); b.Property("Status") @@ -450,7 +450,9 @@ namespace ComputerShopDatabaseImplement.Migrations b.HasOne("ComputerShopDatabaseImplement.Models.EquipmentReceiving", null) .WithMany("Supplies") - .HasForeignKey("ReceivingId"); + .HasForeignKey("ReceivingId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); }); modelBuilder.Entity("ComputerShopDatabaseImplement.Models.SupplyOrder", b => diff --git a/ComputerShopProvider/ComputerShopDatabaseImplement/Models/Order.cs b/ComputerShopProvider/ComputerShopDatabaseImplement/Models/Order.cs index c0f96fd..e6093f4 100644 --- a/ComputerShopProvider/ComputerShopDatabaseImplement/Models/Order.cs +++ b/ComputerShopProvider/ComputerShopDatabaseImplement/Models/Order.cs @@ -27,6 +27,8 @@ namespace ComputerShopDatabaseImplement.Models public virtual List SupplyOrders { get; set; } = new(); [ForeignKey("OrderId")] public virtual List Assemblies { get; set; } = new(); + [Required] + public int ClientId { get; set; } public static Order? Create(OrderBindingModel model) { if (model == null) diff --git a/ComputerShopProvider/ComputerShopDatabaseImplement/Models/Supply.cs b/ComputerShopProvider/ComputerShopDatabaseImplement/Models/Supply.cs index 5adf55d..c2bcd87 100644 --- a/ComputerShopProvider/ComputerShopDatabaseImplement/Models/Supply.cs +++ b/ComputerShopProvider/ComputerShopDatabaseImplement/Models/Supply.cs @@ -26,18 +26,17 @@ namespace ComputerShopDatabaseImplement.Models public int OrderId { get; set; } public int ReceivingId { get; set; } - private Dictionary? _supplyOrders = + private Dictionary? _supplyOrders = null; [NotMapped] - public Dictionary SupplyOrders + public Dictionary SupplyOrders { get { if (_supplyOrders == null) { _supplyOrders = Orders - .ToDictionary(recPC => recPC.SupplyId, recPC => - (recPC.OrderId, recPC.Order as IOrderModel)); + .ToDictionary(recPC => recPC.SupplyId, recPC => recPC.Order as IOrderModel); } return _supplyOrders; } diff --git a/ComputerShopProvider/ComputerShopRestApi/Controllers/OrderController.cs b/ComputerShopProvider/ComputerShopRestApi/Controllers/OrderController.cs new file mode 100644 index 0000000..a80bf5c --- /dev/null +++ b/ComputerShopProvider/ComputerShopRestApi/Controllers/OrderController.cs @@ -0,0 +1,79 @@ +using ComputerShopContracts.BindingModels; +using ComputerShopContracts.BusinessLogicContracts; +using ComputerShopContracts.SearchModels; +using ComputerShopContracts.ViewModels; +using Microsoft.AspNetCore.Http; +using Microsoft.AspNetCore.Mvc; + +namespace ComputerShopRestApi.Controllers +{ + public class OrderController : Controller + { + private readonly ILogger _logger; + private readonly IOrderLogic order; + private readonly IComponentLogic component; + + public OrderController(ILogger logger, IOrderLogic order, IComponentLogic component) + { + _logger = logger; + order = order; + component = component; + } + + [HttpGet] + public List? GetComponentList() + { + try + { + return component.ReadList(null); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка получения списка комплектующих"); + throw; + } + } + + [HttpGet] + public ComponentViewModel? GetPackage(int componentId) + { + try + { + return component.ReadElement(new ComponentSearchModel { Id = componentId }); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка получения продукта по id={Id}", componentId); + throw; + } + } + + [HttpGet] + public List? GetOrders(int clientId) + { + try + { + return order.ReadList(new OrderSearchModel {}); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка получения списка заказов клиента id={Id}", clientId); + throw; + } + } + + [HttpPost] + public void CreateOrder(OrderBindingModel model) + { + try + { + order.CreateOrder(model); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка создания заказа"); + throw; + } + } + } +} diff --git a/ComputerShopProvider/OrdererClientApp/Views/Home/AddOrderToSupply.cshtml b/ComputerShopProvider/OrdererClientApp/Views/Home/AddOrderToSupply.cshtml new file mode 100644 index 0000000..14fe3a9 --- /dev/null +++ b/ComputerShopProvider/OrdererClientApp/Views/Home/AddOrderToSupply.cshtml @@ -0,0 +1,27 @@ +@using ComputerShopContracts.ViewModels; +@using ComputerShopDataModels.Models; + +@{ + ViewData["Title"] = "AddOrderToSupply"; +} + +@model Dictionary + +
+
+ +
+ +
+
+
+ +
+ +
+
+
+
+
+
+
\ No newline at end of file diff --git a/ComputerShopProvider/OrdererClientApp/Views/Home/CreateOrder.cshtml b/ComputerShopProvider/OrdererClientApp/Views/Home/CreateOrder.cshtml new file mode 100644 index 0000000..1627d16 --- /dev/null +++ b/ComputerShopProvider/OrdererClientApp/Views/Home/CreateOrder.cshtml @@ -0,0 +1,20 @@ +@{ + ViewData["Title"] = "CreateOrder"; +} +
+

Создание заказа

+
+
+
+
Сумма:
+
+
+
+
Цена:
+
+
+
+
+
+
+
diff --git a/ComputerShopProvider/OrdererClientApp/Views/Home/Order.cshtml b/ComputerShopProvider/OrdererClientApp/Views/Home/Order.cshtml new file mode 100644 index 0000000..57e780c --- /dev/null +++ b/ComputerShopProvider/OrdererClientApp/Views/Home/Order.cshtml @@ -0,0 +1,75 @@ +@using ComputerShopContracts.ViewModels + +@model List + +@{ + ViewData["Title"] = "Order"; +} + +
+

Заказы

+
+ + +
+ @{ + if (Model == null) + { +

Авторизируйтесь

+ return; + } + +

+ Создать заказ +

+

+ Изменить заказ +

+

+ Удалить заказ +

+ + + + + + + + + + + + @foreach (var item in Model) + { + + + + + @Html.DisplayFor(modelItem => item.DateCreate) + + @Html.DisplayFor(modelItem => item.DateImplement) + + + } + +
+ Номер + + Сумма + + Статус + + Дата создания + + Дата выполнения +
+ @Html.DisplayFor(modelItem => item.Id) + + @Html.DisplayFor(modelItem => item.Sum) + + @Html.DisplayFor(modelItem => item.Status) +
+ } +
\ No newline at end of file diff --git a/ComputerShopProvider/OrdererClientApp/Views/Home/Supply.cshtml b/ComputerShopProvider/OrdererClientApp/Views/Home/Supply.cshtml index f64a442..8d0a125 100644 --- a/ComputerShopProvider/OrdererClientApp/Views/Home/Supply.cshtml +++ b/ComputerShopProvider/OrdererClientApp/Views/Home/Supply.cshtml @@ -1,6 +1,6 @@ @using ComputerShopContracts.ViewModels -@model List +@model List @{ ViewData["Title"] = "Supply"; @@ -20,7 +20,7 @@ }

- Создать поставку + Создать поставку

@@ -29,10 +29,13 @@ Номер + @@ -44,10 +47,13 @@ @Html.DisplayFor(modelItem => item.Id) + }
- Сборка + Статус - Цена + Дата создания + + Дата поставки
- @Html.DisplayFor(modelItem => item.AssemblyName) + @Html.DisplayFor(modelItem => item.Status) - @Html.DisplayFor(modelItem => item.Price) + @Html.DisplayFor(modelItem => item.DateCreate) + + @Html.DisplayFor(modelItem => item.DateImplement)