еще фиксы

This commit is contained in:
Алексей Тихоненков 2024-05-03 20:55:50 +04:00
parent 172c61b682
commit 33a1c735e5
14 changed files with 411 additions and 68 deletions

View File

@ -0,0 +1,112 @@
using DiningRoomContracts.BindingModels;
using DiningRoomContracts.BusinessLogicContracts;
using DiningRoomContracts.SearchModels;
using DiningRoomContracts.StorageContracts;
using DiningRoomContracts.ViewModels;
using Microsoft.Extensions.Logging;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
namespace DiningRoomBusinessLogic.BusinessLogics
{
public class CardLogic : ICardLogic
{
private readonly ILogger _logger;
private readonly ICardStorage _CardStorage;
public CardLogic(ILogger<CardLogic> logger, ICardStorage CardStorage)
{
_logger = logger;
_CardStorage = CardStorage;
}
public List<CardViewModel>? ReadList(CardSearchModel? model)
{
//model.UserId = -1 для swagger, чтобы можно было считать все заявки всех пользователей
var list = (model == null || model.UserId == -1) ? _CardStorage.GetFullList() : _CardStorage.GetFilteredList(model);
if (list == null)
{
_logger.LogWarning("ReadList Cards return null list");
return null;
}
_logger.LogInformation("ReadList Cards.Count:{Count}", list.Count);
return list;
}
public CardViewModel? ReadElement(CardSearchModel model)
{
if (model == null)
{
throw new ArgumentNullException(nameof(model));
}
var element = _CardStorage.GetElement(model);
if (element == null)
{
_logger.LogWarning("ReadElement Card not found");
return null;
}
_logger.LogInformation("ReadElement card found Id:{Id}", element.Id);
return element;
}
public bool Create(CardBindingModel model)
{
CheckModel(model);
if (_CardStorage.Insert(model) == null)
{
_logger.LogWarning("Insert operation failed");
return false;
}
return true;
}
public bool Update(CardBindingModel model)
{
CheckModel(model);
if (_CardStorage.Update(model) == null)
{
_logger.LogWarning("Update operation failed");
return false;
}
return true;
}
public bool ConnectCardDrink(CardBindingModel model)
{
_logger.LogInformation("Connect Card {rId} with drink {aId}", model.Id, model.DrinkId);
return _CardStorage.ConnectCardDrink(model);
}
public bool Delete(CardBindingModel model)
{
CheckModel(model, false);
_logger.LogInformation("Delete. Id:{Id}", model.Id);
if (_CardStorage.Delete(model) == null)
{
_logger.LogWarning("Delete operation failed");
return false;
}
return true;
}
private void CheckModel(CardBindingModel model, bool withParams = true)
{
if (model == null)
{
throw new ArgumentNullException(nameof(model));
}
if (!withParams)
{
return;
}
if (model.DateCardCreate > DateTime.Now)
{
throw new ArgumentException($"Дата создания карты {model.DateCardCreate} не может быть в будущем");
}
}
}
}

View File

@ -6,11 +6,11 @@ using DiningRoomContracts.ViewModels;
namespace DiningRoomBusinessLogic.BusinessLogics
{
public class ReportGuarantorLogic : IReportGuarantorLogic
public class ReportLogic : IReportLogic
{
private readonly IComponentStorage _componentStorage;
public ReportGuarantorLogic(IComponentStorage ComponentStorage)
public ReportLogic(IComponentStorage ComponentStorage)
{
_componentStorage = ComponentStorage;
}
@ -26,7 +26,7 @@ namespace DiningRoomBusinessLogic.BusinessLogics
/// <summary>
/// Получение отчёта для отправки на почту
/// </summary>
public List<ReportComponentByDateViewModel> GetReportComponentsByRequestDate(UserSearchModel CurrentUser, ReportBindingModel Report)
public List<ReportComponentByDateViewModel> GetReportComponentsByCardDate(UserSearchModel CurrentUser, ReportBindingModel Report)
{
return _componentStorage.GetComponentsByDate(Report, CurrentUser);
}

View File

@ -13,7 +13,8 @@ namespace DiningRoomContracts.BindingModels
public int Id { get; set; }
public int UserId { get; set; }
public int? DrinkId { get; set; }
public string CardName { get; set; } = string.Empty;
}
public DateTime DateCardCreate { get; set; } = DateTime.Now;
}
}

