Compare commits

..

3 Commits

Author SHA1 Message Date
d7ab3a10c4 db fix 2023-05-20 09:27:59 +04:00
b4e92e4686 Db Fix 2023-05-20 09:23:37 +04:00
4967f035d9 Error fix 2023-05-20 08:34:33 +04:00
21 changed files with 862 additions and 119 deletions

View File

@ -52,7 +52,7 @@ namespace ComputerShopBusinessLogic.BusinessLogics
return true; return true;
} }
public bool TakeOrderInWork(EquipmentReceivingBindingModel model) public bool TakeInWork(EquipmentReceivingBindingModel model)
{ {
return StatusUpdate(model, EquipmentReceivingStatus.Ожидается); return StatusUpdate(model, EquipmentReceivingStatus.Ожидается);
} }
@ -92,10 +92,5 @@ namespace ComputerShopBusinessLogic.BusinessLogics
return true; return true;
} }
public bool TakeInWork(EquipmentReceivingBindingModel model)
{
throw new NotImplementedException();
}
} }
} }

View File

@ -18,11 +18,13 @@ namespace ComputerShopBusinessLogic.BusinessLogics
private readonly ILogger _logger; private readonly ILogger _logger;
private readonly IOrderStorage _orderStorage; private readonly IOrderStorage _orderStorage;
private readonly IAssemblyStorage _assemblyStorage; private readonly IAssemblyStorage _assemblyStorage;
public OrderLogic(ILogger<ComponentLogic> logger, IOrderStorage orderStorage, IAssemblyStorage assemblyStorage) private readonly ISupplyStorage _supplyStorage;
public OrderLogic(ILogger<ComponentLogic> logger, IOrderStorage orderStorage, IAssemblyStorage assemblyStorage, ISupplyStorage supplyStorage)
{ {
_logger = logger; _logger = logger;
_orderStorage = orderStorage; _orderStorage = orderStorage;
_assemblyStorage = assemblyStorage; _assemblyStorage = assemblyStorage;
_supplyStorage = supplyStorage;
} }
public bool CreateOrder(OrderBindingModel model) public bool CreateOrder(OrderBindingModel model)
{ {
@ -162,5 +164,6 @@ namespace ComputerShopBusinessLogic.BusinessLogics
return true; return true;
} }
} }
} }

View File

@ -17,10 +17,13 @@ namespace ComputerShopBusinessLogic.BusinessLogics
{ {
private readonly ILogger _logger; private readonly ILogger _logger;
private readonly ISupplyStorage _supplyStorage; private readonly ISupplyStorage _supplyStorage;
public SupplyLogic(ILogger logger, ISupplyStorage supplyStorage) private readonly IOrderStorage _orderStorage;
public SupplyLogic(ILogger logger, ISupplyStorage supplyStorage, IOrderStorage orderStorage)
{ {
_logger = logger; _logger = logger;
_supplyStorage = supplyStorage; _supplyStorage = supplyStorage;
_orderStorage = orderStorage;
} }
public bool Create(SupplyBindingModel model) public bool Create(SupplyBindingModel model)
{ {
@ -112,5 +115,31 @@ namespace ComputerShopBusinessLogic.BusinessLogics
} }
return true; return true;
} }
public bool AddOrder(SupplySearchModel supplymodel, OrderSearchModel model)
{
if (model == null)
{
throw new ArgumentNullException(nameof(model));
}
var order = _orderStorage.GetElement(model);
var supply = _supplyStorage.GetElement(supplymodel);
if (order == null || supply == null)
{
return false;
}
order.SupplyOrders[order.Id] = order;
_supplyStorage.Update(new()
{
Id = supply.Id,
SupplyOrders = supply.SupplyOrders,
});
return true;
}
} }
} }

View File

@ -11,6 +11,7 @@ namespace ComputerShopContracts.BindingModels
public class EquipmentReceivingBindingModel : IEquipmentReceivingModel public class EquipmentReceivingBindingModel : IEquipmentReceivingModel
{ {
public int Id { get; set; } public int Id { get; set; }
public int ClientId { get; set; }
public EquipmentReceivingStatus Status { get; set; } = EquipmentReceivingStatus.Неизвестен; public EquipmentReceivingStatus Status { get; set; } = EquipmentReceivingStatus.Неизвестен;
public DateTime? DateImplement { get; set; } public DateTime? DateImplement { get; set; }

View File

@ -11,7 +11,9 @@ namespace ComputerShopContracts.BindingModels
public class SupplyBindingModel : ISupplyModel public class SupplyBindingModel : ISupplyModel
{ {
public int Id { get; set; } public int Id { get; set; }
public int? ReceivingId { get; set; } public int ClientId { get; set; }
public int ReceivingId { get; set; }
public SupplyStatus Status { get; set; } = SupplyStatus.Неизвестен; public SupplyStatus Status { get; set; } = SupplyStatus.Неизвестен;
public DateTime DateCreate { get; set; } = DateTime.Now; public DateTime DateCreate { get; set; } = DateTime.Now;

View File

@ -18,5 +18,6 @@ namespace ComputerShopContracts.BusinessLogicContracts
bool Delete(SupplyBindingModel model); bool Delete(SupplyBindingModel model);
bool TakeInWork(SupplyBindingModel model); bool TakeInWork(SupplyBindingModel model);
bool Finish(SupplyBindingModel model); bool Finish(SupplyBindingModel model);
bool AddOrder(SupplySearchModel supplymodel, OrderSearchModel model);
} }
} }

