diff --git a/Pizzeria/Pizzeria/FormReportShop.Designer.cs b/Pizzeria/Pizzeria/FormReportShop.Designer.cs index a31aa59..dcdd668 100644 --- a/Pizzeria/Pizzeria/FormReportShop.Designer.cs +++ b/Pizzeria/Pizzeria/FormReportShop.Designer.cs @@ -31,7 +31,7 @@ this.buttonSaveToExcel = new System.Windows.Forms.Button(); this.dataGridView = new System.Windows.Forms.DataGridView(); this.ColumnShop = new System.Windows.Forms.DataGridViewTextBoxColumn(); - this.ColumnReinforced = new System.Windows.Forms.DataGridViewTextBoxColumn(); + this.ColumnPizza = new System.Windows.Forms.DataGridViewTextBoxColumn(); this.ColumnCount = new System.Windows.Forms.DataGridViewTextBoxColumn(); ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit(); this.SuspendLayout(); @@ -55,7 +55,7 @@ this.dataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; this.dataGridView.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] { this.ColumnShop, - this.ColumnReinforced, + this.ColumnPizza, this.ColumnCount}); this.dataGridView.Dock = System.Windows.Forms.DockStyle.Bottom; this.dataGridView.Location = new System.Drawing.Point(0, 47); @@ -74,13 +74,13 @@ this.ColumnShop.Name = "ColumnShop"; this.ColumnShop.ReadOnly = true; // - // ColumnReinforced + // ColumnPizza // - this.ColumnReinforced.FillWeight = 140F; - this.ColumnReinforced.HeaderText = "Изделие"; - this.ColumnReinforced.MinimumWidth = 6; - this.ColumnReinforced.Name = "ColumnReinforced"; - this.ColumnReinforced.ReadOnly = true; + this.ColumnPizza.FillWeight = 140F; + this.ColumnPizza.HeaderText = "Пицца"; + this.ColumnPizza.MinimumWidth = 6; + this.ColumnPizza.Name = "ColumnPizza"; + this.ColumnPizza.ReadOnly = true; // // ColumnCount // @@ -90,14 +90,14 @@ this.ColumnCount.Name = "ColumnCount"; this.ColumnCount.ReadOnly = true; // - // FormReportShopReinforcedes + // FormReportShopPizzas // this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.ClientSize = new System.Drawing.Size(598, 450); this.Controls.Add(this.buttonSaveToExcel); this.Controls.Add(this.dataGridView); - this.Name = "FormReportShopReinforcedes"; + this.Name = "FormReportShopPizzas"; this.Text = "Наполненость магазинов"; this.Load += new System.EventHandler(this.FormReportShop_Load); ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit(); @@ -110,7 +110,7 @@ private Button buttonSaveToExcel; private DataGridView dataGridView; private DataGridViewTextBoxColumn ColumnShop; - private DataGridViewTextBoxColumn ColumnReinforced; + private DataGridViewTextBoxColumn ColumnPizza; private DataGridViewTextBoxColumn ColumnCount; } } \ No newline at end of file diff --git a/Pizzeria/PizzeriaContracts/ViewModels/PizzaCount.cs b/Pizzeria/PizzeriaContracts/ViewModels/PizzaCount.cs new file mode 100644 index 0000000..a990e0c --- /dev/null +++ b/Pizzeria/PizzeriaContracts/ViewModels/PizzaCount.cs @@ -0,0 +1,15 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace PizzeriaContracts.ViewModels +{ + public class PizzaCount + { + public PizzaViewModel Pizza { get; set; } = new(); + + public int Count { get; set; } = new(); + } +} diff --git a/Pizzeria/PizzeriaContracts/ViewModels/ShopProducts.cs b/Pizzeria/PizzeriaContracts/ViewModels/ShopProducts.cs new file mode 100644 index 0000000..be5bf8f --- /dev/null +++ b/Pizzeria/PizzeriaContracts/ViewModels/ShopProducts.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace PizzeriaContracts.ViewModels +{ + public class ShopProducts + { + public ShopViewModel Shop { get; set; } = new(); + public Dictionary ShopPizza { get; set; } = new(); + } +} diff --git a/Pizzeria/PizzeriaDatabaseImplement/Migrations/20230503183159_init.Designer.cs b/Pizzeria/PizzeriaDatabaseImplement/Migrations/20230503183159_init.Designer.cs new file mode 100644 index 0000000..e834a0b --- /dev/null +++ b/Pizzeria/PizzeriaDatabaseImplement/Migrations/20230503183159_init.Designer.cs @@ -0,0 +1,300 @@ +// +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("20230503183159_init")] + partial class init + { + /// + 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.Shop", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("Adress") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("OpeningDate") + .HasColumnType("datetime2"); + + b.Property("PizzaMaxCount") + .HasColumnType("int"); + + b.Property("ShopName") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.HasKey("Id"); + + b.ToTable("Shops"); + }); + + modelBuilder.Entity("PizzeriaDatabaseImplement.Models.ShopPizzas", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("Count") + .HasColumnType("int"); + + b.Property("PizzaId") + .HasColumnType("int"); + + b.Property("ShopId") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.HasIndex("PizzaId"); + + b.HasIndex("ShopId"); + + b.ToTable("ShopPizzas"); + }); + + 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.ShopPizzas", b => + { + b.HasOne("PizzeriaDatabaseImplement.Models.Pizza", "Pizza") + .WithMany() + .HasForeignKey("PizzaId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("PizzeriaDatabaseImplement.Models.Shop", "Shop") + .WithMany("Pizzas") + .HasForeignKey("ShopId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Pizza"); + + b.Navigation("Shop"); + }); + + 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"); + }); + + modelBuilder.Entity("PizzeriaDatabaseImplement.Models.Shop", b => + { + b.Navigation("Pizzas"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/Pizzeria/PizzeriaDatabaseImplement/Migrations/20230503183159_init.cs b/Pizzeria/PizzeriaDatabaseImplement/Migrations/20230503183159_init.cs new file mode 100644 index 0000000..86bf874 --- /dev/null +++ b/Pizzeria/PizzeriaDatabaseImplement/Migrations/20230503183159_init.cs @@ -0,0 +1,225 @@ +using System; +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +namespace PizzeriaDatabaseImplement.Migrations +{ + /// + public partial class init : 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: "Shops", + columns: table => new + { + Id = table.Column(type: "int", nullable: false) + .Annotation("SqlServer:Identity", "1, 1"), + ShopName = table.Column(type: "nvarchar(max)", nullable: false), + Adress = table.Column(type: "nvarchar(max)", nullable: false), + OpeningDate = table.Column(type: "datetime2", nullable: false), + PizzaMaxCount = table.Column(type: "int", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Shops", 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.CreateTable( + name: "ShopPizzas", + columns: table => new + { + Id = table.Column(type: "int", nullable: false) + .Annotation("SqlServer:Identity", "1, 1"), + PizzaId = table.Column(type: "int", nullable: false), + ShopId = table.Column(type: "int", nullable: false), + Count = table.Column(type: "int", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_ShopPizzas", x => x.Id); + table.ForeignKey( + name: "FK_ShopPizzas_Pizzas_PizzaId", + column: x => x.PizzaId, + principalTable: "Pizzas", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + table.ForeignKey( + name: "FK_ShopPizzas_Shops_ShopId", + column: x => x.ShopId, + principalTable: "Shops", + 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"); + + migrationBuilder.CreateIndex( + name: "IX_ShopPizzas_PizzaId", + table: "ShopPizzas", + column: "PizzaId"); + + migrationBuilder.CreateIndex( + name: "IX_ShopPizzas_ShopId", + table: "ShopPizzas", + column: "ShopId"); + } + + /// + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropTable( + name: "Orders"); + + migrationBuilder.DropTable( + name: "PizzaComponents"); + + migrationBuilder.DropTable( + name: "ShopPizzas"); + + migrationBuilder.DropTable( + name: "Clients"); + + migrationBuilder.DropTable( + name: "Components"); + + migrationBuilder.DropTable( + name: "Pizzas"); + + migrationBuilder.DropTable( + name: "Shops"); + } + } +} diff --git a/Pizzeria/PizzeriaDatabaseImplement/Migrations/PizzeriaDatabaseModelSnapshot.cs b/Pizzeria/PizzeriaDatabaseImplement/Migrations/PizzeriaDatabaseModelSnapshot.cs new file mode 100644 index 0000000..5b041a4 --- /dev/null +++ b/Pizzeria/PizzeriaDatabaseImplement/Migrations/PizzeriaDatabaseModelSnapshot.cs @@ -0,0 +1,297 @@ +// +using System; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Metadata; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; +using PizzeriaDatabaseImplement; + +#nullable disable + +namespace PizzeriaDatabaseImplement.Migrations +{ + [DbContext(typeof(PizzeriaDatabase))] + partial class PizzeriaDatabaseModelSnapshot : ModelSnapshot + { + protected override void BuildModel(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.Shop", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("Adress") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("OpeningDate") + .HasColumnType("datetime2"); + + b.Property("PizzaMaxCount") + .HasColumnType("int"); + + b.Property("ShopName") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.HasKey("Id"); + + b.ToTable("Shops"); + }); + + modelBuilder.Entity("PizzeriaDatabaseImplement.Models.ShopPizzas", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("Count") + .HasColumnType("int"); + + b.Property("PizzaId") + .HasColumnType("int"); + + b.Property("ShopId") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.HasIndex("PizzaId"); + + b.HasIndex("ShopId"); + + b.ToTable("ShopPizzas"); + }); + + 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.ShopPizzas", b => + { + b.HasOne("PizzeriaDatabaseImplement.Models.Pizza", "Pizza") + .WithMany() + .HasForeignKey("PizzaId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("PizzeriaDatabaseImplement.Models.Shop", "Shop") + .WithMany("Pizzas") + .HasForeignKey("ShopId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Pizza"); + + b.Navigation("Shop"); + }); + + 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"); + }); + + modelBuilder.Entity("PizzeriaDatabaseImplement.Models.Shop", b => + { + b.Navigation("Pizzas"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/Pizzeria/PizzeriaDatabaseImplement/PizzeriaDatabase.cs b/Pizzeria/PizzeriaDatabaseImplement/PizzeriaDatabase.cs index 97f2c93..dedf362 100644 --- a/Pizzeria/PizzeriaDatabaseImplement/PizzeriaDatabase.cs +++ b/Pizzeria/PizzeriaDatabaseImplement/PizzeriaDatabase.cs @@ -20,5 +20,8 @@ namespace PizzeriaDatabaseImplement public virtual DbSet Orders { set; get; } public virtual DbSet Clients { set; get; } + public virtual DbSet Shops { set; get; } + public virtual DbSet ShopPizzas { set; get; } + } } \ No newline at end of file diff --git a/Pizzeria/PizzeriaShopRestApi/APIConfig.cs b/Pizzeria/PizzeriaShopRestApi/APIConfig.cs new file mode 100644 index 0000000..6b6bbf2 --- /dev/null +++ b/Pizzeria/PizzeriaShopRestApi/APIConfig.cs @@ -0,0 +1,12 @@ +namespace PizzeriaShopRestApi +{ + public class APIConfig + { + public static string? ShopPassword; + + public static void LoadData(IConfiguration configuration) + { + ShopPassword = configuration["ShopAPIPassword"]; + } + } +} diff --git a/Pizzeria/PizzeriaShopRestApi/Controllers/ShopController.cs b/Pizzeria/PizzeriaShopRestApi/Controllers/ShopController.cs new file mode 100644 index 0000000..c400026 --- /dev/null +++ b/Pizzeria/PizzeriaShopRestApi/Controllers/ShopController.cs @@ -0,0 +1,151 @@ +using PizzeriaDataModels.Models; +using Microsoft.AspNetCore.Mvc; +using PizzeriaContracts; +using PizzeriaContracts.BindingModels; +using PizzeriaContracts.BusinessLogicsContracts; +using PizzeriaContracts.SearchModels; +using PizzeriaContracts.ViewModels; +using PizzeriaDatabaseImplement.Models; +using System.Runtime.Serialization.Json; +using System.Text.Json; + +namespace PizzeriaShopRestApi.Controllers +{ + [Route("api/[controller]/[action]")] + [ApiController] + public class ShopController : Controller + { + private readonly ILogger _logger; + private readonly IShopLogic _shopLogic; + + public ShopController(ILogger logger, IShopLogic shopLogic) + { + _logger = logger; + _shopLogic = shopLogic; + } + + [HttpGet] + public bool Authentication(string password) + { + return CheckPassword(password); + } + + [HttpGet] + public List? GetShopList(string password) + { + if (!CheckPassword(password)) + { + return null; + } + try + { + return _shopLogic.ReadList(null); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка получения списка магазинов"); + throw; + } + } + + [HttpGet] + public ShopProducts? GetShop(int shopId, string password) + { + if (!CheckPassword(password)) + { + return null; + } + try + { + var shop = _shopLogic.ReadElement(new ShopSearchModel { Id = shopId }); + return new ShopProducts + { + Shop = shop, + ShopPizza = shop?.ShopPizzas?.ToDictionary(x => x.Key, x => new PizzaCount{ Pizza = x.Value.Item1 as PizzaViewModel, Count = x.Value.Item2 }) + }; + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка получения магазина"); + throw; + } + } + + [HttpPost] + public void CreateShop(ShopBindingModel model, string password) + { + if (!CheckPassword(password)) + { + return; + } + try + { + _shopLogic.Create(model); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка создания магазина"); + throw; + } + } + + [HttpPost] + public void UpdateShop(ShopBindingModel model, string password) + { + if (!CheckPassword(password)) + { + return; + } + try + { + _shopLogic.Update(model); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка обновления магазина"); + throw; + } + } + + [HttpDelete] + public void DeleteShop(int shopId,string password) + { + if (!CheckPassword(password)) + { + return; + } + try + { + _shopLogic.Delete(new ShopBindingModel {Id=shopId }); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка удаления магазина"); + throw; + } + } + + [HttpPost] + public void MakeSypply(SupplyBindingModel model, string password) + { + if (!CheckPassword(password)) + { + return; + } + try + { + _shopLogic.MakeSupply(model); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка создания поставки в магазин"); + throw; + } + } + + private bool CheckPassword(string password) + { + return APIConfig.ShopPassword == password; + } + } +} diff --git a/Pizzeria/PizzeriaShopRestApi/Program.cs b/Pizzeria/PizzeriaShopRestApi/Program.cs index b7a2b3c..c2d49fa 100644 --- a/Pizzeria/PizzeriaShopRestApi/Program.cs +++ b/Pizzeria/PizzeriaShopRestApi/Program.cs @@ -3,12 +3,13 @@ using PizzeriaContracts.BusinessLogicsContracts; using PizzeriaContracts.StoragesContracts; using PizzeriaDatabaseImplement.Implements; using Microsoft.OpenApi.Models; +using PizzeriaShopRestApi; var builder = WebApplication.CreateBuilder(args); builder.Logging.SetMinimumLevel(LogLevel.Trace); builder.Logging.AddLog4Net("log4net.config"); - +APIConfig.LoadData(builder.Configuration); // Add services to the container. builder.Services.AddTransient(); builder.Services.AddTransient(); diff --git a/Pizzeria/PizzeriaShopRestApi/appsettings.json b/Pizzeria/PizzeriaShopRestApi/appsettings.json index be2e30e..35f8608 100644 --- a/Pizzeria/PizzeriaShopRestApi/appsettings.json +++ b/Pizzeria/PizzeriaShopRestApi/appsettings.json @@ -6,4 +6,5 @@ } }, "AllowedHosts": "*", + "ShopAPIPassword": "123456" }