View File

@ -16,6 +16,6 @@ namespace DiningRoomContracts.BusinessLogicContracts
bool Create(CardBindingModel model);
bool Update(CardBindingModel model);
bool Delete(CardBindingModel model);
bool ConnectCardDrink(int cardId, int drinkId);
bool ConnectCardDrink(CardBindingModel model);
}
}

View File

@ -4,7 +4,7 @@ using DiningRoomContracts.ViewModels;
namespace DiningRoomContracts.BusinessLogicContracts
{
public interface IReportGuarantorLogic
public interface IReportLogic
{
/// <summary>
/// Получение отчёта для Word или Excel
@ -14,7 +14,7 @@ namespace DiningRoomContracts.BusinessLogicContracts
/// <summary>
/// Получение отчёта для отправки на почту
/// </summary>
List<ReportComponentByDateViewModel> GetReportComponentsByRequestDate(UserSearchModel CurrentUser, ReportBindingModel Report);
List<ReportComponentByDateViewModel> GetReportComponentsByCardDate(UserSearchModel CurrentUser, ReportBindingModel Report);
void SaveReportToWordFile(ReportBindingModel Model);

View File

@ -5,6 +5,8 @@
public int? Id { get; set; }
public int? UserId { get; set; }
public DateTime? DateCardCreate { get; set; }
public int? DrinkId { get; set; }
public string? Cardname { get; set; }
}

View File

@ -17,5 +17,6 @@ namespace DiningRoomContracts.StorageContracts
CardViewModel? Update(CardBindingModel Model);
CardViewModel? Delete(CardBindingModel Model);
}
bool ConnectCardDrink(CardBindingModel model);
}
}

View File

@ -13,5 +13,7 @@ namespace DiningRoomContracts.ViewModels
[DisplayName("Название карты")]
public string CardName { get; set; } = string.Empty;
public Dictionary<int, (IDrinkModel, int)> DrinkCard { get; set; } = new();
[DisplayName("Дата создания")]
public DateTime DateCardCreate { get; set; } = DateTime.Now;
}
}

View File

@ -8,6 +8,6 @@
public double ComponentCost { get; set; }
public List<(int Count, string ProductName, double ProductPrice, DateTime OrderDate)> Orders { get; set; } = new();
public List<(int Count, string ProductName, double ProductPrice)> Orders { get; set; } = new();
}
}

View File

@ -108,7 +108,7 @@ namespace DiningRoomDatabaseImplement.Implements
ComponentName = x.ComponentName,
ComponentCost = x.Cost,
Orders = x.ProductComponents
.Select(y => (y.Count, y.Product.ProductName, y.Product.Cost, y.Product.Order.DateCreate))
.Select(y => (y.Count, y.Product.ProductName, y.Product.Cost))
.ToList(),
})
.ToList();

View File

