This commit is contained in:
the 2024-06-23 17:04:35 +04:00
commit 3de3f75776
17 changed files with 702 additions and 24 deletions

View File

@ -0,0 +1,12 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace BusinessLogic.BusinessLogic
{
internal class SellLogic
{
}
}

View File

@ -12,8 +12,8 @@ namespace Contracts.BindingModels
{ {
public Guid Id { get; set; } public Guid Id { get; set; }
public DateTime DatePurchase { get; set; } public DateTime DatePurchase { get; set; }
public required IUser User { get; set; } public Guid UserId { get; set; }
public required List<IProduct> Products { get; set; }
public PurchaseStatus Status { get; set; } public PurchaseStatus Status { get; set; }
public Dictionary<Guid, (IProduct, int)> PurchaseProducts { get; set; } = new();
} }
} }

View File

@ -14,16 +14,16 @@ namespace Contracts.Converters
{ {
Id = model.Id, Id = model.Id,
DatePurchase = model.DatePurchase, DatePurchase = model.DatePurchase,
User = model.User, UserId = model.UserId,
Products = model.Products, PurchaseProducts = model.PurchaseProducts,
}; };
public static PurchaseBindingModel ToBinding(PurchaseViewModel model) => new() public static PurchaseBindingModel ToBinding(PurchaseViewModel model) => new()
{ {
Id = model.Id, Id = model.Id,
DatePurchase = model.DatePurchase, DatePurchase = model.DatePurchase,
User = model.User, UserId = model.UserId,
Products = model.Products, PurchaseProducts = model.PurchaseProducts,
}; };
} }
} }

View File

@ -0,0 +1,13 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Contracts.Converters
{
public class SellConverter
{
}
}

View File

@ -12,8 +12,9 @@ namespace Contracts.ViewModels
{ {
public Guid Id { get; set; } public Guid Id { get; set; }
public DateTime DatePurchase { get; set; } public DateTime DatePurchase { get; set; }
public required IUser User { get; set; } public required Guid UserId { get; set; }
public required List<IProduct> Products { get; set; }
public PurchaseStatus Status { get; set; } public PurchaseStatus Status { get; set; }
public Dictionary<Guid, (IProduct, int)> PurchaseProducts { get; set; } = new();
} }
} }

View File

@ -29,5 +29,6 @@ namespace DatabaseImplement
public virtual DbSet<Supplier> Suppliers { get; set; } = null!; public virtual DbSet<Supplier> Suppliers { get; set; } = null!;
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!;
} }
} }

View File

