Database change

This commit is contained in:
shadowik 2023-03-27 01:22:49 +04:00
parent 84193355ae
commit 9dd826d28c
17 changed files with 590 additions and 23 deletions

View File

@ -17,9 +17,7 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "PizzeriaFileImplement", "Pi
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "PizzeriaDatabaseImplement", "PizzeriaDatabaseImplement\PizzeriaDatabaseImplement.csproj", "{ACCCBB67-15A1-4568-86C2-BFF5428FA073}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PizzeriaShopRestApi", "PizzeriaShopRestApi\PizzeriaShopRestApi.csproj", "{6B68ABCB-DDDE-452C-AE2E-9299654EE136}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PizzeriaClientApp", "PizzeriaClientApp\PizzeriaClientApp.csproj", "{808F55EE-BD20-440C-B24E-89839F6F8EF0}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "PizzeriaShopRestApi", "PizzeriaShopRestApi\PizzeriaShopRestApi.csproj", "{6B68ABCB-DDDE-452C-AE2E-9299654EE136}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
@ -59,10 +57,6 @@ Global
{6B68ABCB-DDDE-452C-AE2E-9299654EE136}.Debug|Any CPU.Build.0 = Debug|Any CPU
{6B68ABCB-DDDE-452C-AE2E-9299654EE136}.Release|Any CPU.ActiveCfg = Release|Any CPU
{6B68ABCB-DDDE-452C-AE2E-9299654EE136}.Release|Any CPU.Build.0 = Release|Any CPU
{808F55EE-BD20-440C-B24E-89839F6F8EF0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{808F55EE-BD20-440C-B24E-89839F6F8EF0}.Debug|Any CPU.Build.0 = Debug|Any CPU
{808F55EE-BD20-440C-B24E-89839F6F8EF0}.Release|Any CPU.ActiveCfg = Release|Any CPU
{808F55EE-BD20-440C-B24E-89839F6F8EF0}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE

View File

@ -42,6 +42,7 @@
this.buttonOrderReady = new System.Windows.Forms.Button();
this.buttonIssuedOrder = new System.Windows.Forms.Button();
this.buttonRef = new System.Windows.Forms.Button();
this.клиентToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.menuStrip1.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit();
this.SuspendLayout();
@ -63,7 +64,8 @@
//
this.bookToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
this.ingridientsToolStripMenuItem,
this.pizzasToolStripMenuItem});
this.pizzasToolStripMenuItem,
this.клиентToolStripMenuItem});
this.bookToolStripMenuItem.Name = "bookToolStripMenuItem";
this.bookToolStripMenuItem.Size = new System.Drawing.Size(87, 20);
this.bookToolStripMenuItem.Text = "Справочник";
@ -71,14 +73,14 @@
// ingridientsToolStripMenuItem
//
this.ingridientsToolStripMenuItem.Name = "ingridientsToolStripMenuItem";
this.ingridientsToolStripMenuItem.Size = new System.Drawing.Size(148, 22);
this.ingridientsToolStripMenuItem.Size = new System.Drawing.Size(180, 22);
this.ingridientsToolStripMenuItem.Text = "Ингредиенты";
this.ingridientsToolStripMenuItem.Click += new System.EventHandler(this.IngridentsToolStripMenuItem_Click);
//
// pizzasToolStripMenuItem
//
this.pizzasToolStripMenuItem.Name = "pizzasToolStripMenuItem";
this.pizzasToolStripMenuItem.Size = new System.Drawing.Size(148, 22);
this.pizzasToolStripMenuItem.Size = new System.Drawing.Size(180, 22);
this.pizzasToolStripMenuItem.Text = "Пиццы";
this.pizzasToolStripMenuItem.Click += new System.EventHandler(this.PizzasToolStripMenuItem_Click);
//
@ -182,6 +184,13 @@
this.buttonRef.UseVisualStyleBackColor = true;
this.buttonRef.Click += new System.EventHandler(this.ButtonRef_Click);
//
// клиентToolStripMenuItem
//
this.клиентToolStripMenuItem.Name = "клиентToolStripMenuItem";
this.клиентToolStripMenuItem.Size = new System.Drawing.Size(180, 22);
this.клиентToolStripMenuItem.Text = "Клиент";
this.клиентToolStripMenuItem.Click += new System.EventHandler(this.ClientToolStripMenuItem_Click);
//
// FormMain
//
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
@ -223,5 +232,6 @@
private ToolStripMenuItem componentsToolStripMenuItem1;
private ToolStripMenuItem componentPizzaToolStripMenuItem1;
private ToolStripMenuItem ordersToolStripMenuItem;
private ToolStripMenuItem клиентToolStripMenuItem;
}
}