View File

@ -10,6 +10,7 @@ namespace ComputerShopContracts.SearchModels
public class EquipmentReceivingSearchModel public class EquipmentReceivingSearchModel
{ {
public int? Id { get; set; } public int? Id { get; set; }
public int? ClientId { get; set; }
public DateTime? DateFrom { get; set; } public DateTime? DateFrom { get; set; }
public DateTime? DateTo { get; set; } public DateTime? DateTo { get; set; }
public SupplySearchModel? Supply { get; set; } public SupplySearchModel? Supply { get; set; }

View File

@ -9,6 +9,7 @@ namespace ComputerShopContracts.SearchModels
public class SupplySearchModel public class SupplySearchModel
{ {
public int? Id { get; set; } public int? Id { get; set; }
public int? ClientId { get; set; }
public DateTime? DateFrom { get; set; } public DateTime? DateFrom { get; set; }
public DateTime? DateTo { get; set; } public DateTime? DateTo { get; set; }
public ComponentSearchModel? Component { get; set; } public ComponentSearchModel? Component { get; set; }

View File

@ -19,5 +19,7 @@ namespace ComputerShopContracts.ViewModels
[DisplayName("Номер")] [DisplayName("Номер")]
public int Id { get; set; } public int Id { get; set; }
[DisplayName("Номер клиента")]
public int ClientId { get; set; }
} }
} }

View File

