This commit is contained in:
the 2024-06-24 15:09:02 +04:00
commit 93abfa5de5
14 changed files with 766 additions and 56 deletions

View File

@ -8,6 +8,7 @@ using Contracts.ViewModels;
using DatabaseImplement.Implements; using DatabaseImplement.Implements;
using DatabaseImplement.Models; using DatabaseImplement.Models;
using DataModels.Enums; using DataModels.Enums;
using DataModels.Models;
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
@ -37,8 +38,8 @@ namespace BusinessLogic.BusinessLogic
{ {
throw new Exception("Insert operation failed."); throw new Exception("Insert operation failed.");
} }
throw new NotImplementedException();
//return PurchaseConverter.ToView(purchase); return purchase;
} }
public PurchaseViewModel Delete(PurchaseSearchModel model) public PurchaseViewModel Delete(PurchaseSearchModel model)
@ -51,8 +52,9 @@ namespace BusinessLogic.BusinessLogic
{ {
throw new Exception("Delete operation failed."); throw new Exception("Delete operation failed.");
} }
throw new NotImplementedException();
//return PurchaseConverter.ToView(purchase); return purchase;
} }
public PurchaseViewModel ReadElement(PurchaseSearchModel model) public PurchaseViewModel ReadElement(PurchaseSearchModel model)
@ -66,11 +68,12 @@ namespace BusinessLogic.BusinessLogic
throw new ElementNotFoundException(); throw new ElementNotFoundException();
} }
_logger.LogInformation("ReadElement find. Id: {0}", purchase.Id); _logger.LogInformation("ReadElement find. Id: {0}", purchase.Id);
throw new NotImplementedException();
//return PurchaseConverter.ToView(purchase); return purchase;
} }
public IEnumerable<PurchaseViewModel> ReadElements(PurchaseSearchModel? model) public List<PurchaseViewModel> ReadElements(PurchaseSearchModel? model)
{ {
_logger.LogInformation("ReadList. Id: {Id}", model?.Id); _logger.LogInformation("ReadList. Id: {Id}", model?.Id);
var purchase_list = _purchaseStorage.GetFullList(model); var purchase_list = _purchaseStorage.GetFullList(model);
@ -80,8 +83,9 @@ namespace BusinessLogic.BusinessLogic
return []; return [];
} }
_logger.LogInformation("ReadList. Count: {Count}", purchase_list.Count()); _logger.LogInformation("ReadList. Count: {Count}", purchase_list.Count());
throw new NotImplementedException();
//return purchase_list.Select(PurchaseConverter.ToView); return purchase_list;
} }
public PurchaseViewModel Update(PurchaseBindingModel model) public PurchaseViewModel Update(PurchaseBindingModel model)
@ -93,8 +97,7 @@ namespace BusinessLogic.BusinessLogic
{ {
throw new Exception("Update operation failed."); throw new Exception("Update operation failed.");
} }
throw new NotImplementedException(); return purchase;
//return PurchaseConverter.ToView(purchase); }
}
} }
} }

View File