View File

@ -31,6 +31,7 @@ namespace PizzeriaView
{
dataGridView.DataSource = list;
dataGridView.Columns["PizzaId"].Visible = false;
dataGridView.Columns["ClientId"].Visible = false;
dataGridView.Columns["PizzaName"].AutoSizeMode =
DataGridViewAutoSizeColumnMode.Fill;
}
@ -175,5 +176,14 @@ namespace PizzeriaView
form.ShowDialog();
}
}
private void ClientToolStripMenuItem_Click(object sender, EventArgs e)
{
var service = Program.ServiceProvider?.GetService(typeof(FormClients));
if (service is FormClients form)
{
form.ShowDialog();
}
}
}
}

View File

@ -8,9 +8,9 @@ using PizzeriaDatabaseImplement.Implements;
using PizzeriaView;
using System;
using System.Drawing;
using PizzeriaBusinessLogic.BusinessLogics;
using PizzeriaBusinessLogic.Implements;
using PizzeriaBusinessLogic.OfficePackage;
using Microsoft.EntityFrameworkCore.Design;
namespace Pizzeria
{
@ -65,6 +65,7 @@ namespace Pizzeria
services.AddTransient<FormReportPizzaComponents>();
services.AddTransient<FormReportOrders>();
services.AddTransient<FormClients>();
services.AddTransient<EntityFrameworkDesignServicesBuilder>();
}
}
}

View File

@ -0,0 +1,17 @@
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Newtonsoft.Json" Version="13.0.2" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\AbstractShopContracts\AbstractShopContracts.csproj" />
</ItemGroup>
</Project>

View File

@ -3,6 +3,7 @@ using PizzeriaContracts.ViewModels;
using PizzeriaShowClientApp.Models;
using Microsoft.AspNetCore.Mvc;
using System.Diagnostics;
using PizzeriaClientApp;
namespace PizzeriaShowClientApp.Controllers
{
@ -112,7 +113,7 @@ namespace PizzeriaShowClientApp.Controllers
[HttpGet]
public IActionResult Create()
{
ViewBag.Products = APIClient.GetRequest<List<ProductViewModel>>("api/main/getproductlist");
ViewBag.Products = APIClient.GetRequest<List<PizzaViewModel>>("api/main/getproductlist");
return View();
}
@ -130,7 +131,7 @@ namespace PizzeriaShowClientApp.Controllers
APIClient.PostRequest("api/main/createorder", new OrderBindingModel
{
//ClientId = APIClient.Client.Id,
ProductId = product,
PizzaId = product,
Count = count,
Sum = Calc(count, product)
});
@ -140,7 +141,7 @@ namespace PizzeriaShowClientApp.Controllers
[HttpPost]
public double Calc(int count, int product)
{
var prod = APIClient.GetRequest<ProductViewModel>($"api/main/getproduct?productId={product}");
var prod = APIClient.GetRequest<PizzaViewModel>($"api/main/getproduct?productId={product}");
return count * (prod?.Price ?? 1);
}
}

View File

@ -9,10 +9,10 @@ namespace PizzeriaContracts.ViewModels
[DisplayName("Номер")]
public int Id { get; set; }
public int ClientID { get; set; }
public int ClientId { get; set; }
[DisplayName("Имя клиента")]
public string? ClientFIO { get; set; }
public string? ClientFIO { get; set; } = string.Empty;
public int PizzaId { get; set; }

View File