@ -24,7 +24,7 @@ namespace ComputerShopContracts.ViewModels
get; get;
set; set;
} = new(); } = new();
public Dictionary<int, ISupplyModel> SupplyOrders public Dictionary<int, IOrderModel> SupplyOrders
{ {
get; get;
set; set;

View File

@ -22,6 +22,9 @@ namespace ComputerShopContracts.ViewModels
[DisplayName("Номер")] [DisplayName("Номер")]
public int Id { get; set; } public int Id { get; set; }
[DisplayName("Номер клиента")]
public int ClientId { get; set; }
[DisplayName("Номер получения")] [DisplayName("Номер получения")]
public int? ReceivingId { get; set; } public int? ReceivingId { get; set; }
public Dictionary<int, IOrderModel> SupplyOrders public Dictionary<int, IOrderModel> SupplyOrders

View File

@ -0,0 +1,540 @@
// <auto-generated />
using System;
using ComputerShopDatabaseImplement;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Metadata;
using Microsoft.EntityFrameworkCore.Migrations;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
#nullable disable
namespace ComputerShopDatabaseImplement.Migrations
{
[DbContext(typeof(ComputerShopDatabase))]
[Migration("20230520051723_fix")]
partial class fix
{
/// <inheritdoc />
protected override void BuildTargetModel(ModelBuilder modelBuilder)
{
#pragma warning disable 612, 618
modelBuilder
.HasAnnotation("ProductVersion", "7.0.4")
.HasAnnotation("Relational:MaxIdentifierLength", 128);
SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder);
modelBuilder.Entity("ComputerShopDatabaseImplement.Models.Assembly", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<string>("AssemblyName")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<int>("ClientId")
.HasColumnType("int");
b.Property<double>("Price")
.HasColumnType("float");
b.HasKey("Id");
b.HasIndex("ClientId");
b.ToTable("Assemblies");
});
modelBuilder.Entity("ComputerShopDatabaseImplement.Models.AssemblyComponent", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<int>("AssemblyId")
.HasColumnType("int");
b.Property<int>("ComponentId")
.HasColumnType("int");
b.Property<int>("Count")
.HasColumnType("int");
b.HasKey("Id");
b.HasIndex("AssemblyId");
b.HasIndex("ComponentId");
b.ToTable("AssemblyComponents");
});
modelBuilder.Entity("ComputerShopDatabaseImplement.Models.AssemblyOrder", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<int>("AssemblyId")
.HasColumnType("int");
b.Property<int>("Count")
.HasColumnType("int");
b.Property<int>("OrderId")
.HasColumnType("int");
b.HasKey("Id");
b.HasIndex("AssemblyId");
b.HasIndex("OrderId");
b.ToTable("AssemblyOrders");
});
modelBuilder.Entity("ComputerShopDatabaseImplement.Models.Client", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<string>("ClientFIO")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<string>("Email")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<string>("Password")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.HasKey("Id");
b.ToTable("Clients");
});
modelBuilder.Entity("ComputerShopDatabaseImplement.Models.Component", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<int>("ClientId")
.HasColumnType("int");
b.Property<string>("ComponentName")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<double>("Cost")
.HasColumnType("float");
b.HasKey("Id");
b.HasIndex("ClientId");
b.ToTable("Components");
});
modelBuilder.Entity("ComputerShopDatabaseImplement.Models.ComponentSupply", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<int>("ComponentId")
.HasColumnType("int");
b.Property<int>("Count")
.HasColumnType("int");
b.Property<int>("SupplyId")
.HasColumnType("int");
b.HasKey("Id");
b.HasIndex("ComponentId");
b.HasIndex("SupplyId");
b.ToTable("ComponentSupplies");
});
modelBuilder.Entity("ComputerShopDatabaseImplement.Models.EquipmentReceiving", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<int>("ClientId")
.HasColumnType("int");
b.Property<DateTime?>("DateImplement")
.HasColumnType("datetime2");
b.Property<int>("Status")
.HasColumnType("int");
b.HasKey("Id");
b.HasIndex("ClientId");
b.ToTable("EquipmentReceivings");
});
modelBuilder.Entity("ComputerShopDatabaseImplement.Models.Order", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<int>("ClientId")
.HasColumnType("int");
b.Property<DateTime>("DateCreate")
.HasColumnType("datetime2");
b.Property<DateTime?>("DateImplement")
.HasColumnType("datetime2");
b.Property<int>("Status")
.HasColumnType("int");
b.Property<double>("Sum")
.HasColumnType("float");
b.HasKey("Id");
b.HasIndex("ClientId");
b.ToTable("Orders");
});
modelBuilder.Entity("ComputerShopDatabaseImplement.Models.Purchase", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<int>("ClientId")
.HasColumnType("int");
b.Property<int>("ComponentId")
.HasColumnType("int");
b.Property<string>("ComponentName")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<int>("Count")
.HasColumnType("int");
b.Property<DateTime>("DateCreate")
.HasColumnType("datetime2");
b.Property<DateTime?>("DateImplement")
.HasColumnType("datetime2");
b.Property<int>("Status")
.HasColumnType("int");
b.Property<double>("Sum")
.HasColumnType("float");
b.HasKey("Id");
b.HasIndex("ClientId");
b.HasIndex("ComponentId");
b.ToTable("Purchases");
});
modelBuilder.Entity("ComputerShopDatabaseImplement.Models.Supply", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<int>("ClientId")
.HasColumnType("int");
b.Property<DateTime>("DateCreate")
.HasColumnType("datetime2");
b.Property<DateTime?>("DateImplement")
.HasColumnType("datetime2");
b.Property<int>("OrderId")
.HasColumnType("int");
b.Property<int>("ReceivingId")
.HasColumnType("int");
b.Property<int>("Status")
.HasColumnType("int");
b.HasKey("Id");
b.HasIndex("ClientId");
b.HasIndex("ReceivingId");
b.ToTable("Supplies");
});
modelBuilder.Entity("ComputerShopDatabaseImplement.Models.SupplyOrder", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<int>("Count")
.HasColumnType("int");
b.Property<int>("OrderId")
.HasColumnType("int");
b.Property<int>("SupplyId")
.HasColumnType("int");
b.HasKey("Id");
b.HasIndex("OrderId");
b.HasIndex("SupplyId");
b.ToTable("SupplyOrders");
});
modelBuilder.Entity("ComputerShopDatabaseImplement.Models.Assembly", b =>
{
b.HasOne("ComputerShopDatabaseImplement.Models.Client", "Client")
.WithMany("Assemblies")
.HasForeignKey("ClientId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Client");
});
modelBuilder.Entity("ComputerShopDatabaseImplement.Models.AssemblyComponent", b =>
{
b.HasOne("ComputerShopDatabaseImplement.Models.Assembly", "Assembly")
.WithMany("Components")
.HasForeignKey("AssemblyId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("ComputerShopDatabaseImplement.Models.Component", "Component")
.WithMany("AssemblyComponents")
.HasForeignKey("ComponentId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Assembly");
b.Navigation("Component");
});
modelBuilder.Entity("ComputerShopDatabaseImplement.Models.AssemblyOrder", b =>
{
b.HasOne("ComputerShopDatabaseImplement.Models.Assembly", "Assembly")
.WithMany("Orders")
.HasForeignKey("AssemblyId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("ComputerShopDatabaseImplement.Models.Order", "Order")
.WithMany("Assemblies")
.HasForeignKey("OrderId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Assembly");
b.Navigation("Order");
});
modelBuilder.Entity("ComputerShopDatabaseImplement.Models.Component", b =>
{
b.HasOne("ComputerShopDatabaseImplement.Models.Client", null)
.WithMany("Components")
.HasForeignKey("ClientId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
});
modelBuilder.Entity("ComputerShopDatabaseImplement.Models.ComponentSupply", b =>
{
b.HasOne("ComputerShopDatabaseImplement.Models.Component", "Component")
.WithMany("Supplies")
.HasForeignKey("ComponentId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("ComputerShopDatabaseImplement.Models.Supply", "Supply")
.WithMany("ComponentSupplies")
.HasForeignKey("SupplyId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Component");
b.Navigation("Supply");
});
modelBuilder.Entity("ComputerShopDatabaseImplement.Models.EquipmentReceiving", b =>
{
b.HasOne("ComputerShopDatabaseImplement.Models.Client", null)
.WithMany("EquipmentReceivings")
.HasForeignKey("ClientId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
});
modelBuilder.Entity("ComputerShopDatabaseImplement.Models.Order", b =>
{
b.HasOne("ComputerShopDatabaseImplement.Models.Client", null)
.WithMany("Orders")
.HasForeignKey("ClientId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
});
modelBuilder.Entity("ComputerShopDatabaseImplement.Models.Purchase", b =>
{
b.HasOne("ComputerShopDatabaseImplement.Models.Client", "Client")
.WithMany("Purchases")
.HasForeignKey("ClientId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("ComputerShopDatabaseImplement.Models.Component", "Component")
.WithMany("Purchases")
.HasForeignKey("ComponentId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Client");
b.Navigation("Component");
});
modelBuilder.Entity("ComputerShopDatabaseImplement.Models.Supply", b =>
{
b.HasOne("ComputerShopDatabaseImplement.Models.Client", null)
.WithMany("Supplies")
.HasForeignKey("ClientId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("ComputerShopDatabaseImplement.Models.EquipmentReceiving", "Receiving")
.WithMany("Supplies")
.HasForeignKey("ReceivingId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Receiving");
});
modelBuilder.Entity("ComputerShopDatabaseImplement.Models.SupplyOrder", b =>
{
b.HasOne("ComputerShopDatabaseImplement.Models.Order", "Order")
.WithMany("SupplyOrders")
.HasForeignKey("OrderId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("ComputerShopDatabaseImplement.Models.Supply", "Supply")
.WithMany("Orders")
.HasForeignKey("SupplyId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Order");
b.Navigation("Supply");
});
modelBuilder.Entity("ComputerShopDatabaseImplement.Models.Assembly", b =>
{
b.Navigation("Components");
b.Navigation("Orders");
});
modelBuilder.Entity("ComputerShopDatabaseImplement.Models.Client", b =>
{
b.Navigation("Assemblies");
b.Navigation("Components");
b.Navigation("EquipmentReceivings");
b.Navigation("Orders");
b.Navigation("Purchases");
b.Navigation("Supplies");
});
modelBuilder.Entity("ComputerShopDatabaseImplement.Models.Component", b =>
{
b.Navigation("AssemblyComponents");
b.Navigation("Purchases");
b.Navigation("Supplies");
});
modelBuilder.Entity("ComputerShopDatabaseImplement.Models.EquipmentReceiving", b =>
{
b.Navigation("Supplies");
});
modelBuilder.Entity("ComputerShopDatabaseImplement.Models.Order", b =>
{
b.Navigation("Assemblies");
b.Navigation("SupplyOrders");
});
modelBuilder.Entity("ComputerShopDatabaseImplement.Models.Supply", b =>
{
b.Navigation("ComponentSupplies");
b.Navigation("Orders");
});
#pragma warning restore 612, 618
}
}
}

View File

@ -0,0 +1,141 @@
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace ComputerShopDatabaseImplement.Migrations
{
/// <inheritdoc />
public partial class fix : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropForeignKey(
name: "FK_EquipmentReceivings_Clients_ClientId",
table: "EquipmentReceivings");
migrationBuilder.DropForeignKey(
name: "FK_Orders_Clients_ClientId",
table: "Orders");
migrationBuilder.DropForeignKey(
name: "FK_Supplies_Clients_ClientId",
table: "Supplies");
migrationBuilder.AlterColumn<int>(
name: "ClientId",
table: "Supplies",
type: "int",
nullable: false,
defaultValue: 0,
oldClrType: typeof(int),
oldType: "int",
oldNullable: true);
migrationBuilder.AlterColumn<int>(
name: "ClientId",
table: "Orders",
type: "int",
nullable: false,
defaultValue: 0,
oldClrType: typeof(int),
oldType: "int",
oldNullable: true);
migrationBuilder.AlterColumn<int>(
name: "ClientId",
table: "EquipmentReceivings",
type: "int",
nullable: false,
defaultValue: 0,
oldClrType: typeof(int),
oldType: "int",
oldNullable: true);
migrationBuilder.AddForeignKey(
name: "FK_EquipmentReceivings_Clients_ClientId",
table: "EquipmentReceivings",
column: "ClientId",
principalTable: "Clients",
principalColumn: "Id",
onDelete: ReferentialAction.NoAction);
migrationBuilder.AddForeignKey(
name: "FK_Orders_Clients_ClientId",
table: "Orders",
column: "ClientId",
principalTable: "Clients",
principalColumn: "Id",
onDelete: ReferentialAction.NoAction);
migrationBuilder.AddForeignKey(
name: "FK_Supplies_Clients_ClientId",
table: "Supplies",
column: "ClientId",
principalTable: "Clients",
principalColumn: "Id",
onDelete: ReferentialAction.NoAction);
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropForeignKey(
name: "FK_EquipmentReceivings_Clients_ClientId",
table: "EquipmentReceivings");
migrationBuilder.DropForeignKey(
name: "FK_Orders_Clients_ClientId",
table: "Orders");
migrationBuilder.DropForeignKey(
name: "FK_Supplies_Clients_ClientId",
table: "Supplies");
migrationBuilder.AlterColumn<int>(
name: "ClientId",
table: "Supplies",
type: "int",
nullable: true,
oldClrType: typeof(int),
oldType: "int");
migrationBuilder.AlterColumn<int>(
name: "ClientId",
table: "Orders",
type: "int",
nullable: true,
oldClrType: typeof(int),
oldType: "int");
migrationBuilder.AlterColumn<int>(
name: "ClientId",
table: "EquipmentReceivings",
type: "int",
nullable: true,
oldClrType: typeof(int),
oldType: "int");
migrationBuilder.AddForeignKey(
name: "FK_EquipmentReceivings_Clients_ClientId",
table: "EquipmentReceivings",
column: "ClientId",
principalTable: "Clients",
principalColumn: "Id");
migrationBuilder.AddForeignKey(
name: "FK_Orders_Clients_ClientId",
table: "Orders",
column: "ClientId",
principalTable: "Clients",
principalColumn: "Id");
migrationBuilder.AddForeignKey(
name: "FK_Supplies_Clients_ClientId",
table: "Supplies",
column: "ClientId",
principalTable: "Clients",
principalColumn: "Id");
}
}
}

View File

@ -183,7 +183,7 @@ namespace ComputerShopDatabaseImplement.Migrations
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id")); SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<int?>("ClientId") b.Property<int>("ClientId")
.HasColumnType("int"); .HasColumnType("int");
b.Property<DateTime?>("DateImplement") b.Property<DateTime?>("DateImplement")
@ -207,7 +207,7 @@ namespace ComputerShopDatabaseImplement.Migrations
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id")); SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<int?>("ClientId") b.Property<int>("ClientId")
.HasColumnType("int"); .HasColumnType("int");
b.Property<DateTime>("DateCreate") b.Property<DateTime>("DateCreate")
@ -279,7 +279,7 @@ namespace ComputerShopDatabaseImplement.Migrations
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id")); SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<int?>("ClientId") b.Property<int>("ClientId")
.HasColumnType("int"); .HasColumnType("int");
b.Property<DateTime>("DateCreate") b.Property<DateTime>("DateCreate")
@ -413,14 +413,18 @@ namespace ComputerShopDatabaseImplement.Migrations
{ {
b.HasOne("ComputerShopDatabaseImplement.Models.Client", null) b.HasOne("ComputerShopDatabaseImplement.Models.Client", null)
.WithMany("EquipmentReceivings") .WithMany("EquipmentReceivings")
.HasForeignKey("ClientId"); .HasForeignKey("ClientId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
}); });
modelBuilder.Entity("ComputerShopDatabaseImplement.Models.Order", b => modelBuilder.Entity("ComputerShopDatabaseImplement.Models.Order", b =>
{ {
b.HasOne("ComputerShopDatabaseImplement.Models.Client", null) b.HasOne("ComputerShopDatabaseImplement.Models.Client", null)
.WithMany("Orders") .WithMany("Orders")
.HasForeignKey("ClientId"); .HasForeignKey("ClientId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
}); });
modelBuilder.Entity("ComputerShopDatabaseImplement.Models.Purchase", b => modelBuilder.Entity("ComputerShopDatabaseImplement.Models.Purchase", b =>
@ -446,13 +450,17 @@ namespace ComputerShopDatabaseImplement.Migrations
{ {
b.HasOne("ComputerShopDatabaseImplement.Models.Client", null) b.HasOne("ComputerShopDatabaseImplement.Models.Client", null)
.WithMany("Supplies") .WithMany("Supplies")
.HasForeignKey("ClientId"); .HasForeignKey("ClientId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("ComputerShopDatabaseImplement.Models.EquipmentReceiving", null) b.HasOne("ComputerShopDatabaseImplement.Models.EquipmentReceiving", "Receiving")
.WithMany("Supplies") .WithMany("Supplies")
.HasForeignKey("ReceivingId") .HasForeignKey("ReceivingId")
.OnDelete(DeleteBehavior.Cascade) .OnDelete(DeleteBehavior.Cascade)
.IsRequired(); .IsRequired();
b.Navigation("Receiving");
}); });
modelBuilder.Entity("ComputerShopDatabaseImplement.Models.SupplyOrder", b => modelBuilder.Entity("ComputerShopDatabaseImplement.Models.SupplyOrder", b =>

View File

@ -38,20 +38,6 @@ namespace ComputerShopDatabaseImplement.Models
} }
private Dictionary<int, (IOrderModel, int)>? _assemblyOrders = null; private Dictionary<int, (IOrderModel, int)>? _assemblyOrders = null;
[NotMapped]
public Dictionary<int, (IOrderModel, int)> AssemblyOrders
{
get
{
if (_assemblyOrders == null)
{
_assemblyOrders = Orders
.ToDictionary(recPC => recPC.OrderId, recPC =>
(recPC.Order as IOrderModel, recPC.Count));
}
return _assemblyOrders;
}
}
[ForeignKey("AssemblyId")] [ForeignKey("AssemblyId")]
public virtual List<AssemblyComponent> Components { get; set; } = new(); public virtual List<AssemblyComponent> Components { get; set; } = new();
[ForeignKey("AssemblyId")] [ForeignKey("AssemblyId")]
@ -90,7 +76,6 @@ namespace ComputerShopDatabaseImplement.Models
AssemblyName = AssemblyName, AssemblyName = AssemblyName,
Price = Price, Price = Price,
AssemblyComponents = AssemblyComponents, AssemblyComponents = AssemblyComponents,
AssemblyOrders = AssemblyOrders,
ClientId = ClientId ClientId = ClientId
}; };
public void UpdateComponents(ComputerShopDatabase context, AssemblyBindingModel model) public void UpdateComponents(ComputerShopDatabase context, AssemblyBindingModel model)

View File

@ -22,6 +22,8 @@ namespace ComputerShopDatabaseImplement.Models
[ForeignKey("ReceivingId")] [ForeignKey("ReceivingId")]
public List<Supply> Supplies { get; set; } = new(); public List<Supply> Supplies { get; set; } = new();
[Required]
public int ClientId { get; set; }
public static EquipmentReceiving? Create(EquipmentReceivingBindingModel? model) public static EquipmentReceiving? Create(EquipmentReceivingBindingModel? model)
{ {
@ -34,6 +36,7 @@ namespace ComputerShopDatabaseImplement.Models
Status = model.Status, Status = model.Status,
DateImplement = model.DateImplement, DateImplement = model.DateImplement,
Id = model.Id, Id = model.Id,
ClientId = model.ClientId
}; };
} }
@ -52,6 +55,7 @@ namespace ComputerShopDatabaseImplement.Models
DateImplement = DateImplement, DateImplement = DateImplement,
Id = Id, Id = Id,
Status = Status, Status = Status,
ClientId = ClientId
}; };
} }
} }

