Merge branch 'Worker_Raspaev' into Storekeeper
This commit is contained in:
commit
12cc4e83b0
@ -11,7 +11,7 @@ namespace HardwareShopContracts.BindingModels
|
||||
|
||||
public string BuildName { get; set; } = string.Empty;
|
||||
|
||||
public int UserID { get; set; }
|
||||
public int UserId { get; set; }
|
||||
|
||||
public Dictionary<int, (IComponentModel, int)>? BuildComponents { get; set; }
|
||||
}
|
||||
|
@ -10,6 +10,6 @@ namespace HardwareShopContracts.BindingModels
|
||||
|
||||
public string Text { get; set; } = string.Empty;
|
||||
|
||||
public int BuildID { get; set; }
|
||||
public int BuildId { get; set; }
|
||||
}
|
||||
}
|
||||
|
@ -14,7 +14,7 @@ namespace HardwareShopContracts.BindingModels
|
||||
|
||||
public DateTime? DatePurchase { get; set; }
|
||||
|
||||
public int UserID { get; set; }
|
||||
public int UserId { get; set; }
|
||||
|
||||
public Dictionary<int, (IBuildModel, int)>? PurchaseBuilds { get; set; }
|
||||
|
||||
|
@ -15,7 +15,7 @@ namespace HardwareShopContracts.ViewModels
|
||||
[DisplayName("Клиент")]
|
||||
public string UserEmail { get; set; } = string.Empty;
|
||||
|
||||
public int UserID { get; set; }
|
||||
public int UserId { get; set; }
|
||||
|
||||
public Dictionary<int, (IComponentModel, int)>? BuildComponents { get; set; }
|
||||
}
|
||||
|
@ -13,6 +13,6 @@ namespace HardwareShopContracts.ViewModels
|
||||
[DisplayName("Название сборки")]
|
||||
public string BuildName { get; set; } = string.Empty;
|
||||
|
||||
public int BuildID { get; set; }
|
||||
public int BuildId { get; set; }
|
||||
}
|
||||
}
|
||||
|
@ -16,7 +16,7 @@ namespace HardwareShopContracts.ViewModels
|
||||
[DisplayName("Дата оплаты")]
|
||||
public DateTime? DatePurchase { get; set; }
|
||||
|
||||
public int UserID { get; set; }
|
||||
public int UserId { get; set; }
|
||||
|
||||
[DisplayName("Email клиента")]
|
||||
public string UserEmail { get; set; } = string.Empty;
|
||||
|
@ -13,7 +13,7 @@ namespace HardwareShopDataModels.Models
|
||||
|
||||
string BuildName { get; }
|
||||
|
||||
int UserID { get; }
|
||||
int UserId { get; }
|
||||
|
||||
Dictionary<int, (IComponentModel, int)>? BuildComponents { get; }
|
||||
}
|
||||
|
@ -10,6 +10,6 @@ namespace HardwareShopDataModels.Models
|
||||
{
|
||||
string Text { get; }
|
||||
|
||||
int BuildID { get; }
|
||||
int BuildId { get; }
|
||||
}
|
||||
}
|
||||
|
@ -11,7 +11,7 @@ namespace HardwareShopDataModels.Models
|
||||
//через "?" обозначается что поле может быть null
|
||||
DateTime? DatePurchase { get; }
|
||||
|
||||
int UserID { get; }
|
||||
int UserId { get; }
|
||||
|
||||
Dictionary<int, (IBuildModel, int)>? PurchaseBuilds { get; }
|
||||
|
||||
|
@ -1,4 +1,7 @@
|
||||
using HardwareShopDatabaseImplement.Models;
|
||||
using HardwareShopDatabaseImplement.Models.ManyToMany;
|
||||
using HardwareShopDatabaseImplement.Models.Storekeeper;
|
||||
using HardwareShopDatabaseImplement.Models.Worker;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace HardwareShopDatabaseImplement
|
||||
@ -16,9 +19,9 @@ namespace HardwareShopDatabaseImplement
|
||||
|
||||
protected override void OnModelCreating(ModelBuilder modelBuilder)
|
||||
{
|
||||
modelBuilder.Entity<BuildComponent>().HasKey(x => new { x.ComponentId, x.BuildID });
|
||||
modelBuilder.Entity<PurchaseBuild>().HasKey(x => new { x.PurchaseID, x.BuildID });
|
||||
modelBuilder.Entity<PurchaseGood>().HasKey(x => new { x.PurchaseID, x.GoodID });
|
||||
modelBuilder.Entity<BuildComponent>().HasKey(x => new { x.ComponentId, x.BuildId });
|
||||
modelBuilder.Entity<PurchaseBuild>().HasKey(x => new { x.PurchaseId, x.BuildId });
|
||||
modelBuilder.Entity<PurchaseGood>().HasKey(x => new { x.PurchaseId, x.GoodId });
|
||||
}
|
||||
|
||||
public virtual DbSet<Build> Builds { set; get; }
|
||||
@ -33,7 +36,7 @@ namespace HardwareShopDatabaseImplement
|
||||
|
||||
public virtual DbSet<Order> Orders { set; get; }
|
||||
|
||||
public virtual DbSet<Purchase> Purchase { set; get; }
|
||||
public virtual DbSet<Purchase> Purchases { set; get; }
|
||||
|
||||
public virtual DbSet<PurchaseBuild> PurchasesBuilds { set; get; }
|
||||
|
||||
|
@ -20,4 +20,8 @@
|
||||
<ProjectReference Include="..\HardwareShopDataModels\HardwareShopDataModels.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Folder Include="Implements\" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
@ -12,8 +12,8 @@ using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
|
||||
namespace HardwareShopDatabaseImplement.Migrations
|
||||
{
|
||||
[DbContext(typeof(HardwareShopDatabase))]
|
||||
[Migration("20230401103551_init")]
|
||||
partial class init
|
||||
[Migration("20230401124213_init1")]
|
||||
partial class init1
|
||||
{
|
||||
/// <inheritdoc />
|
||||
protected override void BuildTargetModel(ModelBuilder modelBuilder)
|
||||
@ -25,191 +25,114 @@ namespace HardwareShopDatabaseImplement.Migrations
|
||||
|
||||
SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder);
|
||||
|
||||
modelBuilder.Entity("HardwareShopDatabaseImplement.Models.Build", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("int");
|
||||
|
||||
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<string>("BuildName")
|
||||
.IsRequired()
|
||||
.HasColumnType("nvarchar(max)");
|
||||
|
||||
b.Property<decimal>("Price")
|
||||
.HasColumnType("decimal(18,2)");
|
||||
|
||||
b.Property<int>("UserID")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.ToTable("Builds");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("HardwareShopDatabaseImplement.Models.BuildComponent", b =>
|
||||
modelBuilder.Entity("HardwareShopDatabaseImplement.Models.ManyToMany.BuildComponent", b =>
|
||||
{
|
||||
b.Property<int>("ComponentId")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<int>("BuildID")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<int>("BuildId")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<int>("Count")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.HasKey("ComponentId", "BuildID");
|
||||
b.HasKey("ComponentId", "BuildId");
|
||||
|
||||
b.HasIndex("BuildId");
|
||||
|
||||
b.ToTable("BuildComponent");
|
||||
b.ToTable("BuildsComponents");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("HardwareShopDatabaseImplement.Models.Comment", b =>
|
||||
modelBuilder.Entity("HardwareShopDatabaseImplement.Models.ManyToMany.PurchaseBuild", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("int");
|
||||
|
||||
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<int>("BuildID")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<string>("BuildName")
|
||||
.IsRequired()
|
||||
.HasColumnType("nvarchar(max)");
|
||||
|
||||
b.Property<string>("Text")
|
||||
.IsRequired()
|
||||
.HasColumnType("nvarchar(max)");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("BuildID");
|
||||
|
||||
b.ToTable("Comments");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("HardwareShopDatabaseImplement.Models.Component", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("int");
|
||||
|
||||
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.ToTable("Components");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("HardwareShopDatabaseImplement.Models.Good", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("int");
|
||||
|
||||
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.ToTable("Goods");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("HardwareShopDatabaseImplement.Models.Order", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("int");
|
||||
|
||||
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.ToTable("Orders");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("HardwareShopDatabaseImplement.Models.Purchase", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("int");
|
||||
|
||||
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<DateTime?>("DatePurchase")
|
||||
.HasColumnType("datetime2");
|
||||
|
||||
b.Property<int>("PurchaseStatus")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<decimal>("Sum")
|
||||
.HasColumnType("decimal(18,2)");
|
||||
|
||||
b.Property<int>("UserID")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("UserID");
|
||||
|
||||
b.ToTable("Purchase");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("HardwareShopDatabaseImplement.Models.PurchaseBuild", b =>
|
||||
{
|
||||
b.Property<int>("PurchaseID")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<int>("BuildID")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<int>("BuildId")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<int>("Count")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<int>("PurchaseId")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.HasKey("PurchaseID", "BuildID");
|
||||
b.Property<int>("BuildId")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<int>("Count")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.HasKey("PurchaseId", "BuildId");
|
||||
|
||||
b.HasIndex("BuildId");
|
||||
|
||||
b.HasIndex("PurchaseId");
|
||||
|
||||
b.ToTable("PurchasesBuilds");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("HardwareShopDatabaseImplement.Models.PurchaseGood", b =>
|
||||
modelBuilder.Entity("HardwareShopDatabaseImplement.Models.ManyToMany.PurchaseGood", b =>
|
||||
{
|
||||
b.Property<int>("PurchaseID")
|
||||
b.Property<int>("PurchaseId")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<int>("GoodID")
|
||||
b.Property<int>("GoodId")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<int>("Count")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<int>("PurchaseId")
|
||||
.HasColumnType("int");
|
||||
b.HasKey("PurchaseId", "GoodId");
|
||||
|
||||
b.HasKey("PurchaseID", "GoodID");
|
||||
|
||||
b.HasIndex("GoodID");
|
||||
|
||||
b.HasIndex("PurchaseId");
|
||||
b.HasIndex("GoodId");
|
||||
|
||||
b.ToTable("PurchasesGoods");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("HardwareShopDatabaseImplement.Models.Storekeeper.Component", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("int");
|
||||
|
||||
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<int>("UserId")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("UserId");
|
||||
|
||||
b.ToTable("Components");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("HardwareShopDatabaseImplement.Models.Storekeeper.Good", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("int");
|
||||
|
||||
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<int>("UserId")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("UserId");
|
||||
|
||||
b.ToTable("Goods");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("HardwareShopDatabaseImplement.Models.Storekeeper.Order", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("int");
|
||||
|
||||
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<int>("UserId")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("UserId");
|
||||
|
||||
b.ToTable("Orders");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("HardwareShopDatabaseImplement.Models.User", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
@ -238,15 +161,89 @@ namespace HardwareShopDatabaseImplement.Migrations
|
||||
b.ToTable("Users");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("HardwareShopDatabaseImplement.Models.BuildComponent", b =>
|
||||
modelBuilder.Entity("HardwareShopDatabaseImplement.Models.Worker.Build", b =>
|
||||
{
|
||||
b.HasOne("HardwareShopDatabaseImplement.Models.Build", "Build")
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("int");
|
||||
|
||||
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<string>("BuildName")
|
||||
.IsRequired()
|
||||
.HasColumnType("nvarchar(max)");
|
||||
|
||||
b.Property<decimal>("Price")
|
||||
.HasColumnType("decimal(18,2)");
|
||||
|
||||
b.Property<int>("UserId")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("UserId");
|
||||
|
||||
b.ToTable("Builds");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("HardwareShopDatabaseImplement.Models.Worker.Comment", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("int");
|
||||
|
||||
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<int>("BuildId")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<string>("Text")
|
||||
.IsRequired()
|
||||
.HasColumnType("nvarchar(max)");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("BuildId");
|
||||
|
||||
b.ToTable("Comments");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("HardwareShopDatabaseImplement.Models.Worker.Purchase", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("int");
|
||||
|
||||
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<DateTime?>("DatePurchase")
|
||||
.HasColumnType("datetime2");
|
||||
|
||||
b.Property<int>("PurchaseStatus")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<decimal>("Sum")
|
||||
.HasColumnType("decimal(18,2)");
|
||||
|
||||
b.Property<int>("UserId")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("UserId");
|
||||
|
||||
b.ToTable("Purchases");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("HardwareShopDatabaseImplement.Models.ManyToMany.BuildComponent", b =>
|
||||
{
|
||||
b.HasOne("HardwareShopDatabaseImplement.Models.Worker.Build", "Build")
|
||||
.WithMany("Components")
|
||||
.HasForeignKey("BuildId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.HasOne("HardwareShopDatabaseImplement.Models.Component", "Component")
|
||||
b.HasOne("HardwareShopDatabaseImplement.Models.Storekeeper.Component", "Component")
|
||||
.WithMany()
|
||||
.HasForeignKey("ComponentId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
@ -257,37 +254,15 @@ namespace HardwareShopDatabaseImplement.Migrations
|
||||
b.Navigation("Component");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("HardwareShopDatabaseImplement.Models.Comment", b =>
|
||||
modelBuilder.Entity("HardwareShopDatabaseImplement.Models.ManyToMany.PurchaseBuild", b =>
|
||||
{
|
||||
b.HasOne("HardwareShopDatabaseImplement.Models.Build", "Build")
|
||||
.WithMany()
|
||||
.HasForeignKey("BuildID")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.Navigation("Build");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("HardwareShopDatabaseImplement.Models.Purchase", b =>
|
||||
{
|
||||
b.HasOne("HardwareShopDatabaseImplement.Models.User", "User")
|
||||
.WithMany()
|
||||
.HasForeignKey("UserID")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.Navigation("User");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("HardwareShopDatabaseImplement.Models.PurchaseBuild", b =>
|
||||
{
|
||||
b.HasOne("HardwareShopDatabaseImplement.Models.Build", "Build")
|
||||
b.HasOne("HardwareShopDatabaseImplement.Models.Worker.Build", "Build")
|
||||
.WithMany("Purchases")
|
||||
.HasForeignKey("BuildId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.HasOne("HardwareShopDatabaseImplement.Models.Purchase", "Purchase")
|
||||
b.HasOne("HardwareShopDatabaseImplement.Models.Worker.Purchase", "Purchase")
|
||||
.WithMany("Builds")
|
||||
.HasForeignKey("PurchaseId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
@ -298,15 +273,15 @@ namespace HardwareShopDatabaseImplement.Migrations
|
||||
b.Navigation("Purchase");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("HardwareShopDatabaseImplement.Models.PurchaseGood", b =>
|
||||
modelBuilder.Entity("HardwareShopDatabaseImplement.Models.ManyToMany.PurchaseGood", b =>
|
||||
{
|
||||
b.HasOne("HardwareShopDatabaseImplement.Models.Good", "Good")
|
||||
b.HasOne("HardwareShopDatabaseImplement.Models.Storekeeper.Good", "Good")
|
||||
.WithMany()
|
||||
.HasForeignKey("GoodID")
|
||||
.HasForeignKey("GoodId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.HasOne("HardwareShopDatabaseImplement.Models.Purchase", "Purchase")
|
||||
b.HasOne("HardwareShopDatabaseImplement.Models.Worker.Purchase", "Purchase")
|
||||
.WithMany("Goods")
|
||||
.HasForeignKey("PurchaseId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
@ -317,14 +292,82 @@ namespace HardwareShopDatabaseImplement.Migrations
|
||||
b.Navigation("Purchase");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("HardwareShopDatabaseImplement.Models.Build", b =>
|
||||
modelBuilder.Entity("HardwareShopDatabaseImplement.Models.Storekeeper.Component", b =>
|
||||
{
|
||||
b.HasOne("HardwareShopDatabaseImplement.Models.User", "User")
|
||||
.WithMany()
|
||||
.HasForeignKey("UserId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.Navigation("User");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("HardwareShopDatabaseImplement.Models.Storekeeper.Good", b =>
|
||||
{
|
||||
b.HasOne("HardwareShopDatabaseImplement.Models.User", "User")
|
||||
.WithMany()
|
||||
.HasForeignKey("UserId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.Navigation("User");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("HardwareShopDatabaseImplement.Models.Storekeeper.Order", b =>
|
||||
{
|
||||
b.HasOne("HardwareShopDatabaseImplement.Models.User", "User")
|
||||
.WithMany()
|
||||
.HasForeignKey("UserId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.Navigation("User");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("HardwareShopDatabaseImplement.Models.Worker.Build", b =>
|
||||
{
|
||||
b.HasOne("HardwareShopDatabaseImplement.Models.User", "User")
|
||||
.WithMany()
|
||||
.HasForeignKey("UserId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.Navigation("User");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("HardwareShopDatabaseImplement.Models.Worker.Comment", b =>
|
||||
{
|
||||
b.HasOne("HardwareShopDatabaseImplement.Models.Worker.Build", "Build")
|
||||
.WithMany("Comments")
|
||||
.HasForeignKey("BuildId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.Navigation("Build");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("HardwareShopDatabaseImplement.Models.Worker.Purchase", b =>
|
||||
{
|
||||
b.HasOne("HardwareShopDatabaseImplement.Models.User", "User")
|
||||
.WithMany()
|
||||
.HasForeignKey("UserId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.Navigation("User");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("HardwareShopDatabaseImplement.Models.Worker.Build", b =>
|
||||
{
|
||||
b.Navigation("Comments");
|
||||
|
||||
b.Navigation("Components");
|
||||
|
||||
b.Navigation("Purchases");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("HardwareShopDatabaseImplement.Models.Purchase", b =>
|
||||
modelBuilder.Entity("HardwareShopDatabaseImplement.Models.Worker.Purchase", b =>
|
||||
{
|
||||
b.Navigation("Builds");
|
||||
|
@ -6,62 +6,11 @@ using Microsoft.EntityFrameworkCore.Migrations;
|
||||
namespace HardwareShopDatabaseImplement.Migrations
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public partial class init : Migration
|
||||
public partial class init1 : Migration
|
||||
{
|
||||
/// <inheritdoc />
|
||||
protected override void Up(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.CreateTable(
|
||||
name: "Builds",
|
||||
columns: table => new
|
||||
{
|
||||
Id = table.Column<int>(type: "int", nullable: false)
|
||||
.Annotation("SqlServer:Identity", "1, 1"),
|
||||
Price = table.Column<decimal>(type: "decimal(18,2)", nullable: false),
|
||||
BuildName = table.Column<string>(type: "nvarchar(max)", nullable: false),
|
||||
UserID = table.Column<int>(type: "int", nullable: false)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_Builds", x => x.Id);
|
||||
});
|
||||
|
||||
migrationBuilder.CreateTable(
|
||||
name: "Components",
|
||||
columns: table => new
|
||||
{
|
||||
Id = table.Column<int>(type: "int", nullable: false)
|
||||
.Annotation("SqlServer:Identity", "1, 1")
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_Components", x => x.Id);
|
||||
});
|
||||
|
||||
migrationBuilder.CreateTable(
|
||||
name: "Goods",
|
||||
columns: table => new
|
||||
{
|
||||
Id = table.Column<int>(type: "int", nullable: false)
|
||||
.Annotation("SqlServer:Identity", "1, 1")
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_Goods", x => x.Id);
|
||||
});
|
||||
|
||||
migrationBuilder.CreateTable(
|
||||
name: "Orders",
|
||||
columns: table => new
|
||||
{
|
||||
Id = table.Column<int>(type: "int", nullable: false)
|
||||
.Annotation("SqlServer:Identity", "1, 1")
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_Orders", x => x.Id);
|
||||
});
|
||||
|
||||
migrationBuilder.CreateTable(
|
||||
name: "Users",
|
||||
columns: table => new
|
||||
@ -79,54 +28,85 @@ namespace HardwareShopDatabaseImplement.Migrations
|
||||
});
|
||||
|
||||
migrationBuilder.CreateTable(
|
||||
name: "Comments",
|
||||
name: "Builds",
|
||||
columns: table => new
|
||||
{
|
||||
Id = table.Column<int>(type: "int", nullable: false)
|
||||
.Annotation("SqlServer:Identity", "1, 1"),
|
||||
Text = table.Column<string>(type: "nvarchar(max)", nullable: false),
|
||||
Price = table.Column<decimal>(type: "decimal(18,2)", nullable: false),
|
||||
BuildName = table.Column<string>(type: "nvarchar(max)", nullable: false),
|
||||
BuildID = table.Column<int>(type: "int", nullable: false)
|
||||
UserId = table.Column<int>(type: "int", nullable: false)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_Comments", x => x.Id);
|
||||
table.PrimaryKey("PK_Builds", x => x.Id);
|
||||
table.ForeignKey(
|
||||
name: "FK_Comments_Builds_BuildID",
|
||||
column: x => x.BuildID,
|
||||
principalTable: "Builds",
|
||||
name: "FK_Builds_Users_UserId",
|
||||
column: x => x.UserId,
|
||||
principalTable: "Users",
|
||||
principalColumn: "Id",
|
||||
onDelete: ReferentialAction.Cascade);
|
||||
});
|
||||
|
||||
migrationBuilder.CreateTable(
|
||||
name: "BuildComponent",
|
||||
name: "Components",
|
||||
columns: table => new
|
||||
{
|
||||
BuildID = table.Column<int>(type: "int", nullable: false),
|
||||
ComponentId = table.Column<int>(type: "int", nullable: false),
|
||||
Count = table.Column<int>(type: "int", nullable: false),
|
||||
BuildId = table.Column<int>(type: "int", nullable: false)
|
||||
Id = table.Column<int>(type: "int", nullable: false)
|
||||
.Annotation("SqlServer:Identity", "1, 1"),
|
||||
UserId = table.Column<int>(type: "int", nullable: false)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_BuildComponent", x => new { x.ComponentId, x.BuildID });
|
||||
table.PrimaryKey("PK_Components", x => x.Id);
|
||||
table.ForeignKey(
|
||||
name: "FK_BuildComponent_Builds_BuildId",
|
||||
column: x => x.BuildId,
|
||||
principalTable: "Builds",
|
||||
principalColumn: "Id",
|
||||
onDelete: ReferentialAction.Cascade);
|
||||
table.ForeignKey(
|
||||
name: "FK_BuildComponent_Components_ComponentId",
|
||||
column: x => x.ComponentId,
|
||||
principalTable: "Components",
|
||||
name: "FK_Components_Users_UserId",
|
||||
column: x => x.UserId,
|
||||
principalTable: "Users",
|
||||
principalColumn: "Id",
|
||||
onDelete: ReferentialAction.Cascade);
|
||||
});
|
||||
|
||||
migrationBuilder.CreateTable(
|
||||
name: "Purchase",
|
||||
name: "Goods",
|
||||
columns: table => new
|
||||
{
|
||||
Id = table.Column<int>(type: "int", nullable: false)
|
||||
.Annotation("SqlServer:Identity", "1, 1"),
|
||||
UserId = table.Column<int>(type: "int", nullable: false)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_Goods", x => x.Id);
|
||||
table.ForeignKey(
|
||||
name: "FK_Goods_Users_UserId",
|
||||
column: x => x.UserId,
|
||||
principalTable: "Users",
|
||||
principalColumn: "Id",
|
||||
onDelete: ReferentialAction.Cascade);
|
||||
});
|
||||
|
||||
migrationBuilder.CreateTable(
|
||||
name: "Orders",
|
||||
columns: table => new
|
||||
{
|
||||
Id = table.Column<int>(type: "int", nullable: false)
|
||||
.Annotation("SqlServer:Identity", "1, 1"),
|
||||
UserId = table.Column<int>(type: "int", nullable: false)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_Orders", x => x.Id);
|
||||
table.ForeignKey(
|
||||
name: "FK_Orders_Users_UserId",
|
||||
column: x => x.UserId,
|
||||
principalTable: "Users",
|
||||
principalColumn: "Id",
|
||||
onDelete: ReferentialAction.Cascade);
|
||||
});
|
||||
|
||||
migrationBuilder.CreateTable(
|
||||
name: "Purchases",
|
||||
columns: table => new
|
||||
{
|
||||
Id = table.Column<int>(type: "int", nullable: false)
|
||||
@ -134,32 +114,75 @@ namespace HardwareShopDatabaseImplement.Migrations
|
||||
Sum = table.Column<decimal>(type: "decimal(18,2)", nullable: false),
|
||||
PurchaseStatus = table.Column<int>(type: "int", nullable: false),
|
||||
DatePurchase = table.Column<DateTime>(type: "datetime2", nullable: true),
|
||||
UserID = table.Column<int>(type: "int", nullable: false)
|
||||
UserId = table.Column<int>(type: "int", nullable: false)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_Purchase", x => x.Id);
|
||||
table.PrimaryKey("PK_Purchases", x => x.Id);
|
||||
table.ForeignKey(
|
||||
name: "FK_Purchase_Users_UserID",
|
||||
column: x => x.UserID,
|
||||
name: "FK_Purchases_Users_UserId",
|
||||
column: x => x.UserId,
|
||||
principalTable: "Users",
|
||||
principalColumn: "Id",
|
||||
onDelete: ReferentialAction.Cascade);
|
||||
});
|
||||
|
||||
migrationBuilder.CreateTable(
|
||||
name: "Comments",
|
||||
columns: table => new
|
||||
{
|
||||
Id = table.Column<int>(type: "int", nullable: false)
|
||||
.Annotation("SqlServer:Identity", "1, 1"),
|
||||
Text = table.Column<string>(type: "nvarchar(max)", nullable: false),
|
||||
BuildId = table.Column<int>(type: "int", nullable: false)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_Comments", x => x.Id);
|
||||
table.ForeignKey(
|
||||
name: "FK_Comments_Builds_BuildId",
|
||||
column: x => x.BuildId,
|
||||
principalTable: "Builds",
|
||||
principalColumn: "Id",
|
||||
onDelete: ReferentialAction.Cascade);
|
||||
});
|
||||
|
||||
migrationBuilder.CreateTable(
|
||||
name: "BuildsComponents",
|
||||
columns: table => new
|
||||
{
|
||||
BuildId = table.Column<int>(type: "int", nullable: false),
|
||||
ComponentId = table.Column<int>(type: "int", nullable: false),
|
||||
Count = table.Column<int>(type: "int", nullable: false)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_BuildsComponents", x => new { x.ComponentId, x.BuildId });
|
||||
table.ForeignKey(
|
||||
name: "FK_BuildsComponents_Builds_BuildId",
|
||||
column: x => x.BuildId,
|
||||
principalTable: "Builds",
|
||||
principalColumn: "Id",
|
||||
onDelete: ReferentialAction.Cascade);
|
||||
table.ForeignKey(
|
||||
name: "FK_BuildsComponents_Components_ComponentId",
|
||||
column: x => x.ComponentId,
|
||||
principalTable: "Components",
|
||||
principalColumn: "Id",
|
||||
onDelete: ReferentialAction.Cascade);
|
||||
});
|
||||
|
||||
migrationBuilder.CreateTable(
|
||||
name: "PurchasesBuilds",
|
||||
columns: table => new
|
||||
{
|
||||
BuildID = table.Column<int>(type: "int", nullable: false),
|
||||
PurchaseID = table.Column<int>(type: "int", nullable: false),
|
||||
Count = table.Column<int>(type: "int", nullable: false),
|
||||
BuildId = table.Column<int>(type: "int", nullable: false),
|
||||
PurchaseId = table.Column<int>(type: "int", nullable: false)
|
||||
PurchaseId = table.Column<int>(type: "int", nullable: false),
|
||||
Count = table.Column<int>(type: "int", nullable: false)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_PurchasesBuilds", x => new { x.PurchaseID, x.BuildID });
|
||||
table.PrimaryKey("PK_PurchasesBuilds", x => new { x.PurchaseId, x.BuildId });
|
||||
table.ForeignKey(
|
||||
name: "FK_PurchasesBuilds_Builds_BuildId",
|
||||
column: x => x.BuildId,
|
||||
@ -167,9 +190,9 @@ namespace HardwareShopDatabaseImplement.Migrations
|
||||
principalColumn: "Id",
|
||||
onDelete: ReferentialAction.Cascade);
|
||||
table.ForeignKey(
|
||||
name: "FK_PurchasesBuilds_Purchase_PurchaseId",
|
||||
name: "FK_PurchasesBuilds_Purchases_PurchaseId",
|
||||
column: x => x.PurchaseId,
|
||||
principalTable: "Purchase",
|
||||
principalTable: "Purchases",
|
||||
principalColumn: "Id",
|
||||
onDelete: ReferentialAction.Cascade);
|
||||
});
|
||||
@ -178,42 +201,61 @@ namespace HardwareShopDatabaseImplement.Migrations
|
||||
name: "PurchasesGoods",
|
||||
columns: table => new
|
||||
{
|
||||
PurchaseID = table.Column<int>(type: "int", nullable: false),
|
||||
GoodID = table.Column<int>(type: "int", nullable: false),
|
||||
Count = table.Column<int>(type: "int", nullable: false),
|
||||
PurchaseId = table.Column<int>(type: "int", nullable: false)
|
||||
PurchaseId = table.Column<int>(type: "int", nullable: false),
|
||||
GoodId = table.Column<int>(type: "int", nullable: false),
|
||||
Count = table.Column<int>(type: "int", nullable: false)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_PurchasesGoods", x => new { x.PurchaseID, x.GoodID });
|
||||
table.PrimaryKey("PK_PurchasesGoods", x => new { x.PurchaseId, x.GoodId });
|
||||
table.ForeignKey(
|
||||
name: "FK_PurchasesGoods_Goods_GoodID",
|
||||
column: x => x.GoodID,
|
||||
name: "FK_PurchasesGoods_Goods_GoodId",
|
||||
column: x => x.GoodId,
|
||||
principalTable: "Goods",
|
||||
principalColumn: "Id",
|
||||
onDelete: ReferentialAction.Cascade);
|
||||
table.ForeignKey(
|
||||
name: "FK_PurchasesGoods_Purchase_PurchaseId",
|
||||
name: "FK_PurchasesGoods_Purchases_PurchaseId",
|
||||
column: x => x.PurchaseId,
|
||||
principalTable: "Purchase",
|
||||
principalTable: "Purchases",
|
||||
principalColumn: "Id",
|
||||
onDelete: ReferentialAction.Cascade);
|
||||
});
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_BuildComponent_BuildId",
|
||||
table: "BuildComponent",
|
||||
name: "IX_Builds_UserId",
|
||||
table: "Builds",
|
||||
column: "UserId");
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_BuildsComponents_BuildId",
|
||||
table: "BuildsComponents",
|
||||
column: "BuildId");
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_Comments_BuildID",
|
||||
name: "IX_Comments_BuildId",
|
||||
table: "Comments",
|
||||
column: "BuildID");
|
||||
column: "BuildId");
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_Purchase_UserID",
|
||||
table: "Purchase",
|
||||
column: "UserID");
|
||||
name: "IX_Components_UserId",
|
||||
table: "Components",
|
||||
column: "UserId");
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_Goods_UserId",
|
||||
table: "Goods",
|
||||
column: "UserId");
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_Orders_UserId",
|
||||
table: "Orders",
|
||||
column: "UserId");
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_Purchases_UserId",
|
||||
table: "Purchases",
|
||||
column: "UserId");
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_PurchasesBuilds_BuildId",
|
||||
@ -221,26 +263,16 @@ namespace HardwareShopDatabaseImplement.Migrations
|
||||
column: "BuildId");
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_PurchasesBuilds_PurchaseId",
|
||||
table: "PurchasesBuilds",
|
||||
column: "PurchaseId");
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_PurchasesGoods_GoodID",
|
||||
name: "IX_PurchasesGoods_GoodId",
|
||||
table: "PurchasesGoods",
|
||||
column: "GoodID");
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_PurchasesGoods_PurchaseId",
|
||||
table: "PurchasesGoods",
|
||||
column: "PurchaseId");
|
||||
column: "GoodId");
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override void Down(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.DropTable(
|
||||
name: "BuildComponent");
|
||||
name: "BuildsComponents");
|
||||
|
||||
migrationBuilder.DropTable(
|
||||
name: "Comments");
|
||||
@ -264,7 +296,7 @@ namespace HardwareShopDatabaseImplement.Migrations
|
||||
name: "Goods");
|
||||
|
||||
migrationBuilder.DropTable(
|
||||
name: "Purchase");
|
||||
name: "Purchases");
|
||||
|
||||
migrationBuilder.DropTable(
|
||||
name: "Users");
|
@ -22,191 +22,114 @@ namespace HardwareShopDatabaseImplement.Migrations
|
||||
|
||||
SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder);
|
||||
|
||||
modelBuilder.Entity("HardwareShopDatabaseImplement.Models.Build", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("int");
|
||||
|
||||
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<string>("BuildName")
|
||||
.IsRequired()
|
||||
.HasColumnType("nvarchar(max)");
|
||||
|
||||
b.Property<decimal>("Price")
|
||||
.HasColumnType("decimal(18,2)");
|
||||
|
||||
b.Property<int>("UserID")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.ToTable("Builds");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("HardwareShopDatabaseImplement.Models.BuildComponent", b =>
|
||||
modelBuilder.Entity("HardwareShopDatabaseImplement.Models.ManyToMany.BuildComponent", b =>
|
||||
{
|
||||
b.Property<int>("ComponentId")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<int>("BuildID")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<int>("BuildId")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<int>("Count")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.HasKey("ComponentId", "BuildID");
|
||||
b.HasKey("ComponentId", "BuildId");
|
||||
|
||||
b.HasIndex("BuildId");
|
||||
|
||||
b.ToTable("BuildComponent");
|
||||
b.ToTable("BuildsComponents");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("HardwareShopDatabaseImplement.Models.Comment", b =>
|
||||
modelBuilder.Entity("HardwareShopDatabaseImplement.Models.ManyToMany.PurchaseBuild", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("int");
|
||||
|
||||
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<int>("BuildID")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<string>("BuildName")
|
||||
.IsRequired()
|
||||
.HasColumnType("nvarchar(max)");
|
||||
|
||||
b.Property<string>("Text")
|
||||
.IsRequired()
|
||||
.HasColumnType("nvarchar(max)");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("BuildID");
|
||||
|
||||
b.ToTable("Comments");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("HardwareShopDatabaseImplement.Models.Component", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("int");
|
||||
|
||||
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.ToTable("Components");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("HardwareShopDatabaseImplement.Models.Good", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("int");
|
||||
|
||||
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.ToTable("Goods");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("HardwareShopDatabaseImplement.Models.Order", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("int");
|
||||
|
||||
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.ToTable("Orders");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("HardwareShopDatabaseImplement.Models.Purchase", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("int");
|
||||
|
||||
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<DateTime?>("DatePurchase")
|
||||
.HasColumnType("datetime2");
|
||||
|
||||
b.Property<int>("PurchaseStatus")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<decimal>("Sum")
|
||||
.HasColumnType("decimal(18,2)");
|
||||
|
||||
b.Property<int>("UserID")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("UserID");
|
||||
|
||||
b.ToTable("Purchase");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("HardwareShopDatabaseImplement.Models.PurchaseBuild", b =>
|
||||
{
|
||||
b.Property<int>("PurchaseID")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<int>("BuildID")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<int>("BuildId")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<int>("Count")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<int>("PurchaseId")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.HasKey("PurchaseID", "BuildID");
|
||||
b.Property<int>("BuildId")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<int>("Count")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.HasKey("PurchaseId", "BuildId");
|
||||
|
||||
b.HasIndex("BuildId");
|
||||
|
||||
b.HasIndex("PurchaseId");
|
||||
|
||||
b.ToTable("PurchasesBuilds");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("HardwareShopDatabaseImplement.Models.PurchaseGood", b =>
|
||||
modelBuilder.Entity("HardwareShopDatabaseImplement.Models.ManyToMany.PurchaseGood", b =>
|
||||
{
|
||||
b.Property<int>("PurchaseID")
|
||||
b.Property<int>("PurchaseId")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<int>("GoodID")
|
||||
b.Property<int>("GoodId")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<int>("Count")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<int>("PurchaseId")
|
||||
.HasColumnType("int");
|
||||
b.HasKey("PurchaseId", "GoodId");
|
||||
|
||||
b.HasKey("PurchaseID", "GoodID");
|
||||
|
||||
b.HasIndex("GoodID");
|
||||
|
||||
b.HasIndex("PurchaseId");
|
||||
b.HasIndex("GoodId");
|
||||
|
||||
b.ToTable("PurchasesGoods");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("HardwareShopDatabaseImplement.Models.Storekeeper.Component", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("int");
|
||||
|
||||
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<int>("UserId")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("UserId");
|
||||
|
||||
b.ToTable("Components");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("HardwareShopDatabaseImplement.Models.Storekeeper.Good", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("int");
|
||||
|
||||
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<int>("UserId")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("UserId");
|
||||
|
||||
b.ToTable("Goods");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("HardwareShopDatabaseImplement.Models.Storekeeper.Order", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("int");
|
||||
|
||||
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<int>("UserId")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("UserId");
|
||||
|
||||
b.ToTable("Orders");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("HardwareShopDatabaseImplement.Models.User", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
@ -235,15 +158,89 @@ namespace HardwareShopDatabaseImplement.Migrations
|
||||
b.ToTable("Users");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("HardwareShopDatabaseImplement.Models.BuildComponent", b =>
|
||||
modelBuilder.Entity("HardwareShopDatabaseImplement.Models.Worker.Build", b =>
|
||||
{
|
||||
b.HasOne("HardwareShopDatabaseImplement.Models.Build", "Build")
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("int");
|
||||
|
||||
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<string>("BuildName")
|
||||
.IsRequired()
|
||||
.HasColumnType("nvarchar(max)");
|
||||
|
||||
b.Property<decimal>("Price")
|
||||
.HasColumnType("decimal(18,2)");
|
||||
|
||||
b.Property<int>("UserId")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("UserId");
|
||||
|
||||
b.ToTable("Builds");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("HardwareShopDatabaseImplement.Models.Worker.Comment", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("int");
|
||||
|
||||
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<int>("BuildId")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<string>("Text")
|
||||
.IsRequired()
|
||||
.HasColumnType("nvarchar(max)");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("BuildId");
|
||||
|
||||
b.ToTable("Comments");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("HardwareShopDatabaseImplement.Models.Worker.Purchase", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("int");
|
||||
|
||||
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<DateTime?>("DatePurchase")
|
||||
.HasColumnType("datetime2");
|
||||
|
||||
b.Property<int>("PurchaseStatus")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<decimal>("Sum")
|
||||
.HasColumnType("decimal(18,2)");
|
||||
|
||||
b.Property<int>("UserId")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("UserId");
|
||||
|
||||
b.ToTable("Purchases");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("HardwareShopDatabaseImplement.Models.ManyToMany.BuildComponent", b =>
|
||||
{
|
||||
b.HasOne("HardwareShopDatabaseImplement.Models.Worker.Build", "Build")
|
||||
.WithMany("Components")
|
||||
.HasForeignKey("BuildId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.HasOne("HardwareShopDatabaseImplement.Models.Component", "Component")
|
||||
b.HasOne("HardwareShopDatabaseImplement.Models.Storekeeper.Component", "Component")
|
||||
.WithMany()
|
||||
.HasForeignKey("ComponentId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
@ -254,37 +251,15 @@ namespace HardwareShopDatabaseImplement.Migrations
|
||||
b.Navigation("Component");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("HardwareShopDatabaseImplement.Models.Comment", b =>
|
||||
modelBuilder.Entity("HardwareShopDatabaseImplement.Models.ManyToMany.PurchaseBuild", b =>
|
||||
{
|
||||
b.HasOne("HardwareShopDatabaseImplement.Models.Build", "Build")
|
||||
.WithMany()
|
||||
.HasForeignKey("BuildID")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.Navigation("Build");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("HardwareShopDatabaseImplement.Models.Purchase", b =>
|
||||
{
|
||||
b.HasOne("HardwareShopDatabaseImplement.Models.User", "User")
|
||||
.WithMany()
|
||||
.HasForeignKey("UserID")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.Navigation("User");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("HardwareShopDatabaseImplement.Models.PurchaseBuild", b =>
|
||||
{
|
||||
b.HasOne("HardwareShopDatabaseImplement.Models.Build", "Build")
|
||||
b.HasOne("HardwareShopDatabaseImplement.Models.Worker.Build", "Build")
|
||||
.WithMany("Purchases")
|
||||
.HasForeignKey("BuildId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.HasOne("HardwareShopDatabaseImplement.Models.Purchase", "Purchase")
|
||||
b.HasOne("HardwareShopDatabaseImplement.Models.Worker.Purchase", "Purchase")
|
||||
.WithMany("Builds")
|
||||
.HasForeignKey("PurchaseId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
@ -295,15 +270,15 @@ namespace HardwareShopDatabaseImplement.Migrations
|
||||
b.Navigation("Purchase");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("HardwareShopDatabaseImplement.Models.PurchaseGood", b =>
|
||||
modelBuilder.Entity("HardwareShopDatabaseImplement.Models.ManyToMany.PurchaseGood", b =>
|
||||
{
|
||||
b.HasOne("HardwareShopDatabaseImplement.Models.Good", "Good")
|
||||
b.HasOne("HardwareShopDatabaseImplement.Models.Storekeeper.Good", "Good")
|
||||
.WithMany()
|
||||
.HasForeignKey("GoodID")
|
||||
.HasForeignKey("GoodId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.HasOne("HardwareShopDatabaseImplement.Models.Purchase", "Purchase")
|
||||
b.HasOne("HardwareShopDatabaseImplement.Models.Worker.Purchase", "Purchase")
|
||||
.WithMany("Goods")
|
||||
.HasForeignKey("PurchaseId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
@ -314,14 +289,82 @@ namespace HardwareShopDatabaseImplement.Migrations
|
||||
b.Navigation("Purchase");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("HardwareShopDatabaseImplement.Models.Build", b =>
|
||||
modelBuilder.Entity("HardwareShopDatabaseImplement.Models.Storekeeper.Component", b =>
|
||||
{
|
||||
b.HasOne("HardwareShopDatabaseImplement.Models.User", "User")
|
||||
.WithMany()
|
||||
.HasForeignKey("UserId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.Navigation("User");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("HardwareShopDatabaseImplement.Models.Storekeeper.Good", b =>
|
||||
{
|
||||
b.HasOne("HardwareShopDatabaseImplement.Models.User", "User")
|
||||
.WithMany()
|
||||
.HasForeignKey("UserId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.Navigation("User");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("HardwareShopDatabaseImplement.Models.Storekeeper.Order", b =>
|
||||
{
|
||||
b.HasOne("HardwareShopDatabaseImplement.Models.User", "User")
|
||||
.WithMany()
|
||||
.HasForeignKey("UserId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.Navigation("User");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("HardwareShopDatabaseImplement.Models.Worker.Build", b =>
|
||||
{
|
||||
b.HasOne("HardwareShopDatabaseImplement.Models.User", "User")
|
||||
.WithMany()
|
||||
.HasForeignKey("UserId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.Navigation("User");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("HardwareShopDatabaseImplement.Models.Worker.Comment", b =>
|
||||
{
|
||||
b.HasOne("HardwareShopDatabaseImplement.Models.Worker.Build", "Build")
|
||||
.WithMany("Comments")
|
||||
.HasForeignKey("BuildId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.Navigation("Build");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("HardwareShopDatabaseImplement.Models.Worker.Purchase", b =>
|
||||
{
|
||||
b.HasOne("HardwareShopDatabaseImplement.Models.User", "User")
|
||||
.WithMany()
|
||||
.HasForeignKey("UserId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.Navigation("User");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("HardwareShopDatabaseImplement.Models.Worker.Build", b =>
|
||||
{
|
||||
b.Navigation("Comments");
|
||||
|
||||
b.Navigation("Components");
|
||||
|
||||
b.Navigation("Purchases");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("HardwareShopDatabaseImplement.Models.Purchase", b =>
|
||||
modelBuilder.Entity("HardwareShopDatabaseImplement.Models.Worker.Purchase", b =>
|
||||
{
|
||||
b.Navigation("Builds");
|
||||
|
||||
|
@ -1,4 +1,6 @@
|
||||
using System;
|
||||
using HardwareShopDatabaseImplement.Models.Storekeeper;
|
||||
using HardwareShopDatabaseImplement.Models.Worker;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
@ -6,12 +8,12 @@ using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace HardwareShopDatabaseImplement.Models
|
||||
namespace HardwareShopDatabaseImplement.Models.ManyToMany
|
||||
{
|
||||
public class BuildComponent
|
||||
{
|
||||
|
||||
public int BuildID { get; set; }
|
||||
public int BuildId { get; set; }
|
||||
|
||||
public int ComponentId { get; set; }
|
||||
|
@ -1,4 +1,5 @@
|
||||
using System;
|
||||
using HardwareShopDatabaseImplement.Models.Worker;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
@ -6,14 +7,14 @@ using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace HardwareShopDatabaseImplement.Models
|
||||
namespace HardwareShopDatabaseImplement.Models.ManyToMany
|
||||
{
|
||||
public class PurchaseBuild
|
||||
{
|
||||
|
||||
public int BuildID { get; set; }
|
||||
public int BuildId { get; set; }
|
||||
|
||||
public int PurchaseID { get; set; }
|
||||
public int PurchaseId { get; set; }
|
||||
|
||||
[Required]
|
||||
public int Count { get; set; }
|
@ -1,4 +1,6 @@
|
||||
using System;
|
||||
using HardwareShopDatabaseImplement.Models.Storekeeper;
|
||||
using HardwareShopDatabaseImplement.Models.Worker;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
@ -6,14 +8,14 @@ using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace HardwareShopDatabaseImplement.Models
|
||||
namespace HardwareShopDatabaseImplement.Models.ManyToMany
|
||||
{
|
||||
public class PurchaseGood
|
||||
{
|
||||
|
||||
public int PurchaseID { get; set; }
|
||||
public int PurchaseId { get; set; }
|
||||
|
||||
public int GoodID { get; set; }
|
||||
public int GoodId { get; set; }
|
||||
|
||||
[Required]
|
||||
public int Count { get; set; }
|
@ -1,37 +0,0 @@
|
||||
using HardwareShopDataModels.Enums;
|
||||
using HardwareShopDataModels.Models;
|
||||
using HardwareShopDataModels.Models;
|
||||
using System.ComponentModel;
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
|
||||
namespace HardwareShopDatabaseImplement.Models
|
||||
{
|
||||
public class Purchase : IPurchaseModel
|
||||
{
|
||||
public int Id { get; set; }
|
||||
|
||||
public decimal Sum { get; set; }
|
||||
|
||||
public PurchaseStatus PurchaseStatus { get; set; } = PurchaseStatus.Неизвестен;
|
||||
|
||||
public DateTime? DatePurchase { get; set; }
|
||||
|
||||
public int UserID { get; set; }
|
||||
|
||||
public virtual User User { get; set; }
|
||||
|
||||
[NotMapped]
|
||||
public Dictionary<int, (IBuildModel, int)>? PurchaseBuilds { get; set; }
|
||||
|
||||
[NotMapped]
|
||||
public Dictionary<int, (IGoodModel, int)> PurchaseGoods { get; set; } = new();
|
||||
|
||||
|
||||
[ForeignKey("PurchaseId")]
|
||||
public virtual List<PurchaseBuild>? Builds { get; set; }
|
||||
|
||||
[ForeignKey("PurchaseId")]
|
||||
public virtual List<PurchaseGood> Goods { get; set; } = new();
|
||||
|
||||
}
|
||||
}
|
@ -5,7 +5,7 @@ using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace HardwareShopDatabaseImplement.Models
|
||||
namespace HardwareShopDatabaseImplement.Models.Storekeeper
|
||||
{
|
||||
public class Component : IComponentModel
|
||||
{
|
@ -6,7 +6,7 @@ using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace HardwareShopDatabaseImplement.Models
|
||||
namespace HardwareShopDatabaseImplement.Models.Storekeeper
|
||||
{
|
||||
public class Good : IGoodModel
|
||||
{
|
@ -2,7 +2,7 @@
|
||||
using HardwareShopDataModels.Models;
|
||||
using HardwareShopDataModels.Models;
|
||||
using System.ComponentModel;
|
||||
namespace HardwareShopDatabaseImplement.Models
|
||||
namespace HardwareShopDatabaseImplement.Models.Storekeeper
|
||||
{
|
||||
public class Order : IOrderModel
|
||||
{
|
@ -1,11 +1,11 @@
|
||||
using HardwareShopContracts.BindingModels;
|
||||
using HardwareShopContracts.ViewModels;
|
||||
using HardwareShopDatabaseImplement.Models.ManyToMany;
|
||||
using HardwareShopDataModels.Models;
|
||||
using System.ComponentModel;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
|
||||
namespace HardwareShopDatabaseImplement.Models
|
||||
namespace HardwareShopDatabaseImplement.Models.Worker
|
||||
{
|
||||
public class Build : IBuildModel
|
||||
{
|
||||
@ -18,7 +18,7 @@ namespace HardwareShopDatabaseImplement.Models
|
||||
public string BuildName { get; set; } = string.Empty;
|
||||
|
||||
[Required]
|
||||
public int UserID { get; set; }
|
||||
public int UserId { get; set; }
|
||||
|
||||
public virtual User User { get; set; }
|
||||
|
||||
@ -55,7 +55,7 @@ namespace HardwareShopDatabaseImplement.Models
|
||||
Id = model.Id,
|
||||
Price = model.Price,
|
||||
BuildName = model.BuildName,
|
||||
UserID = model.UserID,
|
||||
UserId = model.UserId,
|
||||
Components = model.BuildComponents.Select(x => new BuildComponent
|
||||
{
|
||||
Component = context.Components.First(y => y.Id == x.Key),
|
||||
@ -76,13 +76,13 @@ namespace HardwareShopDatabaseImplement.Models
|
||||
BuildName = BuildName,
|
||||
Price = Price,
|
||||
UserEmail = User.Email,
|
||||
UserID = UserID,
|
||||
UserId = UserId,
|
||||
BuildComponents = BuildComponents
|
||||
};
|
||||
|
||||
public void UpdateComponents(HardwareShopDatabase context, BuildBindingModel model)
|
||||
{
|
||||
var buildComponents = context.BuildsComponents.Where(rec => rec.BuildID == model.Id).ToList();
|
||||
var buildComponents = context.BuildsComponents.Where(rec => rec.BuildId == model.Id).ToList();
|
||||
if (buildComponents != null && buildComponents.Count > 0)
|
||||
{ // удалили те в бд, которых нет в модели
|
||||
context.BuildsComponents.RemoveRange(buildComponents.Where(rec => !model.BuildComponents.ContainsKey(rec.ComponentId)));
|
@ -4,7 +4,7 @@ using HardwareShopDataModels.Models;
|
||||
using System.ComponentModel;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
|
||||
namespace HardwareShopDatabaseImplement.Models
|
||||
namespace HardwareShopDatabaseImplement.Models.Worker
|
||||
{
|
||||
public class Comment : ICommentModel
|
||||
{
|
||||
@ -14,7 +14,7 @@ namespace HardwareShopDatabaseImplement.Models
|
||||
public string Text { get; set; } = string.Empty;
|
||||
|
||||
[Required]
|
||||
public int BuildID { get; set; }
|
||||
public int BuildId { get; set; }
|
||||
|
||||
public virtual Build Build { get; set; }
|
||||
|
||||
@ -28,7 +28,7 @@ namespace HardwareShopDatabaseImplement.Models
|
||||
{
|
||||
Id = model.Id,
|
||||
Text = model.Text,
|
||||
BuildID = model.BuildID
|
||||
BuildId = model.BuildId
|
||||
};
|
||||
}
|
||||
public void Update(CommentBindingModel? model)
|
||||
@ -43,7 +43,7 @@ namespace HardwareShopDatabaseImplement.Models
|
||||
{
|
||||
Id = Id,
|
||||
Text = Text,
|
||||
BuildID = BuildID,
|
||||
BuildId = BuildId,
|
||||
BuildName = Build.BuildName
|
||||
};
|
||||
}
|
@ -0,0 +1,158 @@
|
||||
using HardwareShopContracts.BindingModels;
|
||||
using HardwareShopContracts.ViewModels;
|
||||
using HardwareShopDatabaseImplement.Models.ManyToMany;
|
||||
using HardwareShopDataModels.Enums;
|
||||
using HardwareShopDataModels.Models;
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
using System.Diagnostics;
|
||||
|
||||
namespace HardwareShopDatabaseImplement.Models.Worker
|
||||
{
|
||||
public class Purchase : IPurchaseModel
|
||||
{
|
||||
public int Id { get; set; }
|
||||
|
||||
public decimal Sum { get; set; }
|
||||
|
||||
public PurchaseStatus PurchaseStatus { get; set; } = PurchaseStatus.Неизвестен;
|
||||
|
||||
public DateTime? DatePurchase { get; set; }
|
||||
|
||||
public int UserId { get; set; }
|
||||
|
||||
public virtual User User { get; set; }
|
||||
|
||||
[ForeignKey("PurchaseId")]
|
||||
public virtual List<PurchaseBuild>? Builds { get; set; }
|
||||
|
||||
public Dictionary<int, (IBuildModel, int)>? _purchaseBuilds = null;
|
||||
|
||||
[NotMapped]
|
||||
public Dictionary<int, (IBuildModel, int)>? PurchaseBuilds
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_purchaseBuilds == null)
|
||||
{
|
||||
_purchaseBuilds = Builds.ToDictionary(recPB => recPB.BuildId, recPB => (recPB.Build as IBuildModel, recPB.Count));
|
||||
}
|
||||
return _purchaseBuilds;
|
||||
}
|
||||
}
|
||||
|
||||
[ForeignKey("PurchaseId")]
|
||||
public virtual List<PurchaseGood> Goods { get; set; } = new();
|
||||
|
||||
public Dictionary<int, (IGoodModel, int)>? _purchaseGoods = null;
|
||||
[NotMapped]
|
||||
public Dictionary<int, (IGoodModel, int)>? PurchaseGoods
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_purchaseGoods == null)
|
||||
{
|
||||
_purchaseGoods = Goods.ToDictionary(recPG => recPG.GoodId, recPG => (recPG.Good as IGoodModel, recPG.Count));
|
||||
}
|
||||
return _purchaseGoods;
|
||||
}
|
||||
}
|
||||
|
||||
public static Purchase Create(HardwareShopDatabase context, PurchaseBindingModel model)
|
||||
{
|
||||
return new Purchase()
|
||||
{
|
||||
Id = model.Id,
|
||||
Sum = model.Sum,
|
||||
PurchaseStatus = model.PurchaseStatus,
|
||||
DatePurchase = model.DatePurchase,
|
||||
UserId = model.UserId,
|
||||
Builds = model.PurchaseBuilds.Select(x => new PurchaseBuild
|
||||
{
|
||||
Build = context.Builds.First(y => y.Id == x.Key),
|
||||
Count = x.Value.Item2
|
||||
}).ToList(),
|
||||
Goods = model.PurchaseGoods.Select(x => new PurchaseGood
|
||||
{
|
||||
Good = context.Goods.First(y => y.Id == x.Key),
|
||||
Count = x.Value.Item2
|
||||
}).ToList()
|
||||
};
|
||||
}
|
||||
|
||||
public void Update(PurchaseBindingModel model)
|
||||
{
|
||||
PurchaseStatus = model.PurchaseStatus;
|
||||
DatePurchase = model.DatePurchase;
|
||||
}
|
||||
|
||||
public PurchaseViewModel GetViewModel => new()
|
||||
{
|
||||
Id = Id,
|
||||
Sum = Sum,
|
||||
PurchaseStatus = PurchaseStatus,
|
||||
DatePurchase = DatePurchase,
|
||||
UserId = UserId,
|
||||
UserEmail = User.Email,
|
||||
PurchaseBuilds = PurchaseBuilds,
|
||||
PurchaseGoods = PurchaseGoods
|
||||
};
|
||||
|
||||
public void UpdateBuilds(HardwareShopDatabase context, PurchaseBindingModel model)
|
||||
{
|
||||
var purchaseBuilds = context.PurchasesBuilds.Where(rec => rec.PurchaseId == model.Id).ToList();
|
||||
if (purchaseBuilds != null && purchaseBuilds.Count > 0)
|
||||
{
|
||||
context.PurchasesBuilds.RemoveRange(purchaseBuilds.Where(rec => !model.PurchaseBuilds.ContainsKey(rec.BuildId)));
|
||||
context.SaveChanges();
|
||||
foreach (var updateBuild in purchaseBuilds)
|
||||
{
|
||||
updateBuild.Count = model.PurchaseBuilds[updateBuild.BuildId].Item2;
|
||||
model.PurchaseBuilds.Remove(updateBuild.BuildId);
|
||||
}
|
||||
context.SaveChanges();
|
||||
}
|
||||
var purchase = context.Purchases.First(x => x.Id == Id);
|
||||
foreach (var dc in model.PurchaseBuilds)
|
||||
{
|
||||
context.PurchasesBuilds.Add(new PurchaseBuild
|
||||
{
|
||||
Purchase = purchase,
|
||||
Build = context.Builds.First(x => x.Id == dc.Key),
|
||||
Count = dc.Value.Item2
|
||||
});
|
||||
context.SaveChanges();
|
||||
}
|
||||
_purchaseBuilds = null;
|
||||
}
|
||||
|
||||
public void UpdateGoods(HardwareShopDatabase context, PurchaseBindingModel model)
|
||||
{
|
||||
var purchaseGoods = context.PurchasesGoods.Where(rec => rec.PurchaseId == model.Id).ToList();
|
||||
if (purchaseGoods != null && purchaseGoods.Count > 0)
|
||||
{ // удалили те в бд, которых нет в модели
|
||||
context.PurchasesGoods.RemoveRange(purchaseGoods.Where(rec => !model.PurchaseGoods.ContainsKey(rec.GoodId)));
|
||||
context.SaveChanges();
|
||||
// обновили количество у существующих записей
|
||||
foreach (var updateGood in purchaseGoods)
|
||||
{
|
||||
updateGood.Count = model.PurchaseGoods[updateGood.GoodId].Item2;
|
||||
model.PurchaseGoods.Remove(updateGood.GoodId);
|
||||
}
|
||||
context.SaveChanges();
|
||||
}
|
||||
var purchase = context.Purchases.First(x => x.Id == Id);
|
||||
//добавляем в бд блюда которые есть в моделе, но ещё нет в бд
|
||||
foreach (var dc in model.PurchaseGoods)
|
||||
{
|
||||
context.PurchasesGoods.Add(new PurchaseGood
|
||||
{
|
||||
Purchase = purchase,
|
||||
Good = context.Goods.First(x => x.Id == dc.Key),
|
||||
Count = dc.Value.Item2
|
||||
});
|
||||
context.SaveChanges();
|
||||
}
|
||||
_purchaseGoods = null;
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user