@ -31,8 +31,7 @@ namespace BusinessLogic.BusinessLogic
{ {
throw new Exception("Insert operation failed."); throw new Exception("Insert operation failed.");
} }
//return sell; return sell;
return new();
} }
public SellViewModel GetElement(SellSearchModel model) public SellViewModel GetElement(SellSearchModel model)
{ {
@ -42,19 +41,18 @@ namespace BusinessLogic.BusinessLogic
{ {
throw new Exception("Get element operation failed."); throw new Exception("Get element operation failed.");
} }
return new(); return sell;
//return sell;
} }
public IEnumerable<SellViewModel> GetElements(SellSearchModel? model) public IEnumerable<SellViewModel> GetElements(SellSearchModel? model)
{ {
//var sell_list = _sellStorage.GetList(model); var sell_list = _sellStorage.GetFullList(model);
//if (sell_list is null || sell_list.Count() == 0) if (sell_list is null || sell_list.Count() == 0)
//{ {
// _logger.LogWarning("ReadList return null list"); _logger.LogWarning("ReadList return null list");
// return []; return [];
//} }
return []; return sell_list;
//return sell_list;
} }
public SellViewModel Update(SellSearchModel model) public SellViewModel Update(SellSearchModel model)
{ {
@ -64,8 +62,7 @@ namespace BusinessLogic.BusinessLogic
{ {
throw new Exception("Update operation failed."); throw new Exception("Update operation failed.");
} }
return new(); return sell;
//return sell;
} }
public SellViewModel Delete(SellSearchModel model) public SellViewModel Delete(SellSearchModel model)
{ {
@ -75,8 +72,7 @@ namespace BusinessLogic.BusinessLogic
{ {
throw new Exception("Update operation failed."); throw new Exception("Update operation failed.");
} }
return new(); return sell;
//return sell;
} }
} }
} }

View File

@ -1,4 +1,5 @@
using System; using DataModels.Models;
using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
@ -10,6 +11,7 @@ namespace Contracts.BindingModels
{ {
public Guid Id { get; set; } public Guid Id { get; set; }
public DateTime DateSell { get; set; } public DateTime DateSell { get; set; }
public Guid? SupplyDocId { get; set; } public Guid? UserId { get; set; }
public Dictionary<Guid, (IProduct, int)> SellProducts { get; set; } = new();
} }
} }

View File

@ -17,7 +17,7 @@ namespace Contracts.BusinessLogicContracts
PurchaseViewModel ReadElement(PurchaseSearchModel model); PurchaseViewModel ReadElement(PurchaseSearchModel model);
IEnumerable<PurchaseViewModel> ReadElements(PurchaseSearchModel? model); List<PurchaseViewModel> ReadElements(PurchaseSearchModel? model);
PurchaseViewModel Delete(PurchaseSearchModel model); PurchaseViewModel Delete(PurchaseSearchModel model);
} }

View File

@ -15,14 +15,14 @@ namespace Contracts.Converters
{ {
Id = model.Id, Id = model.Id,
DateSell = model.DateSell, DateSell = model.DateSell,
SupplyDocId = model.SupplyDocId UserId = model.UserId
}; };
public static SellBindingModel ToBinding(SellViewModel model) => new() public static SellBindingModel ToBinding(SellViewModel model) => new()
{ {
Id = model.Id, Id = model.Id,
DateSell = model.DateSell, DateSell = model.DateSell,
SupplyDocId = model.SupplyDocId UserId = model.UserId
}; };
} }
} }

View File

@ -11,6 +11,7 @@ namespace Contracts.ViewModels
{ {
public Guid Id { get; set; } public Guid Id { get; set; }
public DateTime DateSell { get; set; } public DateTime DateSell { get; set; }
public Guid? SupplyDocId { get; set; } public Guid? UserId { get; set; }
} public Dictionary<Guid, (IProduct, int)> SellProducts { get; set; } = new();
}
} }

View File

@ -30,6 +30,7 @@ namespace DatabaseImplement
public virtual DbSet<SupplierProduct> SupplierProducts { get; set; } = null!; public virtual DbSet<SupplierProduct> SupplierProducts { get; set; } = null!;
public virtual DbSet<MediaFile> MediaFiles { get; set; } = null!; public virtual DbSet<MediaFile> MediaFiles { get; set; } = null!;
public virtual DbSet<PurchaseProducts> PurchaseProducts { get; set; } = null!; public virtual DbSet<PurchaseProducts> PurchaseProducts { get; set; } = null!;
public virtual DbSet<SellProducts> SellProducts { get; set; } = null!;
public virtual DbSet<SupplyDoc> SupplyDocs { get; set; } = null!; public virtual DbSet<SupplyDoc> SupplyDocs { get; set; } = null!;
} }
} }

View File