View File

@ -24,8 +24,7 @@ namespace ComputerShopDatabaseImplement.Models
public DateTime? DateImplement { get; private set; } public DateTime? DateImplement { get; private set; }
[ForeignKey("OrderId")] [ForeignKey("OrderId")]
public virtual List<SupplyOrder> Supplies { get; set; } = new(); public virtual List<SupplyOrder> SupplyOrders { get; set; } = new();
private Dictionary<int, IOrderModel>? _supplyOrders = null;
[ForeignKey("OrderId")] [ForeignKey("OrderId")]
public virtual List<AssemblyOrder> Assemblies { get; set; } = new(); public virtual List<AssemblyOrder> Assemblies { get; set; } = new();
@ -45,20 +44,6 @@ namespace ComputerShopDatabaseImplement.Models
return _assemblyOrders; return _assemblyOrders;
} }
} }
[NotMapped]
public Dictionary<int, IOrderModel> SupplyOrders
{
get
{
if (_supplyOrders == null)
{
_supplyOrders = Supplies
.ToDictionary(recPC => recPC.SupplyId, recPC =>
(recPC.Order as IOrderModel));
}
return _supplyOrders;
}
}
[Required] [Required]
public int ClientId { get; set; } public int ClientId { get; set; }

View File

@ -24,6 +24,7 @@ namespace ComputerShopDatabaseImplement.Models
public DateTime? DateImplement { get; private set; } public DateTime? DateImplement { get; private set; }
public int OrderId { get; set; } public int OrderId { get; set; }
public int ClientId { get; set; }
public int? ReceivingId { get; set; } public int? ReceivingId { get; set; }
public virtual EquipmentReceiving Receiving { get; set; } public virtual EquipmentReceiving Receiving { get; set; }
@ -53,6 +54,7 @@ namespace ComputerShopDatabaseImplement.Models
return new Supply return new Supply
{ {
Id = model.Id, Id = model.Id,
ClientId = model.ClientId,
Status = model.Status, Status = model.Status,
DateCreate = model.DateCreate, DateCreate = model.DateCreate,
DateImplement = model.DateImplement, DateImplement = model.DateImplement,
@ -78,7 +80,8 @@ namespace ComputerShopDatabaseImplement.Models
Status = Status, Status = Status,
DateCreate = DateCreate, DateCreate = DateCreate,
DateImplement = DateImplement, DateImplement = DateImplement,
SupplyOrders = SupplyOrders SupplyOrders = SupplyOrders,
ClientId = ClientId
}; };
public void UpdateOrders(ComputerShopDatabase context, SupplyBindingModel model) public void UpdateOrders(ComputerShopDatabase context, SupplyBindingModel model)
{ {

View File

@ -1,4 +1,8 @@
using Microsoft.AspNetCore.Http; using ComputerShopContracts.BindingModels;
using ComputerShopContracts.BusinessLogicContracts;
using ComputerShopContracts.SearchModels;
using ComputerShopContracts.ViewModels;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
namespace ComputerShopRestApi.Controllers namespace ComputerShopRestApi.Controllers
@ -7,6 +11,55 @@ namespace ComputerShopRestApi.Controllers
[ApiController] [ApiController]
public class EquipmentReceivingController : Controller public class EquipmentReceivingController : Controller
{ {
private readonly ILogger _logger;
private readonly IEquipmentReceivingLogic _equipmentReceiving;
public EquipmentReceivingController(ILogger<MainController> logger, IEquipmentReceivingLogic equipmentReceiving)
{
_logger = logger;
_equipmentReceiving = equipmentReceiving;
}
[HttpGet]
public List<EquipmentReceivingViewModel>? GetReceivingList()
{
try
{
return _equipmentReceiving.ReadList(null);
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка получения списка компонентов");
throw;
}
}
[HttpGet]
public List<EquipmentReceivingViewModel>? GetReceivings(int clientId)
{
try
{
return _equipmentReceiving.ReadList(new EquipmentReceivingSearchModel
{
ClientId = clientId
});
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка получения списка получений клиента id ={ Id}", clientId);
throw;
}
}
[HttpPost]
public void CreateReceiving(EquipmentReceivingBindingModel model)
{
try
{
_equipmentReceiving.Create(model);
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка создания получения");
throw;
}
}
} }
} }