@ -12,7 +12,7 @@ using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
namespace DiningRoomDatabaseImplement.Migrations
{
[DbContext(typeof(DiningRoomDatabase))]
[Migration("20240430170642_InitialCreate")]
[Migration("20240503165534_InitialCreate")]
partial class InitialCreate
{
/// <inheritdoc />
@ -37,11 +37,21 @@ namespace DiningRoomDatabaseImplement.Migrations
.IsRequired()
.HasColumnType("text");
b.Property<DateTime>("DateCardCreate")
.HasColumnType("timestamp without time zone");
b.Property<int?>("DrinkId")
.HasColumnType("integer");
b.Property<int>("UserId")
.HasColumnType("integer");
b.HasKey("Id");
b.HasIndex("DrinkId");
b.HasIndex("UserId");
b.ToTable("Cards");
});
@ -69,6 +79,8 @@ namespace DiningRoomDatabaseImplement.Migrations
b.HasKey("Id");
b.HasIndex("UserId");
b.ToTable("Components");
});
@ -99,6 +111,8 @@ namespace DiningRoomDatabaseImplement.Migrations
b.HasKey("Id");
b.HasIndex("UserId");
b.ToTable("Drinks");
});
@ -143,6 +157,10 @@ namespace DiningRoomDatabaseImplement.Migrations
b.Property<int>("ProductId")
.HasColumnType("integer");
b.Property<string>("ProductName")
.IsRequired()
.HasColumnType("text");
b.Property<int>("Status")
.HasColumnType("integer");
@ -172,6 +190,9 @@ namespace DiningRoomDatabaseImplement.Migrations
b.Property<double>("Cost")
.HasColumnType("double precision");
b.Property<int?>("OrderId")
.HasColumnType("integer");
b.Property<string>("ProductName")
.IsRequired()
.HasColumnType("text");
@ -181,6 +202,8 @@ namespace DiningRoomDatabaseImplement.Migrations
b.HasKey("Id");
b.HasIndex("UserId");
b.ToTable("Products");
});
@ -205,6 +228,8 @@ namespace DiningRoomDatabaseImplement.Migrations
b.HasIndex("ComponentId");
b.HasIndex("ProductId");
b.ToTable("ProductComponents");
});
@ -233,6 +258,39 @@ namespace DiningRoomDatabaseImplement.Migrations
b.ToTable("Users");
});
modelBuilder.Entity("DiningRoomDatabaseImplement.Models.Card", b =>
{
b.HasOne("DiningRoomDatabaseImplement.Models.Drink", "Drink")
.WithMany("Cards")
.HasForeignKey("DrinkId");
b.HasOne("DiningRoomDatabaseImplement.Models.User", null)
.WithMany("Cards")
.HasForeignKey("UserId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Drink");
});
modelBuilder.Entity("DiningRoomDatabaseImplement.Models.Component", b =>
{
b.HasOne("DiningRoomDatabaseImplement.Models.User", null)
.WithMany("Components")
.HasForeignKey("UserId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
});
modelBuilder.Entity("DiningRoomDatabaseImplement.Models.Drink", b =>
{
b.HasOne("DiningRoomDatabaseImplement.Models.User", null)
.WithMany("Drinks")
.HasForeignKey("UserId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
});
modelBuilder.Entity("DiningRoomDatabaseImplement.Models.DrinkComponent", b =>
{
b.HasOne("DiningRoomDatabaseImplement.Models.Component", "Component")
@ -255,20 +313,27 @@ namespace DiningRoomDatabaseImplement.Migrations
modelBuilder.Entity("DiningRoomDatabaseImplement.Models.Order", b =>
{
b.HasOne("DiningRoomDatabaseImplement.Models.Product", "Product")
.WithMany()
.WithMany("Order")
.HasForeignKey("ProductId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("DiningRoomDatabaseImplement.Models.User", "User")
.WithMany()
b.HasOne("DiningRoomDatabaseImplement.Models.User", null)
.WithMany("Orders")
.HasForeignKey("UserId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Product");
});
b.Navigation("User");
modelBuilder.Entity("DiningRoomDatabaseImplement.Models.Product", b =>
{
b.HasOne("DiningRoomDatabaseImplement.Models.User", null)
.WithMany("Products")
.HasForeignKey("UserId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
});
modelBuilder.Entity("DiningRoomDatabaseImplement.Models.ProductComponent", b =>
@ -281,7 +346,7 @@ namespace DiningRoomDatabaseImplement.Migrations
b.HasOne("DiningRoomDatabaseImplement.Models.Product", "Product")
.WithMany("Components")
.HasForeignKey("ComponentId")
.HasForeignKey("ProductId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
@ -299,12 +364,29 @@ namespace DiningRoomDatabaseImplement.Migrations
modelBuilder.Entity("DiningRoomDatabaseImplement.Models.Drink", b =>
{
b.Navigation("Cards");
b.Navigation("Components");
});
modelBuilder.Entity("DiningRoomDatabaseImplement.Models.Product", b =>
{
b.Navigation("Components");
b.Navigation("Order");
});
modelBuilder.Entity("DiningRoomDatabaseImplement.Models.User", b =>
{
b.Navigation("Cards");
b.Navigation("Components");
b.Navigation("Drinks");
b.Navigation("Orders");
b.Navigation("Products");
});
#pragma warning restore 612, 618
}

View File

@ -13,17 +13,18 @@ namespace DiningRoomDatabaseImplement.Migrations
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.CreateTable(
name: "Cards",
name: "Users",
columns: table => new
{
Id = table.Column<int>(type: "integer", nullable: false)
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
UserId = table.Column<int>(type: "integer", nullable: false),
CardName = table.Column<string>(type: "text", nullable: false)
Login = table.Column<string>(type: "text", nullable: false),
Password = table.Column<string>(type: "text", nullable: false),
Email = table.Column<string>(type: "text", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Cards", x => x.Id);
table.PrimaryKey("PK_Users", x => x.Id);
});
migrationBuilder.CreateTable(
@ -40,6 +41,12 @@ namespace DiningRoomDatabaseImplement.Migrations
constraints: table =>
{
table.PrimaryKey("PK_Components", x => x.Id);
table.ForeignKey(
name: "FK_Components_Users_UserId",
column: x => x.UserId,
principalTable: "Users",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateTable(
@ -57,6 +64,12 @@ namespace DiningRoomDatabaseImplement.Migrations
constraints: table =>
{
table.PrimaryKey("PK_Drinks", x => x.Id);
table.ForeignKey(
name: "FK_Drinks_Users_UserId",
column: x => x.UserId,
principalTable: "Users",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateTable(
@ -67,26 +80,45 @@ namespace DiningRoomDatabaseImplement.Migrations
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
UserId = table.Column<int>(type: "integer", nullable: false),
ProductName = table.Column<string>(type: "text", nullable: false),
OrderId = table.Column<int>(type: "integer", nullable: true),
Cost = table.Column<double>(type: "double precision", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Products", x => x.Id);
table.ForeignKey(
name: "FK_Products_Users_UserId",
column: x => x.UserId,
principalTable: "Users",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateTable(
name: "Users",
name: "Cards",
columns: table => new
{
Id = table.Column<int>(type: "integer", nullable: false)
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
Login = table.Column<string>(type: "text", nullable: false),
Password = table.Column<string>(type: "text", nullable: false),
Email = table.Column<string>(type: "text", nullable: false)
UserId = table.Column<int>(type: "integer", nullable: false),
CardName = table.Column<string>(type: "text", nullable: false),
DrinkId = table.Column<int>(type: "integer", nullable: true),
DateCardCreate = table.Column<DateTime>(type: "timestamp without time zone", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Users", x => x.Id);
table.PrimaryKey("PK_Cards", x => x.Id);
table.ForeignKey(
name: "FK_Cards_Drinks_DrinkId",
column: x => x.DrinkId,
principalTable: "Drinks",
principalColumn: "Id");
table.ForeignKey(
name: "FK_Cards_Users_UserId",
column: x => x.UserId,
principalTable: "Users",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateTable(
@ -116,6 +148,37 @@ namespace DiningRoomDatabaseImplement.Migrations
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateTable(
name: "Orders",
columns: table => new
{
Id = table.Column<int>(type: "integer", nullable: false)
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
ProductId = table.Column<int>(type: "integer", nullable: false),
ProductName = table.Column<string>(type: "text", nullable: false),
Count = table.Column<int>(type: "integer", nullable: false),
Sum = table.Column<double>(type: "double precision", nullable: false),
Status = table.Column<int>(type: "integer", nullable: false),
DateCreate = table.Column<DateTime>(type: "timestamp without time zone", nullable: false),
UserId = table.Column<int>(type: "integer", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Orders", x => x.Id);
table.ForeignKey(
name: "FK_Orders_Products_ProductId",
column: x => x.ProductId,
principalTable: "Products",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
table.ForeignKey(
name: "FK_Orders_Users_UserId",
column: x => x.UserId,
principalTable: "Users",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateTable(
name: "ProductComponents",
columns: table => new
@ -136,48 +199,38 @@ namespace DiningRoomDatabaseImplement.Migrations
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
table.ForeignKey(
name: "FK_ProductComponents_Products_ComponentId",
column: x => x.ComponentId,
principalTable: "Products",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateTable(
name: "Orders",
columns: table => new
{
Id = table.Column<int>(type: "integer", nullable: false)
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
ProductId = table.Column<int>(type: "integer", nullable: false),
UserId = table.Column<int>(type: "integer", nullable: false),
Sum = table.Column<double>(type: "double precision", nullable: false),
Count = table.Column<int>(type: "integer", nullable: false),
DateCreate = table.Column<DateTime>(type: "timestamp without time zone", nullable: false),
Status = table.Column<int>(type: "integer", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Orders", x => x.Id);
table.ForeignKey(
name: "FK_Orders_Products_ProductId",
name: "FK_ProductComponents_Products_ProductId",
column: x => x.ProductId,
principalTable: "Products",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
table.ForeignKey(
name: "FK_Orders_Users_UserId",
column: x => x.UserId,
principalTable: "Users",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateIndex(
name: "IX_Cards_DrinkId",
table: "Cards",
column: "DrinkId");
migrationBuilder.CreateIndex(
name: "IX_Cards_UserId",
table: "Cards",
column: "UserId");
migrationBuilder.CreateIndex(
name: "IX_Components_UserId",
table: "Components",
column: "UserId");
migrationBuilder.CreateIndex(
name: "IX_DrinkComponents_ComponentId",
table: "DrinkComponents",
column: "ComponentId");
migrationBuilder.CreateIndex(
name: "IX_Drinks_UserId",
table: "Drinks",
column: "UserId");
migrationBuilder.CreateIndex(
name: "IX_Orders_ProductId",
table: "Orders",
@ -192,6 +245,16 @@ namespace DiningRoomDatabaseImplement.Migrations
name: "IX_ProductComponents_ComponentId",
table: "ProductComponents",
column: "ComponentId");
migrationBuilder.CreateIndex(
name: "IX_ProductComponents_ProductId",
table: "ProductComponents",
column: "ProductId");
migrationBuilder.CreateIndex(
name: "IX_Products_UserId",
table: "Products",
column: "UserId");
}
/// <inheritdoc />
@ -212,14 +275,14 @@ namespace DiningRoomDatabaseImplement.Migrations
migrationBuilder.DropTable(
name: "Drinks");
migrationBuilder.DropTable(
name: "Users");
migrationBuilder.DropTable(
name: "Components");
migrationBuilder.DropTable(
name: "Products");
migrationBuilder.DropTable(
name: "Users");
}
}
}

View File

@ -34,11 +34,21 @@ namespace DiningRoomDatabaseImplement.Migrations
.IsRequired()
.HasColumnType("text");
b.Property<DateTime>("DateCardCreate")
.HasColumnType("timestamp without time zone");
b.Property<int?>("DrinkId")
.HasColumnType("integer");
b.Property<int>("UserId")
.HasColumnType("integer");
b.HasKey("Id");
b.HasIndex("DrinkId");
b.HasIndex("UserId");
b.ToTable("Cards");
});
@ -66,6 +76,8 @@ namespace DiningRoomDatabaseImplement.Migrations
b.HasKey("Id");
b.HasIndex("UserId");
b.ToTable("Components");
});
@ -96,6 +108,8 @@ namespace DiningRoomDatabaseImplement.Migrations
b.HasKey("Id");
b.HasIndex("UserId");
b.ToTable("Drinks");
});
@ -140,6 +154,10 @@ namespace DiningRoomDatabaseImplement.Migrations
b.Property<int>("ProductId")
.HasColumnType("integer");
b.Property<string>("ProductName")
.IsRequired()
.HasColumnType("text");
b.Property<int>("Status")
.HasColumnType("integer");
@ -169,6 +187,9 @@ namespace DiningRoomDatabaseImplement.Migrations
b.Property<double>("Cost")
.HasColumnType("double precision");
b.Property<int?>("OrderId")
.HasColumnType("integer");
b.Property<string>("ProductName")
.IsRequired()
.HasColumnType("text");
@ -178,6 +199,8 @@ namespace DiningRoomDatabaseImplement.Migrations
b.HasKey("Id");
b.HasIndex("UserId");
b.ToTable("Products");
});
@ -202,6 +225,8 @@ namespace DiningRoomDatabaseImplement.Migrations
b.HasIndex("ComponentId");
b.HasIndex("ProductId");
b.ToTable("ProductComponents");
});
@ -230,6 +255,39 @@ namespace DiningRoomDatabaseImplement.Migrations
b.ToTable("Users");
});
modelBuilder.Entity("DiningRoomDatabaseImplement.Models.Card", b =>
{
b.HasOne("DiningRoomDatabaseImplement.Models.Drink", "Drink")
.WithMany("Cards")
.HasForeignKey("DrinkId");
b.HasOne("DiningRoomDatabaseImplement.Models.User", null)
.WithMany("Cards")
.HasForeignKey("UserId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Drink");
});
modelBuilder.Entity("DiningRoomDatabaseImplement.Models.Component", b =>
{
b.HasOne("DiningRoomDatabaseImplement.Models.User", null)
.WithMany("Components")
.HasForeignKey("UserId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
});
modelBuilder.Entity("DiningRoomDatabaseImplement.Models.Drink", b =>
{
b.HasOne("DiningRoomDatabaseImplement.Models.User", null)
.WithMany("Drinks")
.HasForeignKey("UserId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
});
modelBuilder.Entity("DiningRoomDatabaseImplement.Models.DrinkComponent", b =>
{
b.HasOne("DiningRoomDatabaseImplement.Models.Component", "Component")
@ -252,20 +310,27 @@ namespace DiningRoomDatabaseImplement.Migrations
modelBuilder.Entity("DiningRoomDatabaseImplement.Models.Order", b =>
{
b.HasOne("DiningRoomDatabaseImplement.Models.Product", "Product")
.WithMany()
.WithMany("Order")
.HasForeignKey("ProductId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("DiningRoomDatabaseImplement.Models.User", "User")
.WithMany()
b.HasOne("DiningRoomDatabaseImplement.Models.User", null)
.WithMany("Orders")
.HasForeignKey("UserId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Product");
});
b.Navigation("User");
modelBuilder.Entity("DiningRoomDatabaseImplement.Models.Product", b =>
{
b.HasOne("DiningRoomDatabaseImplement.Models.User", null)
.WithMany("Products")
.HasForeignKey("UserId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
});
modelBuilder.Entity("DiningRoomDatabaseImplement.Models.ProductComponent", b =>
@ -278,7 +343,7 @@ namespace DiningRoomDatabaseImplement.Migrations
b.HasOne("DiningRoomDatabaseImplement.Models.Product", "Product")
.WithMany("Components")
.HasForeignKey("ComponentId")
.HasForeignKey("ProductId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
@ -296,12 +361,29 @@ namespace DiningRoomDatabaseImplement.Migrations
modelBuilder.Entity("DiningRoomDatabaseImplement.Models.Drink", b =>
{
b.Navigation("Cards");
b.Navigation("Components");
});
modelBuilder.Entity("DiningRoomDatabaseImplement.Models.Product", b =>
{
b.Navigation("Components");
b.Navigation("Order");
});
modelBuilder.Entity("DiningRoomDatabaseImplement.Models.User", b =>
{
b.Navigation("Cards");
b.Navigation("Components");
b.Navigation("Drinks");
b.Navigation("Orders");
b.Navigation("Products");
});
#pragma warning restore 612, 618
}

View File

@ -17,8 +17,6 @@ namespace DiningRoomDatabaseImplement.Models
[Required]
public string ProductName { get; set; } = string.Empty;
public int? OrderId { get; set; }
public virtual Order? Order { get; set; }
[Required]
public double Cost { get; set; }
private Dictionary<int, (IComponentModel, int)>? _productComponents;
@ -42,7 +40,7 @@ namespace DiningRoomDatabaseImplement.Models
[ForeignKey("ProductId")]
public virtual List<ProductComponent> Components { get; set; } = new();
[ForeignKey("ProductId")]
public virtual List<Order> Orders { get; set; } = new();
public virtual List<Order> Order { get; set; } = new();
public static Product Create(DiningRoomDatabase Context, ProductBindingModel Model)
{
return new()