This commit is contained in:
the 2023-05-24 18:51:13 +04:00
parent dc3dab57ba
commit 92235ba186
9 changed files with 618 additions and 17 deletions

View File

@ -10,6 +10,7 @@ using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
using ComputerShopDataModels.Enums;
namespace ComputerShopBusinessLogic.BusinessLogics namespace ComputerShopBusinessLogic.BusinessLogics
{ {
@ -38,6 +39,9 @@ namespace ComputerShopBusinessLogic.BusinessLogics
{ {
var result = new List<ReportComponentReceivingViewModel>(); var result = new List<ReportComponentReceivingViewModel>();
var supplies1 = _supplyStorage.GetFullList();
var recs = _receivingStorage.GetFullList();
foreach (int id in ids) foreach (int id in ids)
{ {
var component = _componentStorage.GetElement(new ComponentSearchModel() var component = _componentStorage.GetElement(new ComponentSearchModel()
@ -51,13 +55,12 @@ namespace ComputerShopBusinessLogic.BusinessLogics
var receivings = new List<EquipmentReceivingViewModel>(); var receivings = new List<EquipmentReceivingViewModel>();
foreach(var supply in supplies) foreach(var supply in supplies)
{ {
if (supply.ReceivingId.HasValue) if (supply.ReceivingId.HasValue)
{ {
var receiving = _receivingStorage.GetElement(new() { Id = supply.ReceivingId.Value }); var receiving = _receivingStorage.GetElement(new() { Id = supply.ReceivingId.Value });
if (receiving != null && receivings.Contains(receiving)) if (receiving != null && !receivings.Contains(receiving))
{ {
receivings.Add(receiving); receivings.Add(receiving);
} }
@ -68,7 +71,7 @@ namespace ComputerShopBusinessLogic.BusinessLogics
var receivingnames = new List<string>(); var receivingnames = new List<string>();
foreach (var receiving in receivings) foreach (var receiving in receivings)
{ {
receivingnames.Add($"Id: {receiving.Id}. Date: {receiving.Status}."); receivingnames.Add($"Id: {receiving.Id}. Status: {Enum.GetName(typeof(EquipmentReceivingStatus), receiving.Status)}.");
} }
if(receivingnames.Count > 0 && component != null) if(receivingnames.Count > 0 && component != null)
{ {

View File

@ -25,5 +25,11 @@ namespace ComputerShopContracts.BindingModels
get; get;
set; set;
} = new(); } = new();
public Dictionary<int, IComponentModel> SupplyComponents
{
get;
set;
} = new();
} }
} }

View File

@ -32,6 +32,11 @@ namespace ComputerShopContracts.ViewModels
get; get;
set; set;
} = new(); } = new();
public Dictionary<int, IComponentModel> SupplyComponents
{
get;
set;
} = new();
} }
} }

View File

@ -15,7 +15,7 @@ namespace ComputerShopDatabaseImplement
{ {
if (optionsBuilder.IsConfigured == false) 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-IRUVF5S\SQLEXPRESS;Initial Catalog=ComputerShopDatabaseCWW;Integrated Security=True;MultipleActiveResultSets=True;;TrustServerCertificate=True");
} }
base.OnConfiguring(optionsBuilder); base.OnConfiguring(optionsBuilder);
} }

View File

@ -52,7 +52,7 @@ namespace ComputerShopDatabaseImplement.Implements
return new(); return new();
} }
using var context = new ComputerShopDatabase(); using var context = new ComputerShopDatabase();
if(model.ComponentId.HasValue) if(!model.ComponentId.HasValue)
return context.Supplies return context.Supplies
.Include(x => x.Orders) .Include(x => x.Orders)
.ThenInclude(x => x.Order) .ThenInclude(x => x.Order)
@ -66,9 +66,9 @@ namespace ComputerShopDatabaseImplement.Implements
.Include(x => x.Orders) .Include(x => x.Orders)
.ThenInclude(x => x.Order) .ThenInclude(x => x.Order)
.Include(x => x.Receiving) .Include(x => x.Receiving)
.Include(x => x.ComponentSupplies) .Include(x => x.Components)
.ThenInclude(x => x.Component) .ThenInclude(x => x.Component)
.Where(x => x.ComponentSupplies.Any(x => x.ComponentId == model.ComponentId)) .Where(x => x.Components.Any(x => x.ComponentId == model.ComponentId))
.ToList() .ToList()
.Select(x => x.GetViewModel) .Select(x => x.GetViewModel)
.ToList(); .ToList();
@ -80,6 +80,8 @@ namespace ComputerShopDatabaseImplement.Implements
return context.Supplies return context.Supplies
.Include(x => x.Orders) .Include(x => x.Orders)
.ThenInclude(x => x.Order) .ThenInclude(x => x.Order)
.Include(x => x.Components)
.ThenInclude(x => x.Component)
.Include(x => x.Receiving) .Include(x => x.Receiving)
.ToList() .ToList()
.Select(x => x.GetViewModel) .Select(x => x.GetViewModel)