@ -13,7 +13,7 @@ namespace DatabaseImplement.Implements
{ {
public SellBindingModel? Delete(SellSearchModel model) public SellBindingModel? Delete(SellSearchModel model)
{ {
return new(); throw new NotImplementedException();
} }
public SellBindingModel? GetElement(SellSearchModel model) public SellBindingModel? GetElement(SellSearchModel model)

View File

@ -0,0 +1,395 @@
// <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("20240623130351_many-to-many")]
partial class manytomany
{
/// <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.HasKey("Id");
b.ToTable("Sells");
});
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.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.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");
});
modelBuilder.Entity("DatabaseImplement.Models.Purchase", 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,90 @@
using System;
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace DatabaseImplement.Migrations
{
/// <inheritdoc />
public partial class manytomany : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.AddColumn<Guid>(
name: "UserId",
table: "Purchases",
type: "uuid",
nullable: false,
defaultValue: new Guid("00000000-0000-0000-0000-000000000000"));
migrationBuilder.CreateTable(
name: "PurchaseProducts",
columns: table => new
{
Id = table.Column<Guid>(type: "uuid", nullable: false),
PurchaseId = 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_PurchaseProducts", x => x.Id);
table.ForeignKey(
name: "FK_PurchaseProducts_Products_ProductId",
column: x => x.ProductId,
principalTable: "Products",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
table.ForeignKey(
name: "FK_PurchaseProducts_Purchases_PurchaseId",
column: x => x.PurchaseId,
principalTable: "Purchases",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateIndex(
name: "IX_Purchases_UserId",
table: "Purchases",
column: "UserId");
migrationBuilder.CreateIndex(
name: "IX_PurchaseProducts_ProductId",
table: "PurchaseProducts",
column: "ProductId");
migrationBuilder.CreateIndex(
name: "IX_PurchaseProducts_PurchaseId",
table: "PurchaseProducts",
column: "PurchaseId");
migrationBuilder.AddForeignKey(
name: "FK_Purchases_Users_UserId",
table: "Purchases",
column: "UserId",
principalTable: "Users",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropForeignKey(
name: "FK_Purchases_Users_UserId",
table: "Purchases");
migrationBuilder.DropTable(
name: "PurchaseProducts");
migrationBuilder.DropIndex(
name: "IX_Purchases_UserId",
table: "Purchases");
migrationBuilder.DropColumn(
name: "UserId",
table: "Purchases");
}
}
}

View File

@ -83,11 +83,40 @@ namespace DatabaseImplement.Migrations
b.Property<int>("Status") b.Property<int>("Status")
.HasColumnType("integer"); .HasColumnType("integer");
b.Property<Guid>("UserId")
.HasColumnType("uuid");
b.HasKey("Id"); b.HasKey("Id");
b.HasIndex("UserId");
b.ToTable("Purchases"); 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 => modelBuilder.Entity("DatabaseImplement.Models.Role", b =>
{ {
b.Property<Guid>("Id") b.Property<Guid>("Id")
@ -250,6 +279,36 @@ namespace DatabaseImplement.Migrations
b.ToTable("Users"); 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.SupplierProduct", b => modelBuilder.Entity("DatabaseImplement.Models.SupplierProduct", b =>
{ {
b.HasOne("DatabaseImplement.Models.Product", "Product") b.HasOne("DatabaseImplement.Models.Product", "Product")
@ -308,6 +367,16 @@ namespace DatabaseImplement.Migrations
b.Navigation("Role"); b.Navigation("Role");
}); });
modelBuilder.Entity("DatabaseImplement.Models.Product", b =>
{
b.Navigation("PurchaseProducts");
});
modelBuilder.Entity("DatabaseImplement.Models.Purchase", b =>
{
b.Navigation("Products");
});
modelBuilder.Entity("DatabaseImplement.Models.Supplier", b => modelBuilder.Entity("DatabaseImplement.Models.Supplier", b =>
{ {
b.Navigation("Products"); b.Navigation("Products");

View File

@ -4,6 +4,7 @@ using DataModels.Models;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
@ -25,7 +26,8 @@ namespace DatabaseImplement.Models
public bool IsBeingSold { get; set; } public bool IsBeingSold { get; set; }
[Required] [Required]
public int Amount { get; set; } public int Amount { get; set; }
[ForeignKey("ProductId")]
public virtual List<PurchaseProducts> PurchaseProducts { get; set; } = new();
public ProductBindingModel GetBindingModel() => new() public ProductBindingModel GetBindingModel() => new()
{ {
Id = Id, Id = Id,
@ -83,7 +85,6 @@ namespace DatabaseImplement.Models
IsBeingSold = model.IsBeingSold; IsBeingSold = model.IsBeingSold;
Amount = model.Amount; Amount = model.Amount;
} }
public ProductViewModel GetViewModel public ProductViewModel GetViewModel
{ {
get get

View File

@ -2,10 +2,13 @@
using Contracts.ViewModels; using Contracts.ViewModels;
using DataModels.Enums; using DataModels.Enums;
using DataModels.Models; using DataModels.Models;
using Microsoft.EntityFrameworkCore.Metadata.Internal;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations;
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;
@ -16,26 +19,62 @@ namespace DatabaseImplement.Models
public Guid Id { get; set; } public Guid Id { get; set; }
[Required] [Required]
public DateTime DatePurchase { get; set; } public DateTime DatePurchase { get; set; }
[Required]
public Guid UserId { get; set; }
[Required] [Required]
public PurchaseStatus Status { get; private set; } = PurchaseStatus.Unknown; public PurchaseStatus Status { get; private set; } = PurchaseStatus.Unknown;
private Dictionary<Guid, (IProduct, int)>? _purchaseProducts = null;
public virtual User? User { get; set; }
[DataMember]
[NotMapped]
public Dictionary<Guid, (IProduct, int)> PurchaseProducts
{
get
{
if (_purchaseProducts == null)
{
_purchaseProducts = Products.ToDictionary(e => e.ProductId, e => (e.Product as IProduct, e.Count));
}
return _purchaseProducts;
}
set { }
}
[ForeignKey("PurchaseId")]
public virtual List<PurchaseProducts> Products { get; set; } = new();
public PurchaseBindingModel GetBindingModel() => new() public PurchaseBindingModel GetBindingModel() => new()
{ {
Id = Id, Id = Id,
DatePurchase = DatePurchase, DatePurchase = DatePurchase,
User = null, UserId = UserId,
Products = new(), PurchaseProducts = PurchaseProducts,
Status = Status
};
public PurchaseViewModel GetViewModel() => new()
{
Id = Id,
DatePurchase = DatePurchase,
UserId = UserId,
PurchaseProducts = PurchaseProducts,
Status = Status
}; };
public static Purchase ToPurchaseFromView(PurchaseViewModel model, Purchase purchase) => new() public static Purchase ToPurchaseFromView(PurchaseViewModel model, Purchase purchase) => new()
{ {
Id = model.Id, Id = model.Id,
DatePurchase = model.DatePurchase DatePurchase = model.DatePurchase,
UserId = model.UserId,
PurchaseProducts = model.PurchaseProducts,
Status = model.Status
}; };
public static Purchase ToPurchaseFromBinding(PurchaseBindingModel model, Purchase purchase) => new() public static Purchase ToPurchaseFromBinding(PurchaseBindingModel model, Purchase purchase) => new()
{ {
Id = model.Id, Id = model.Id,
DatePurchase = model.DatePurchase, DatePurchase = model.DatePurchase,
UserId = model.UserId,
PurchaseProducts = model.PurchaseProducts,
Status = model.Status
}; };
public void Update(PurchaseBindingModel model, Purchase purchase) public void Update(PurchaseBindingModel model, Purchase purchase)

View File

@ -0,0 +1,24 @@
using Microsoft.EntityFrameworkCore;
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 PurchaseProducts
{
public Guid Id { get; set; }
[Required]
public Guid PurchaseId { get; set; }
[Required]
public Guid ProductId { get; set; }
[Required]
public int Count { get; set; }
public virtual Product Product { get; set; } = new();
public virtual Purchase Purchase { get; set; } = new();
}
}

4
WebApp/Pages/Cart.cshtml Normal file
View File

@ -0,0 +1,4 @@
@page
@model WebApp.Pages.CartModel
@{
}

View File

@ -0,0 +1,13 @@
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.RazorPages;
namespace WebApp.Pages
{
public class CartModel : PageModel
{
public void OnGet()
{
}
}
}

View File

@ -0,0 +1,4 @@
@page
@model WebApp.Pages.CatalogModel
@{
}

View File

@ -0,0 +1,12 @@
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.RazorPages;
namespace WebApp.Pages
{
public class CatalogModel : PageModel
{
public void OnGet()
{
}
}
}