View File

@ -14,24 +14,40 @@ namespace ComputerShopRestApi.Controllers
private readonly ILogger _logger; private readonly ILogger _logger;
private readonly ISupplyLogic _supply; private readonly ISupplyLogic _supply;
private readonly IOrderLogic _order; private readonly IOrderLogic _order;
public SupplyController(ILogger<SupplyController> logger, ISupplyLogic supply, IOrderLogic order) private readonly IEquipmentReceivingLogic _equipmentReceiving;
public SupplyController(ILogger<SupplyController> logger, ISupplyLogic supply, IOrderLogic order, IEquipmentReceivingLogic equipmentReceiving)
{ {
_logger = logger; _logger = logger;
_supply = supply; _supply = supply;
_order = order; _order = order;
_equipmentReceiving = equipmentReceiving;
} }
/* [HttpGet]
public List<EquipmentReceivingViewModel>? GetReceivingList(int clientId)
{
try
{
return _equipmentReceiving.ReadList(new EquipmentReceivingSearchModel
{
ClientId = clientId
});
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка получения списка поставок клиента id ={ Id}", clientId);
throw;
}
}
[HttpGet] [HttpGet]
public List<AssemblyViewModel>? GetAssemblyList(int clientId) public List<SupplyViewModel>? GetSupplyList(int componentid)
{ {
try try
{ {
return _supply.ReadList(new SupplySearchModel return _supply.ReadList(new SupplySearchModel { ComponentId = componentid });
{
});
} }
catch (Exception ex) catch (Exception ex)
{ {
@ -41,91 +57,72 @@ namespace ComputerShopRestApi.Controllers
} }
[HttpGet] [HttpGet]
public Tuple<AssemblyViewModel, List<Tuple<string, int>>>? GetAssembly(int assemblyId) public List<OrderViewModel>? GetOrderList()
{ {
try try
{ {
var elem = _supply.ReadElement(new SupplySearchModel { Id = assemblyId }); return _order.ReadList(null);
if (elem == null)
return null;
return Tuple.Create(elem, elem.AssemblyComponents.Select(x => Tuple.Create(x.Value.Item1.ComponentName, x.Value.Item2)).ToList());
} }
catch (Exception ex) catch (Exception ex)
{ {
_logger.LogError(ex, "Ошибка получения сборки по id={Id}", assemblyId); _logger.LogError(ex, "Ошибка получения списка заказов");
throw;
}
}
[HttpGet]
public List<ComponentViewModel>? GetComponentList()
{
try
{
return _component.ReadList(null);
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка получения списка компонентов");
throw; throw;
} }
} }
[HttpPost] [HttpPost]
public void CreateAssembly(AssemblyBindingModel model) public void CreateSupply(SupplyBindingModel model)
{ {
try try
{ {
_assembly.Create(model); _supply.Create(model);
} }
catch (Exception ex) catch (Exception ex)
{ {
_logger.LogError(ex, "Ошибка создания сборки"); _logger.LogError(ex, "Ошибка создания поставки");
throw; throw;
} }
} }
[HttpPost] [HttpPost]
public void DeleteAssembly(AssemblyBindingModel model) public void DeleteSupply(SupplyBindingModel model)
{ {
try try
{ {
_assembly.Delete(model); _supply.Delete(model);
} }
catch (Exception ex) catch (Exception ex)
{ {
_logger.LogError(ex, "Ошибка удаления сборки"); _logger.LogError(ex, "Ошибка удаления поставки");
throw; throw;
} }
} }
[HttpPost] [HttpPost]
public void AddComponentToAssembly(Tuple<AssemblySearchModel, ComponentSearchModel, int> model) public void AddOrderToSupply(Tuple<SupplySearchModel, OrderSearchModel> model)
{ {
try try
{ {
_assembly.AddComponentToAssembly(model.Item1, model.Item2, model.Item3); _supply.AddOrder(model.Item1, model.Item2);
} }
catch (Exception ex) catch (Exception ex)
{ {
_logger.LogError(ex, "Ошибка добавления компонента в сборку."); _logger.LogError(ex, "Ошибка.");
throw; throw;
} }
} }
[HttpPost] [HttpPost]
public void EditAssembly(AssemblyBindingModel model) public void EditOrder(OrderBindingModel model)
{ {
try try
{ {
_assembly.Update(model); _order.Update(model);
} }
catch (Exception ex) catch (Exception ex)
{ {
_logger.LogError(ex, "Ошибка удаления сборки"); _logger.LogError(ex, "Ошибка удаления заказа");
throw; throw;
} }
} }
*/
} }
} }