@ -10,6 +10,7 @@ namespace PizzeriaDataModels.Models
public interface IOrderModel : IId
{
int PizzaId { get; }
int ClientId { get; }
int Count { get; }
double Sum { get; }
OrderStatus Status { get; }

View File

@ -0,0 +1,84 @@
using PizzeriaContracts.BindingModels;
using PizzeriaContracts.SearchModels;
using PizzeriaContracts.StoragesContracts;
using PizzeriaContracts.ViewModels;
using PizzeriaDatabaseImplement.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace PizzeriaDatabaseImplement.Implements
{
public class ClientStorage : IClientStorage
{
public ClientViewModel? Delete(ClientBindingModel model)
{
using var context = new PizzeriaDatabase();
var element = context.Clients.FirstOrDefault(rec => rec.Id == model.Id);
if (element != null)
{
context.Clients.Remove(element);
context.SaveChanges();
return element.GetViewModel;
}
return null;
}
public ClientViewModel? GetElement(ClientSearchModel model)
{
if (string.IsNullOrEmpty(model.ClientFIO) && !model.Id.HasValue)
{
return null;
}
using var context = new PizzeriaDatabase();
return context.Clients.FirstOrDefault(x =>
(!string.IsNullOrEmpty(model.ClientFIO) && x.ClientFIO == model.ClientFIO) ||
(model.Id.HasValue && x.Id == model.Id))
?.GetViewModel;
}
public List<ClientViewModel> GetFilteredList(ClientSearchModel model)
{
if (string.IsNullOrEmpty(model.ClientFIO))
{
return new();
}
using var context = new PizzeriaDatabase();
return context.Clients.Where(x => x.ClientFIO.Contains(model.ClientFIO)).Select(x => x.GetViewModel).ToList();
}
public List<ClientViewModel> GetFullList()
{
using var context = new PizzeriaDatabase();
return context.Clients.Select(x => x.GetViewModel).ToList();
}
public ClientViewModel? Insert(ClientBindingModel model)
{
var newComponent = Client.Create(model);
if (newComponent == null)
{
return null;
}
using var context = new PizzeriaDatabase();
context.Clients.Add(newComponent);
context.SaveChanges();
return newComponent.GetViewModel;
}
public ClientViewModel? Update(ClientBindingModel model)
{
using var context = new PizzeriaDatabase();
var component = context.Clients.FirstOrDefault(x => x.Id == model.Id);
if (component == null)
{
return null;
}
component.Update(model);
context.SaveChanges();
return component.GetViewModel;
}
}
}

View File

@ -0,0 +1,223 @@
// <auto-generated />
using System;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Metadata;
using Microsoft.EntityFrameworkCore.Migrations;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
using PizzeriaDatabaseImplement;
#nullable disable
namespace PizzeriaDatabaseImplement.Migrations
{
[DbContext(typeof(PizzeriaDatabase))]
[Migration("20230326163442_InitialCreate")]
partial class InitialCreate
{
/// <inheritdoc />
protected override void BuildTargetModel(ModelBuilder modelBuilder)
{
#pragma warning disable 612, 618
modelBuilder
.HasAnnotation("ProductVersion", "7.0.3")
.HasAnnotation("Relational:MaxIdentifierLength", 128);
SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder);
modelBuilder.Entity("PizzeriaDatabaseImplement.Models.Client", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<string>("ClientFIO")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<string>("Email")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<string>("Password")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.HasKey("Id");
b.ToTable("Clients");
});
modelBuilder.Entity("PizzeriaDatabaseImplement.Models.Component", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<string>("ComponentName")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<double>("Cost")
.HasColumnType("float");
b.HasKey("Id");
b.ToTable("Components");
});
modelBuilder.Entity("PizzeriaDatabaseImplement.Models.Order", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<int>("ClientId")
.HasColumnType("int");
b.Property<int>("Count")
.HasColumnType("int");
b.Property<DateTime>("DateCreate")
.HasColumnType("datetime2");
b.Property<DateTime?>("DateImplement")
.HasColumnType("datetime2");
b.Property<int>("PizzaId")
.HasColumnType("int");
b.Property<int>("Status")
.HasColumnType("int");
b.Property<double>("Sum")
.HasColumnType("float");
b.HasKey("Id");
b.HasIndex("ClientId");
b.HasIndex("PizzaId");
b.ToTable("Orders");
});
modelBuilder.Entity("PizzeriaDatabaseImplement.Models.Pizza", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<string>("PizzaName")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<double>("Price")
.HasColumnType("float");
b.HasKey("Id");
b.ToTable("Pizzas");
});
modelBuilder.Entity("PizzeriaDatabaseImplement.Models.PizzaComponent", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<int?>("ClientId")
.HasColumnType("int");
b.Property<int>("ComponentId")
.HasColumnType("int");
b.Property<int>("Count")
.HasColumnType("int");
b.Property<int>("PizzaId")
.HasColumnType("int");
b.HasKey("Id");
b.HasIndex("ClientId");
b.HasIndex("ComponentId");
b.HasIndex("PizzaId");
b.ToTable("PizzaComponents");
});
modelBuilder.Entity("PizzeriaDatabaseImplement.Models.Order", b =>
{
b.HasOne("PizzeriaDatabaseImplement.Models.Client", "Client")
.WithMany()
.HasForeignKey("ClientId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("PizzeriaDatabaseImplement.Models.Pizza", "Pizza")
.WithMany("Orders")
.HasForeignKey("PizzaId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Client");
b.Navigation("Pizza");
});
modelBuilder.Entity("PizzeriaDatabaseImplement.Models.PizzaComponent", b =>
{
b.HasOne("PizzeriaDatabaseImplement.Models.Client", null)
.WithMany("Components")
.HasForeignKey("ClientId");
b.HasOne("PizzeriaDatabaseImplement.Models.Component", "Component")
.WithMany("PizzaComponents")
.HasForeignKey("ComponentId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("PizzeriaDatabaseImplement.Models.Pizza", "Pizza")
.WithMany("Components")
.HasForeignKey("PizzaId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Component");
b.Navigation("Pizza");
});
modelBuilder.Entity("PizzeriaDatabaseImplement.Models.Client", b =>
{
b.Navigation("Components");
});
modelBuilder.Entity("PizzeriaDatabaseImplement.Models.Component", b =>
{
b.Navigation("PizzaComponents");
});
modelBuilder.Entity("PizzeriaDatabaseImplement.Models.Pizza", b =>
{
b.Navigation("Components");
b.Navigation("Orders");
});
#pragma warning restore 612, 618
}
}
}