View File

@ -0,0 +1,538 @@
// <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("20230524135850_ordermig")]
partial class ordermig
{
/// <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?>("ReceivingId")
.IsRequired()
.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,29 @@
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace ComputerShopDatabaseImplement.Migrations
{
/// <inheritdoc />
public partial class ordermig : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropColumn(
name: "OrderId",
table: "Supplies");
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.AddColumn<int>(
name: "OrderId",
table: "Supplies",
type: "int",
nullable: false,
defaultValue: 0);
}
}
}

View File

@ -288,10 +288,8 @@ namespace ComputerShopDatabaseImplement.Migrations
b.Property<DateTime?>("DateImplement") b.Property<DateTime?>("DateImplement")
.HasColumnType("datetime2"); .HasColumnType("datetime2");
b.Property<int>("OrderId") b.Property<int?>("ReceivingId")
.HasColumnType("int"); .IsRequired()
b.Property<int>("ReceivingId")
.HasColumnType("int"); .HasColumnType("int");
b.Property<int>("Status") b.Property<int>("Status")

View File

@ -22,8 +22,6 @@ namespace ComputerShopDatabaseImplement.Models
public DateTime DateCreate { get; private set; } = DateTime.Now; public DateTime DateCreate { get; private set; } = DateTime.Now;
public DateTime? DateImplement { get; private set; } public DateTime? DateImplement { get; private set; }
public int OrderId { get; set; }
public int ClientId { get; set; } public int ClientId { get; set; }
public int? ReceivingId { get; set; } public int? ReceivingId { get; set; }
@ -31,6 +29,7 @@ namespace ComputerShopDatabaseImplement.Models
private Dictionary<int, IOrderModel>? _supplyOrders = private Dictionary<int, IOrderModel>? _supplyOrders =
null; null;
private Dictionary<int, IComponentModel>? _supplyComponents = null;
[NotMapped] [NotMapped]
public Dictionary<int, IOrderModel> SupplyOrders public Dictionary<int, IOrderModel> SupplyOrders
{ {
@ -44,10 +43,23 @@ namespace ComputerShopDatabaseImplement.Models
return _supplyOrders; return _supplyOrders;
} }
} }
[NotMapped]
public Dictionary<int, IComponentModel> SupplyComponents
{
get
{
if (_supplyComponents == null)
{
_supplyComponents = Components
.ToDictionary(recPC => recPC.SupplyId, recPC => recPC.Component as IComponentModel);
}
return _supplyComponents;
}
}
[ForeignKey("SupplyId")] [ForeignKey("SupplyId")]
public virtual List<SupplyOrder> Orders { get; set; } = new(); public virtual List<SupplyOrder> Orders { get; set; } = new();
[ForeignKey("SupplyId")] [ForeignKey("SupplyId")]
public virtual List<ComponentSupply> ComponentSupplies { get; set; } = new(); public virtual List<ComponentSupply> Components { get; set; } = new();
public static Supply Create(ComputerShopDatabase context, SupplyBindingModel model) public static Supply Create(ComputerShopDatabase context, SupplyBindingModel model)
{ {
@ -58,10 +70,16 @@ namespace ComputerShopDatabaseImplement.Models
Status = model.Status, Status = model.Status,
DateCreate = model.DateCreate, DateCreate = model.DateCreate,
DateImplement = model.DateImplement, DateImplement = model.DateImplement,
ReceivingId = model.ReceivingId,
Orders = model.SupplyOrders.Select(x => new Orders = model.SupplyOrders.Select(x => new
SupplyOrder SupplyOrder
{ {
Order = context.Orders.First(y => y.Id == x.Key), Order = context.Orders.First(y => y.Id == x.Key),
}).ToList(),
Components = model.SupplyComponents.Select(x => new
ComponentSupply
{
Component = context.Components.First(y => y.Id == x.Key),
}).ToList() }).ToList()
}; };
} }
@ -81,6 +99,8 @@ namespace ComputerShopDatabaseImplement.Models
DateCreate = DateCreate, DateCreate = DateCreate,
DateImplement = DateImplement, DateImplement = DateImplement,
SupplyOrders = SupplyOrders, SupplyOrders = SupplyOrders,
SupplyComponents = SupplyComponents,
ReceivingId = ReceivingId,
ClientId = ClientId ClientId = ClientId
}; };
public void UpdateOrders(ComputerShopDatabase context, SupplyBindingModel model) public void UpdateOrders(ComputerShopDatabase context, SupplyBindingModel model)