diff --git a/Pizzeria/Pizzeria.sln b/Pizzeria/Pizzeria.sln index d13f23c..c9b5c94 100644 --- a/Pizzeria/Pizzeria.sln +++ b/Pizzeria/Pizzeria.sln @@ -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 diff --git a/Pizzeria/Pizzeria/FormMain.Designer.cs b/Pizzeria/Pizzeria/FormMain.Designer.cs index 9f1dfb5..976efab 100644 --- a/Pizzeria/Pizzeria/FormMain.Designer.cs +++ b/Pizzeria/Pizzeria/FormMain.Designer.cs @@ -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; } } \ No newline at end of file diff --git a/Pizzeria/Pizzeria/FormMain.cs b/Pizzeria/Pizzeria/FormMain.cs index 3534ce0..1cb9644 100644 --- a/Pizzeria/Pizzeria/FormMain.cs +++ b/Pizzeria/Pizzeria/FormMain.cs @@ -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(); + } + } } } diff --git a/Pizzeria/Pizzeria/Program.cs b/Pizzeria/Pizzeria/Program.cs index a9a25d1..80b9624 100644 --- a/Pizzeria/Pizzeria/Program.cs +++ b/Pizzeria/Pizzeria/Program.cs @@ -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(); services.AddTransient(); services.AddTransient(); + services.AddTransient(); } } } \ No newline at end of file diff --git a/Pizzeria/PizzeriaClientApp/AbstractShowClientApp.csproj b/Pizzeria/PizzeriaClientApp/AbstractShowClientApp.csproj new file mode 100644 index 0000000..e0a21f1 --- /dev/null +++ b/Pizzeria/PizzeriaClientApp/AbstractShowClientApp.csproj @@ -0,0 +1,17 @@ + + + + net6.0 + enable + enable + + + + + + + + + + + diff --git a/Pizzeria/PizzeriaClientApp/Controllers/HomeController.cs b/Pizzeria/PizzeriaClientApp/Controllers/HomeController.cs index e0c668b..8339fcc 100644 --- a/Pizzeria/PizzeriaClientApp/Controllers/HomeController.cs +++ b/Pizzeria/PizzeriaClientApp/Controllers/HomeController.cs @@ -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>("api/main/getproductlist"); + ViewBag.Products = APIClient.GetRequest>("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($"api/main/getproduct?productId={product}"); + var prod = APIClient.GetRequest($"api/main/getproduct?productId={product}"); return count * (prod?.Price ?? 1); } } diff --git a/Pizzeria/PizzeriaContracts/ViewModels/OrderViewModel.cs b/Pizzeria/PizzeriaContracts/ViewModels/OrderViewModel.cs index 059b8a8..0593696 100644 --- a/Pizzeria/PizzeriaContracts/ViewModels/OrderViewModel.cs +++ b/Pizzeria/PizzeriaContracts/ViewModels/OrderViewModel.cs @@ -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; } diff --git a/Pizzeria/PizzeriaDataModels/Models/IOrderModel.cs b/Pizzeria/PizzeriaDataModels/Models/IOrderModel.cs index ecab3d7..ffd3d6b 100644 --- a/Pizzeria/PizzeriaDataModels/Models/IOrderModel.cs +++ b/Pizzeria/PizzeriaDataModels/Models/IOrderModel.cs @@ -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; } diff --git a/Pizzeria/PizzeriaDatabaseImplement/Implements/ClientStorage.cs b/Pizzeria/PizzeriaDatabaseImplement/Implements/ClientStorage.cs new file mode 100644 index 0000000..4d72188 --- /dev/null +++ b/Pizzeria/PizzeriaDatabaseImplement/Implements/ClientStorage.cs @@ -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 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 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; + } + } +} diff --git a/Pizzeria/PizzeriaDatabaseImplement/Migrations/20230326163442_InitialCreate.Designer.cs b/Pizzeria/PizzeriaDatabaseImplement/Migrations/20230326163442_InitialCreate.Designer.cs new file mode 100644 index 0000000..fdfe058 --- /dev/null +++ b/Pizzeria/PizzeriaDatabaseImplement/Migrations/20230326163442_InitialCreate.Designer.cs @@ -0,0 +1,223 @@ +// +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 + { + /// + 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("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("ClientFIO") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Email") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Password") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.HasKey("Id"); + + b.ToTable("Clients"); + }); + + modelBuilder.Entity("PizzeriaDatabaseImplement.Models.Component", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("ComponentName") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Cost") + .HasColumnType("float"); + + b.HasKey("Id"); + + b.ToTable("Components"); + }); + + modelBuilder.Entity("PizzeriaDatabaseImplement.Models.Order", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("ClientId") + .HasColumnType("int"); + + b.Property("Count") + .HasColumnType("int"); + + b.Property("DateCreate") + .HasColumnType("datetime2"); + + b.Property("DateImplement") + .HasColumnType("datetime2"); + + b.Property("PizzaId") + .HasColumnType("int"); + + b.Property("Status") + .HasColumnType("int"); + + b.Property("Sum") + .HasColumnType("float"); + + b.HasKey("Id"); + + b.HasIndex("ClientId"); + + b.HasIndex("PizzaId"); + + b.ToTable("Orders"); + }); + + modelBuilder.Entity("PizzeriaDatabaseImplement.Models.Pizza", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("PizzaName") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Price") + .HasColumnType("float"); + + b.HasKey("Id"); + + b.ToTable("Pizzas"); + }); + + modelBuilder.Entity("PizzeriaDatabaseImplement.Models.PizzaComponent", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("ClientId") + .HasColumnType("int"); + + b.Property("ComponentId") + .HasColumnType("int"); + + b.Property("Count") + .HasColumnType("int"); + + b.Property("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 + } + } +} diff --git a/Pizzeria/PizzeriaDatabaseImplement/Migrations/20230326163442_InitialCreate.cs b/Pizzeria/PizzeriaDatabaseImplement/Migrations/20230326163442_InitialCreate.cs new file mode 100644 index 0000000..8b81e2f --- /dev/null +++ b/Pizzeria/PizzeriaDatabaseImplement/Migrations/20230326163442_InitialCreate.cs @@ -0,0 +1,166 @@ +using System; +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +namespace PizzeriaDatabaseImplement.Migrations +{ + /// + public partial class InitialCreate : Migration + { + /// + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.CreateTable( + name: "Clients", + columns: table => new + { + Id = table.Column(type: "int", nullable: false) + .Annotation("SqlServer:Identity", "1, 1"), + ClientFIO = table.Column(type: "nvarchar(max)", nullable: false), + Email = table.Column(type: "nvarchar(max)", nullable: false), + Password = table.Column(type: "nvarchar(max)", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Clients", x => x.Id); + }); + + migrationBuilder.CreateTable( + name: "Components", + columns: table => new + { + Id = table.Column(type: "int", nullable: false) + .Annotation("SqlServer:Identity", "1, 1"), + ComponentName = table.Column(type: "nvarchar(max)", nullable: false), + Cost = table.Column(type: "float", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Components", x => x.Id); + }); + + migrationBuilder.CreateTable( + name: "Pizzas", + columns: table => new + { + Id = table.Column(type: "int", nullable: false) + .Annotation("SqlServer:Identity", "1, 1"), + PizzaName = table.Column(type: "nvarchar(max)", nullable: false), + Price = table.Column(type: "float", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Pizzas", x => x.Id); + }); + + migrationBuilder.CreateTable( + name: "Orders", + columns: table => new + { + Id = table.Column(type: "int", nullable: false) + .Annotation("SqlServer:Identity", "1, 1"), + ClientId = table.Column(type: "int", nullable: false), + PizzaId = table.Column(type: "int", nullable: false), + Count = table.Column(type: "int", nullable: false), + Sum = table.Column(type: "float", nullable: false), + Status = table.Column(type: "int", nullable: false), + DateCreate = table.Column(type: "datetime2", nullable: false), + DateImplement = table.Column(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(type: "int", nullable: false) + .Annotation("SqlServer:Identity", "1, 1"), + PizzaId = table.Column(type: "int", nullable: false), + ComponentId = table.Column(type: "int", nullable: false), + Count = table.Column(type: "int", nullable: false), + ClientId = table.Column(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"); + } + + /// + 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"); + } + } +} diff --git a/Pizzeria/PizzeriaDatabaseImplement/Models/Client.cs b/Pizzeria/PizzeriaDatabaseImplement/Models/Client.cs new file mode 100644 index 0000000..ce18966 --- /dev/null +++ b/Pizzeria/PizzeriaDatabaseImplement/Models/Client.cs @@ -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 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; + } + } +} diff --git a/Pizzeria/PizzeriaDatabaseImplement/Models/Pizza.cs b/Pizzeria/PizzeriaDatabaseImplement/Models/Pizza.cs index a32f628..87acbff 100644 --- a/Pizzeria/PizzeriaDatabaseImplement/Models/Pizza.cs +++ b/Pizzeria/PizzeriaDatabaseImplement/Models/Pizza.cs @@ -33,8 +33,7 @@ namespace PizzeriaDatabaseImplement.Models [ForeignKey("PizzaId")] public virtual List 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 }); diff --git a/Pizzeria/PizzeriaDatabaseImplement/Models/PizzaComponent.cs b/Pizzeria/PizzeriaDatabaseImplement/Models/PizzaComponent.cs index 35fb5aa..a5a83e3 100644 --- a/Pizzeria/PizzeriaDatabaseImplement/Models/PizzaComponent.cs +++ b/Pizzeria/PizzeriaDatabaseImplement/Models/PizzaComponent.cs @@ -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(); } } diff --git a/Pizzeria/PizzeriaDatabaseImplement/PizzeriaDatabase.cs b/Pizzeria/PizzeriaDatabaseImplement/PizzeriaDatabase.cs index ba9d1b2..67fde82 100644 --- a/Pizzeria/PizzeriaDatabaseImplement/PizzeriaDatabase.cs +++ b/Pizzeria/PizzeriaDatabaseImplement/PizzeriaDatabase.cs @@ -18,6 +18,7 @@ namespace PizzeriaDatabaseImplement public virtual DbSet Pizzas { set; get; } public virtual DbSet PizzaComponents { set; get; } public virtual DbSet Orders { set; get; } + public virtual DbSet Clients { set; get; } } } \ No newline at end of file diff --git a/Pizzeria/PizzeriaFileImplement/Models/Order.cs b/Pizzeria/PizzeriaFileImplement/Models/Order.cs index 80c21ca..b4fd1d4 100644 --- a/Pizzeria/PizzeriaFileImplement/Models/Order.cs +++ b/Pizzeria/PizzeriaFileImplement/Models/Order.cs @@ -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; } diff --git a/Pizzeria/PizzeriaListImplement/Models/Order.cs b/Pizzeria/PizzeriaListImplement/Models/Order.cs index 35020b0..505ab61 100644 --- a/Pizzeria/PizzeriaListImplement/Models/Order.cs +++ b/Pizzeria/PizzeriaListImplement/Models/Order.cs @@ -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; }