View File

@ -0,0 +1,166 @@
using System;
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace PizzeriaDatabaseImplement.Migrations
{
/// <inheritdoc />
public partial class InitialCreate : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.CreateTable(
name: "Clients",
columns: table => new
{
Id = table.Column<int>(type: "int", nullable: false)
.Annotation("SqlServer:Identity", "1, 1"),
ClientFIO = table.Column<string>(type: "nvarchar(max)", nullable: false),
Email = table.Column<string>(type: "nvarchar(max)", nullable: false),
Password = table.Column<string>(type: "nvarchar(max)", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Clients", x => x.Id);
});
migrationBuilder.CreateTable(
name: "Components",
columns: table => new
{
Id = table.Column<int>(type: "int", nullable: false)
.Annotation("SqlServer:Identity", "1, 1"),
ComponentName = table.Column<string>(type: "nvarchar(max)", nullable: false),
Cost = table.Column<double>(type: "float", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Components", x => x.Id);
});
migrationBuilder.CreateTable(
name: "Pizzas",
columns: table => new
{
Id = table.Column<int>(type: "int", nullable: false)
.Annotation("SqlServer:Identity", "1, 1"),
PizzaName = table.Column<string>(type: "nvarchar(max)", nullable: false),
Price = table.Column<double>(type: "float", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Pizzas", x => x.Id);
});
migrationBuilder.CreateTable(
name: "Orders",
columns: table => new
{
Id = table.Column<int>(type: "int", nullable: false)
.Annotation("SqlServer:Identity", "1, 1"),
ClientId = table.Column<int>(type: "int", nullable: false),
PizzaId = table.Column<int>(type: "int", nullable: false),
Count = table.Column<int>(type: "int", nullable: false),
Sum = table.Column<double>(type: "float", nullable: false),
Status = table.Column<int>(type: "int", nullable: false),
DateCreate = table.Column<DateTime>(type: "datetime2", nullable: false),
DateImplement = table.Column<DateTime>(type: "datetime2", nullable: true)
},
constraints: table =>
{
table.PrimaryKey("PK_Orders", x => x.Id);
table.ForeignKey(
name: "FK_Orders_Clients_ClientId",
column: x => x.ClientId,
principalTable: "Clients",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
table.ForeignKey(
name: "FK_Orders_Pizzas_PizzaId",
column: x => x.PizzaId,
principalTable: "Pizzas",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateTable(
name: "PizzaComponents",
columns: table => new
{
Id = table.Column<int>(type: "int", nullable: false)
.Annotation("SqlServer:Identity", "1, 1"),
PizzaId = table.Column<int>(type: "int", nullable: false),
ComponentId = table.Column<int>(type: "int", nullable: false),
Count = table.Column<int>(type: "int", nullable: false),
ClientId = table.Column<int>(type: "int", nullable: true)
},
constraints: table =>
{
table.PrimaryKey("PK_PizzaComponents", x => x.Id);
table.ForeignKey(
name: "FK_PizzaComponents_Clients_ClientId",
column: x => x.ClientId,
principalTable: "Clients",
principalColumn: "Id");
table.ForeignKey(
name: "FK_PizzaComponents_Components_ComponentId",
column: x => x.ComponentId,
principalTable: "Components",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
table.ForeignKey(
name: "FK_PizzaComponents_Pizzas_PizzaId",
column: x => x.PizzaId,
principalTable: "Pizzas",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateIndex(
name: "IX_Orders_ClientId",
table: "Orders",
column: "ClientId");
migrationBuilder.CreateIndex(
name: "IX_Orders_PizzaId",
table: "Orders",
column: "PizzaId");
migrationBuilder.CreateIndex(
name: "IX_PizzaComponents_ClientId",
table: "PizzaComponents",
column: "ClientId");
migrationBuilder.CreateIndex(
name: "IX_PizzaComponents_ComponentId",
table: "PizzaComponents",
column: "ComponentId");
migrationBuilder.CreateIndex(
name: "IX_PizzaComponents_PizzaId",
table: "PizzaComponents",
column: "PizzaId");
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropTable(
name: "Orders");
migrationBuilder.DropTable(
name: "PizzaComponents");
migrationBuilder.DropTable(
name: "Clients");
migrationBuilder.DropTable(
name: "Components");
migrationBuilder.DropTable(
name: "Pizzas");
}
}
}

View File

@ -0,0 +1,57 @@
using PizzeriaContracts.BindingModels;
using PizzeriaContracts.ViewModels;
using PizzeriaDataModels.Models;
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace PizzeriaDatabaseImplement.Models
{
public class Client : IClientModel
{
public int Id { get; set; }
[Required]
public string ClientFIO { get; set; }
[Required]
public string Email { get; set; }
[Required]
public string Password { get; set; }
[ForeignKey("ClientId")]
public virtual List<PizzaComponent> Components { get; set; } = new();
public ClientViewModel GetViewModel => new()
{
Id = Id,
ClientFIO = ClientFIO,
Email = Email,
Password = Password
};
public static Client Create(ClientBindingModel model)
{
return new Client()
{
Id = model.Id,
ClientFIO = model.ClientFIO,
Email = model.Email,
Password = model.Password,
};
}
public void Update(ClientBindingModel model)
{
ClientFIO = model.ClientFIO;
Email = model.Email;
Password = model.Password;
}
}
}

View File

@ -33,8 +33,7 @@ namespace PizzeriaDatabaseImplement.Models
[ForeignKey("PizzaId")]
public virtual List<Order> Orders { get; set; } = new();
public static Pizza
Create(PizzeriaDatabase context, PizzaBindingModel model)
public static Pizza Create(PizzeriaDatabase context, PizzaBindingModel model)
{
return new Pizza()
{
@ -61,7 +60,7 @@ namespace PizzeriaDatabaseImplement.Models
};
public void UpdateComponents(PizzeriaDatabase context, PizzaBindingModel model)
{
var pizzaComponents = context.PizzaComponents.Where(rec => rec.ProductId == model.Id).ToList();
var pizzaComponents = context.PizzaComponents.Where(rec => rec.PizzaId == model.Id).ToList();
if (pizzaComponents != null && pizzaComponents.Count > 0) {
context.PizzaComponents.RemoveRange(pizzaComponents.Where(rec => !model.PizzaComponents.ContainsKey(rec.ComponentId)));
@ -74,11 +73,11 @@ namespace PizzeriaDatabaseImplement.Models
context.SaveChanges();
}
var product = context.Pizzas.First(x => x.Id == Id);
var pizza = context.Pizzas.First(x => x.Id == Id);
foreach (var pc in model.PizzaComponents) {
context.PizzaComponents.Add(new PizzaComponent
{
Product = product,
Pizza = pizza,
Component = context.Components.First(x => x.Id == pc.Key),
Count = pc.Value.Item2
});

View File

@ -11,12 +11,12 @@ namespace PizzeriaDatabaseImplement.Models
{
public int Id { get; set; }
[Required]
public int ProductId { get; set; }
public int PizzaId { get; set; }
[Required]
public int ComponentId { get; set; }
[Required]
public int Count { get; set; }
public virtual Component Component { get; set; } = new();
public virtual Pizza Product { get; set; } = new();
public virtual Pizza Pizza { get; set; } = new();
}
}

View File

@ -18,6 +18,7 @@ namespace PizzeriaDatabaseImplement
public virtual DbSet<Pizza> Pizzas { set; get; }
public virtual DbSet<PizzaComponent> PizzaComponents { set; get; }
public virtual DbSet<Order> Orders { set; get; }
public virtual DbSet<Client> Clients { set; get; }
}
}

View File

@ -9,6 +9,7 @@ namespace PizzeriaFileImplement.Models
public class Order : IOrderModel
{
public int Id { get; private set; }
public int ClientId { get; private set; }
public int PizzaId { get; private set; }
public int Count { get; private set; }
public double Sum { get; private set; }

View File

@ -8,6 +8,8 @@ namespace PizzeriaListImplement.Models
public class Order : IOrderModel
{
public int Id { get; private set; }
public int ClientId { get; private set; }
public int PizzaId { get; private set; }
public int Count { get; private set; }
public double Sum { get; private set; }