@ -32,7 +32,8 @@ namespace DatabaseImplement.Implements
{ {
using var context = new Database(); using var context = new Database();
return context.Sells return context.Sells
.Include(x => x.SupplyDoc) .Include(x => x.Products)
.ThenInclude(x => x.Product)
.FirstOrDefault(x => (model.Id.HasValue && x.Id == model.Id))?.GetViewModel; .FirstOrDefault(x => (model.Id.HasValue && x.Id == model.Id))?.GetViewModel;
} }
@ -45,7 +46,8 @@ namespace DatabaseImplement.Implements
{ {
using var context = new Database(); using var context = new Database();
return context.Sells return context.Sells
.Include(x => x.SupplyDoc) .Include(x => x.Products)
.ThenInclude(x => x.Product)
.ToList() .ToList()
.Select((Sell sell, int index) => sell.GetViewModel) .Select((Sell sell, int index) => sell.GetViewModel)
.ToList(); .ToList();

View File

@ -0,0 +1,477 @@
// <auto-generated />
using System;
using DatabaseImplement;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Migrations;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
#nullable disable
namespace DatabaseImplement.Migrations
{
[DbContext(typeof(Database))]
[Migration("20240624105540_sellproducts")]
partial class sellproducts
{
/// <inheritdoc />
protected override void BuildTargetModel(ModelBuilder modelBuilder)
{
#pragma warning disable 612, 618
modelBuilder
.HasAnnotation("ProductVersion", "8.0.6")
.HasAnnotation("Relational:MaxIdentifierLength", 63);
NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder);
modelBuilder.Entity("DatabaseImplement.Models.MediaFile", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("uuid");
b.Property<string>("Location")
.IsRequired()
.HasColumnType("text");
b.Property<string>("Name")
.IsRequired()
.HasColumnType("text");
b.Property<Guid>("ProductId")
.HasColumnType("uuid");
b.HasKey("Id");
b.ToTable("MediaFiles");
});
modelBuilder.Entity("DatabaseImplement.Models.Product", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("uuid");
b.Property<int>("Amount")
.HasColumnType("integer");
b.Property<bool>("IsBeingSold")
.HasColumnType("boolean");
b.Property<string>("Name")
.IsRequired()
.HasColumnType("text");
b.Property<double>("Price")
.HasColumnType("double precision");
b.Property<double>("Rate")
.HasColumnType("double precision");
b.HasKey("Id");
b.ToTable("Products");
});
modelBuilder.Entity("DatabaseImplement.Models.Purchase", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("uuid");
b.Property<DateTime>("DatePurchase")
.HasColumnType("timestamp with time zone");
b.Property<int>("Status")
.HasColumnType("integer");
b.Property<Guid>("UserId")
.HasColumnType("uuid");
b.HasKey("Id");
b.HasIndex("UserId");
b.ToTable("Purchases");
});
modelBuilder.Entity("DatabaseImplement.Models.PurchaseProducts", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("uuid");
b.Property<int>("Count")
.HasColumnType("integer");
b.Property<Guid>("ProductId")
.HasColumnType("uuid");
b.Property<Guid>("PurchaseId")
.HasColumnType("uuid");
b.HasKey("Id");
b.HasIndex("ProductId");
b.HasIndex("PurchaseId");
b.ToTable("PurchaseProducts");
});
modelBuilder.Entity("DatabaseImplement.Models.Role", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("uuid");
b.Property<string>("Name")
.IsRequired()
.HasColumnType("text");
b.HasKey("Id");
b.ToTable("Roles");
});
modelBuilder.Entity("DatabaseImplement.Models.Sell", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("uuid");
b.Property<DateTime>("DateSell")
.HasColumnType("timestamp with time zone");
b.Property<Guid?>("UserId")
.HasColumnType("uuid");
b.HasKey("Id");
b.HasIndex("UserId");
b.ToTable("Sells");
});
modelBuilder.Entity("DatabaseImplement.Models.SellProducts", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("uuid");
b.Property<int>("Count")
.HasColumnType("integer");
b.Property<Guid>("ProductId")
.HasColumnType("uuid");
b.Property<Guid>("SellId")
.HasColumnType("uuid");
b.HasKey("Id");
b.HasIndex("ProductId");
b.HasIndex("SellId");
b.ToTable("SellProducts");
});
modelBuilder.Entity("DatabaseImplement.Models.Supplier", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("uuid");
b.Property<int>("Deals")
.HasColumnType("integer");
b.Property<string>("Name")
.IsRequired()
.HasColumnType("text");
b.HasKey("Id");
b.ToTable("Suppliers");
});
modelBuilder.Entity("DatabaseImplement.Models.SupplierProduct", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("uuid");
b.Property<int>("Count")
.HasColumnType("integer");
b.Property<Guid>("ProductId")
.HasColumnType("uuid");
b.Property<Guid>("SupplierId")
.HasColumnType("uuid");
b.HasKey("Id");
b.HasIndex("ProductId");
b.HasIndex("SupplierId");
b.ToTable("SupplierProducts");
});
modelBuilder.Entity("DatabaseImplement.Models.Supply", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("uuid");
b.Property<DateTime>("Date")
.HasColumnType("timestamp with time zone");
b.Property<string>("Name")
.IsRequired()
.HasColumnType("text");
b.Property<double>("Price")
.HasColumnType("double precision");
b.Property<int>("Status")
.HasColumnType("integer");
b.Property<Guid>("SupplierId")
.HasColumnType("uuid");
b.HasKey("Id");
b.HasIndex("SupplierId");
b.ToTable("Supplies");
});
modelBuilder.Entity("DatabaseImplement.Models.SupplyDoc", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("uuid");
b.Property<string>("Name")
.IsRequired()
.HasColumnType("text");
b.Property<Guid>("SupplyId")
.HasColumnType("uuid");
b.HasKey("Id");
b.ToTable("SupplyDocs");
});
modelBuilder.Entity("DatabaseImplement.Models.SupplyProduct", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("uuid");
b.Property<int>("Count")
.HasColumnType("integer");
b.Property<Guid>("ProductId")
.HasColumnType("uuid");
b.Property<Guid>("SupplyId")
.HasColumnType("uuid");
b.HasKey("Id");
b.HasIndex("ProductId");
b.HasIndex("SupplyId");
b.ToTable("SupplyProducts");
});
modelBuilder.Entity("DatabaseImplement.Models.User", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("uuid");
b.Property<DateTime>("Birthday")
.HasColumnType("timestamp with time zone");
b.Property<string>("Email")
.IsRequired()
.HasColumnType("text");
b.Property<string>("FirstName")
.IsRequired()
.HasColumnType("text");
b.Property<bool>("OnlyImportantMails")
.HasColumnType("boolean");
b.Property<string>("PasswordHash")
.IsRequired()
.HasColumnType("text");
b.Property<Guid?>("RoleId")
.HasColumnType("uuid");
b.Property<string>("SecondName")
.IsRequired()
.HasColumnType("text");
b.HasKey("Id");
b.HasIndex("RoleId");
b.ToTable("Users");
});
modelBuilder.Entity("DatabaseImplement.Models.Purchase", b =>
{
b.HasOne("DatabaseImplement.Models.User", "User")
.WithMany()
.HasForeignKey("UserId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("User");
});
modelBuilder.Entity("DatabaseImplement.Models.PurchaseProducts", b =>
{
b.HasOne("DatabaseImplement.Models.Product", "Product")
.WithMany("PurchaseProducts")
.HasForeignKey("ProductId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("DatabaseImplement.Models.Purchase", "Purchase")
.WithMany("Products")
.HasForeignKey("PurchaseId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Product");
b.Navigation("Purchase");
});
modelBuilder.Entity("DatabaseImplement.Models.Sell", b =>
{
b.HasOne("DatabaseImplement.Models.User", "User")
.WithMany()
.HasForeignKey("UserId");
b.Navigation("User");
});
modelBuilder.Entity("DatabaseImplement.Models.SellProducts", b =>
{
b.HasOne("DatabaseImplement.Models.Product", "Product")
.WithMany("SellProducts")
.HasForeignKey("ProductId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("DatabaseImplement.Models.Sell", "Sell")
.WithMany("Products")
.HasForeignKey("SellId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Product");
b.Navigation("Sell");
});
modelBuilder.Entity("DatabaseImplement.Models.SupplierProduct", b =>
{
b.HasOne("DatabaseImplement.Models.Product", "Product")
.WithMany()
.HasForeignKey("ProductId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("DatabaseImplement.Models.Supplier", "Supplier")
.WithMany("Products")
.HasForeignKey("SupplierId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Product");
b.Navigation("Supplier");
});
modelBuilder.Entity("DatabaseImplement.Models.Supply", b =>
{
b.HasOne("DatabaseImplement.Models.Supplier", "Supplier")
.WithMany()
.HasForeignKey("SupplierId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Supplier");
});
modelBuilder.Entity("DatabaseImplement.Models.SupplyProduct", b =>
{
b.HasOne("DatabaseImplement.Models.Product", "Product")
.WithMany()
.HasForeignKey("ProductId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("DatabaseImplement.Models.Supply", "Supply")
.WithMany("Products")
.HasForeignKey("SupplyId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Product");
b.Navigation("Supply");
});
modelBuilder.Entity("DatabaseImplement.Models.User", b =>
{
b.HasOne("DatabaseImplement.Models.Role", "Role")
.WithMany()
.HasForeignKey("RoleId");
b.Navigation("Role");
});
modelBuilder.Entity("DatabaseImplement.Models.Product", b =>
{
b.Navigation("PurchaseProducts");
b.Navigation("SellProducts");
});
modelBuilder.Entity("DatabaseImplement.Models.Purchase", b =>
{
b.Navigation("Products");
});
modelBuilder.Entity("DatabaseImplement.Models.Sell", b =>
{
b.Navigation("Products");
});
modelBuilder.Entity("DatabaseImplement.Models.Supplier", b =>
{
b.Navigation("Products");
});
modelBuilder.Entity("DatabaseImplement.Models.Supply", b =>
{
b.Navigation("Products");
});
#pragma warning restore 612, 618
}
}
}

View File

@ -0,0 +1,104 @@
using System;
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace DatabaseImplement.Migrations
{
/// <inheritdoc />
public partial class sellproducts : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.AddColumn<Guid>(
name: "UserId",
table: "Sells",
type: "uuid",
nullable: true);
migrationBuilder.CreateTable(
name: "SellProducts",
columns: table => new
{
Id = table.Column<Guid>(type: "uuid", nullable: false),
SellId = table.Column<Guid>(type: "uuid", nullable: false),
ProductId = table.Column<Guid>(type: "uuid", nullable: false),
Count = table.Column<int>(type: "integer", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_SellProducts", x => x.Id);
table.ForeignKey(
name: "FK_SellProducts_Products_ProductId",
column: x => x.ProductId,
principalTable: "Products",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
table.ForeignKey(
name: "FK_SellProducts_Sells_SellId",
column: x => x.SellId,
principalTable: "Sells",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateTable(
name: "SupplyDocs",
columns: table => new
{
Id = table.Column<Guid>(type: "uuid", nullable: false),
Name = table.Column<string>(type: "text", nullable: false),
SupplyId = table.Column<Guid>(type: "uuid", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_SupplyDocs", x => x.Id);
});
migrationBuilder.CreateIndex(
name: "IX_Sells_UserId",
table: "Sells",
column: "UserId");
migrationBuilder.CreateIndex(
name: "IX_SellProducts_ProductId",
table: "SellProducts",
column: "ProductId");
migrationBuilder.CreateIndex(
name: "IX_SellProducts_SellId",
table: "SellProducts",
column: "SellId");
migrationBuilder.AddForeignKey(
name: "FK_Sells_Users_UserId",
table: "Sells",
column: "UserId",
principalTable: "Users",
principalColumn: "Id");
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropForeignKey(
name: "FK_Sells_Users_UserId",
table: "Sells");
migrationBuilder.DropTable(
name: "SellProducts");
migrationBuilder.DropTable(
name: "SupplyDocs");
migrationBuilder.DropIndex(
name: "IX_Sells_UserId",
table: "Sells");
migrationBuilder.DropColumn(
name: "UserId",
table: "Sells");
}
}
}

View File

@ -41,7 +41,7 @@ namespace DatabaseImplement.Migrations
b.HasKey("Id"); b.HasKey("Id");
b.ToTable("MediaFiles", (string)null); b.ToTable("MediaFiles");
}); });
modelBuilder.Entity("DatabaseImplement.Models.Product", b => modelBuilder.Entity("DatabaseImplement.Models.Product", b =>
@ -68,7 +68,7 @@ namespace DatabaseImplement.Migrations
b.HasKey("Id"); b.HasKey("Id");
b.ToTable("Products", (string)null); b.ToTable("Products");
}); });
modelBuilder.Entity("DatabaseImplement.Models.Purchase", b => modelBuilder.Entity("DatabaseImplement.Models.Purchase", b =>
@ -90,7 +90,7 @@ namespace DatabaseImplement.Migrations
b.HasIndex("UserId"); b.HasIndex("UserId");
b.ToTable("Purchases", (string)null); b.ToTable("Purchases");
}); });
modelBuilder.Entity("DatabaseImplement.Models.PurchaseProducts", b => modelBuilder.Entity("DatabaseImplement.Models.PurchaseProducts", b =>
@ -114,7 +114,7 @@ namespace DatabaseImplement.Migrations
b.HasIndex("PurchaseId"); b.HasIndex("PurchaseId");
b.ToTable("PurchaseProducts", (string)null); b.ToTable("PurchaseProducts");
}); });
modelBuilder.Entity("DatabaseImplement.Models.Role", b => modelBuilder.Entity("DatabaseImplement.Models.Role", b =>
@ -129,7 +129,7 @@ namespace DatabaseImplement.Migrations
b.HasKey("Id"); b.HasKey("Id");
b.ToTable("Roles", (string)null); b.ToTable("Roles");
}); });
modelBuilder.Entity("DatabaseImplement.Models.Sell", b => modelBuilder.Entity("DatabaseImplement.Models.Sell", b =>
@ -141,9 +141,38 @@ namespace DatabaseImplement.Migrations
b.Property<DateTime>("DateSell") b.Property<DateTime>("DateSell")
.HasColumnType("timestamp with time zone"); .HasColumnType("timestamp with time zone");
b.Property<Guid?>("UserId")
.HasColumnType("uuid");
b.HasKey("Id"); b.HasKey("Id");
b.ToTable("Sells", (string)null); b.HasIndex("UserId");
b.ToTable("Sells");
});
modelBuilder.Entity("DatabaseImplement.Models.SellProducts", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("uuid");
b.Property<int>("Count")
.HasColumnType("integer");
b.Property<Guid>("ProductId")
.HasColumnType("uuid");
b.Property<Guid>("SellId")
.HasColumnType("uuid");
b.HasKey("Id");
b.HasIndex("ProductId");
b.HasIndex("SellId");
b.ToTable("SellProducts");
}); });
modelBuilder.Entity("DatabaseImplement.Models.Supplier", b => modelBuilder.Entity("DatabaseImplement.Models.Supplier", b =>
@ -161,7 +190,7 @@ namespace DatabaseImplement.Migrations
b.HasKey("Id"); b.HasKey("Id");
b.ToTable("Suppliers", (string)null); b.ToTable("Suppliers");
}); });
modelBuilder.Entity("DatabaseImplement.Models.SupplierProduct", b => modelBuilder.Entity("DatabaseImplement.Models.SupplierProduct", b =>
@ -185,7 +214,7 @@ namespace DatabaseImplement.Migrations
b.HasIndex("SupplierId"); b.HasIndex("SupplierId");
b.ToTable("SupplierProducts", (string)null); b.ToTable("SupplierProducts");
}); });
modelBuilder.Entity("DatabaseImplement.Models.Supply", b => modelBuilder.Entity("DatabaseImplement.Models.Supply", b =>
@ -214,7 +243,25 @@ namespace DatabaseImplement.Migrations
b.HasIndex("SupplierId"); b.HasIndex("SupplierId");
b.ToTable("Supplies", (string)null); b.ToTable("Supplies");
});
modelBuilder.Entity("DatabaseImplement.Models.SupplyDoc", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("uuid");
b.Property<string>("Name")
.IsRequired()
.HasColumnType("text");
b.Property<Guid>("SupplyId")
.HasColumnType("uuid");
b.HasKey("Id");
b.ToTable("SupplyDocs");
}); });
modelBuilder.Entity("DatabaseImplement.Models.SupplyProduct", b => modelBuilder.Entity("DatabaseImplement.Models.SupplyProduct", b =>
@ -238,7 +285,7 @@ namespace DatabaseImplement.Migrations
b.HasIndex("SupplyId"); b.HasIndex("SupplyId");
b.ToTable("SupplyProducts", (string)null); b.ToTable("SupplyProducts");
}); });
modelBuilder.Entity("DatabaseImplement.Models.User", b => modelBuilder.Entity("DatabaseImplement.Models.User", b =>
@ -276,7 +323,7 @@ namespace DatabaseImplement.Migrations
b.HasIndex("RoleId"); b.HasIndex("RoleId");
b.ToTable("Users", (string)null); b.ToTable("Users");
}); });
modelBuilder.Entity("DatabaseImplement.Models.Purchase", b => modelBuilder.Entity("DatabaseImplement.Models.Purchase", b =>
@ -309,6 +356,34 @@ namespace DatabaseImplement.Migrations
b.Navigation("Purchase"); b.Navigation("Purchase");
}); });
modelBuilder.Entity("DatabaseImplement.Models.Sell", b =>
{
b.HasOne("DatabaseImplement.Models.User", "User")
.WithMany()
.HasForeignKey("UserId");
b.Navigation("User");
});
modelBuilder.Entity("DatabaseImplement.Models.SellProducts", b =>
{
b.HasOne("DatabaseImplement.Models.Product", "Product")
.WithMany("SellProducts")
.HasForeignKey("ProductId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("DatabaseImplement.Models.Sell", "Sell")
.WithMany("Products")
.HasForeignKey("SellId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Product");
b.Navigation("Sell");
});
modelBuilder.Entity("DatabaseImplement.Models.SupplierProduct", b => modelBuilder.Entity("DatabaseImplement.Models.SupplierProduct", b =>
{ {
b.HasOne("DatabaseImplement.Models.Product", "Product") b.HasOne("DatabaseImplement.Models.Product", "Product")
@ -370,6 +445,8 @@ namespace DatabaseImplement.Migrations
modelBuilder.Entity("DatabaseImplement.Models.Product", b => modelBuilder.Entity("DatabaseImplement.Models.Product", b =>
{ {
b.Navigation("PurchaseProducts"); b.Navigation("PurchaseProducts");
b.Navigation("SellProducts");
}); });
modelBuilder.Entity("DatabaseImplement.Models.Purchase", b => modelBuilder.Entity("DatabaseImplement.Models.Purchase", b =>
@ -377,6 +454,11 @@ namespace DatabaseImplement.Migrations
b.Navigation("Products"); b.Navigation("Products");
}); });
modelBuilder.Entity("DatabaseImplement.Models.Sell", b =>
{
b.Navigation("Products");
});
modelBuilder.Entity("DatabaseImplement.Models.Supplier", b => modelBuilder.Entity("DatabaseImplement.Models.Supplier", b =>
{ {
b.Navigation("Products"); b.Navigation("Products");

View File

@ -28,7 +28,9 @@ namespace DatabaseImplement.Models
public int Amount { get; set; } public int Amount { get; set; }
[ForeignKey("ProductId")] [ForeignKey("ProductId")]
public virtual List<PurchaseProducts> PurchaseProducts { get; set; } = new(); public virtual List<PurchaseProducts> PurchaseProducts { get; set; } = new();
public ProductBindingModel GetBindingModel() => new() [ForeignKey("ProductId")]
public virtual List<SellProducts> SellProducts { get; set; } = new();
public ProductBindingModel GetBindingModel() => new()
{ {
Id = Id, Id = Id,
Name = Name, Name = Name,

View File

@ -4,7 +4,9 @@ using Contracts.ViewModels;
using DataModels.Models; using DataModels.Models;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.ComponentModel.DataAnnotations.Schema;
using System.Linq; using System.Linq;
using System.Runtime.Serialization;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
@ -14,16 +16,32 @@ namespace DatabaseImplement.Models
{ {
public Guid Id { get; set; } public Guid Id { get; set; }
public DateTime DateSell { get; set; } public DateTime DateSell { get; set; }
public Guid? SupplyDocId { get; set; } public Guid? UserId { get; set; }
private Dictionary<Guid, (IProduct, int)>? _sellProducts = null;
public virtual SupplyDoc? SupplyDoc { get; set; } public virtual User? User { get; set; }
[DataMember]
[NotMapped]
public Dictionary<Guid, (IProduct, int)> PurchaseProducts
{
get
{
if (_sellProducts == null)
{
_sellProducts = Products.ToDictionary(e => e.ProductId, e => (e.Product as IProduct, e.Count));
}
return _sellProducts;
}
set { }
}
[ForeignKey("SellId")]
public virtual List<SellProducts> Products { get; set; } = new();
public static Sell Create(Database context, SellBindingModel model) public static Sell Create(Database context, SellBindingModel model)
{ {
return new Sell() return new Sell()
{ {
Id = model.Id, Id = model.Id,
DateSell = model.DateSell, DateSell = model.DateSell,
SupplyDocId = model.SupplyDocId, UserId = model.UserId,
}; };
} }
@ -31,13 +49,13 @@ namespace DatabaseImplement.Models
{ {
Id = Id, Id = Id,
DateSell = DateSell, DateSell = DateSell,
SupplyDocId = SupplyDocId, UserId = UserId,
}; };
public SellViewModel GetViewModel => new() public SellViewModel GetViewModel => new()
{ {
Id = Id, Id = Id,
DateSell = DateSell, DateSell = DateSell,
SupplyDocId = SupplyDocId, UserId = UserId,
}; };
public static Sell ToSellFromView(SellViewModel model, Sell sell) => new() public static Sell ToSellFromView(SellViewModel model, Sell sell) => new()
@ -60,7 +78,7 @@ namespace DatabaseImplement.Models
} }
DateSell = model.DateSell; DateSell = model.DateSell;
SupplyDocId = model.SupplyDocId; UserId = model.UserId;
} }
} }
} }

View File

@ -0,0 +1,22 @@
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace DatabaseImplement.Models
{
public class SellProducts
{
public Guid Id { get; set; }
[Required]
public Guid SellId { get; set; }
[Required]
public Guid ProductId { get; set; }
[Required]
public int Count { get; set; }
public virtual Sell Sell { get; set; } = new();
public virtual Product Product { get; set; } = new();
}
}