View File

@ -127,54 +127,43 @@ namespace OrdererClientApp.Controllers
} }
[HttpGet] [HttpGet]
public IActionResult CreatePurchase() public IActionResult CreateEquipmentReceiving()
{ {
ViewBag.Components = APIClient.GetRequest<List<ComponentViewModel>>("api/main/getcomponentlist"); ViewBag.EquipmentReceivings = APIClient.GetRequest<List<EquipmentReceivingViewModel>>("api/main/getreceivingslist");
return View(); return View();
} }
[HttpPost] [HttpPost]
public void CreatePurchase(int component, int count) public void CreateSupply(int receiving)
{ {
if (APIClient.Client == null) if (APIClient.Client == null)
{ {
throw new Exception("Вы как суда попали? Суда вход только авторизованным"); throw new Exception("Вы как суда попали? Суда вход только авторизованным");
} }
if (count <= 0)
{ APIClient.PostRequest("api/main/createreceiving", new SupplyBindingModel
throw new Exception("Количество и сумма должны быть больше 0");
}
APIClient.PostRequest("api/main/createpurchase", new PurchaseBindingModel
{ {
ClientId = APIClient.Client.Id, ClientId = APIClient.Client.Id,
ComponentId = component, ReceivingId = receiving,
Count = count,
Sum = Calc(count, component)
}); });
Response.Redirect("Index"); Response.Redirect("Index");
} }
[HttpGet] [HttpGet]
public IActionResult CreateComponent() public IActionResult CreateOrder()
{ {
return View(); return View();
} }
[HttpPost] [HttpPost]
public void CreateComponent(string name, int cost) public void CreateOrder(int sum)
{ {
if (APIClient.Client == null) if (APIClient.Client == null)
{ {
throw new Exception("Вы как суда попали? Суда вход только авторизованным"); throw new Exception("Вы как суда попали? Суда вход только авторизованным");
} }
if (cost <= 0) APIClient.PostRequest("api/order/createorder", new OrderBindingModel
{
throw new Exception("Цена должна быть больше 0");
}
APIClient.PostRequest("api/component/createcomponent", new ComponentBindingModel
{ {
ClientId = APIClient.Client.Id, ClientId = APIClient.Client.Id,
ComponentName = name,
Cost = cost
}); });
Response.Redirect("Index"); Response.Redirect("Index");
} }
@ -218,13 +207,13 @@ namespace OrdererClientApp.Controllers
{ {
throw new Exception("Сумма должна быть больше 0"); throw new Exception("Сумма должна быть больше 0");
} }
//APIClient.PostRequest("api/assembly/createassembly", new AssemblyBindingModel APIClient.PostRequest("api/assembly/createassembly", new AssemblyBindingModel
//{ {
// ClientId = APIClient.Client.Id, ClientId = APIClient.Client.Id,
// AssemblyName = name, AssemblyName = name,
// Price = 0, Price = 0,
// AssemblyComponents = new() AssemblyComponents = new()
//}); });
System.Diagnostics.Debug.WriteLine("it might work"); System.Diagnostics.Debug.WriteLine("it might work");
Response.Redirect("Index"); Response.Redirect("Index");
} }