diff --git a/PrecastConcretePlant/PrecastConcretePlant/FormMain.cs b/PrecastConcretePlant/PrecastConcretePlant/FormMain.cs index f62fdd6..b9a1692 100644 --- a/PrecastConcretePlant/PrecastConcretePlant/FormMain.cs +++ b/PrecastConcretePlant/PrecastConcretePlant/FormMain.cs @@ -1,4 +1,4 @@ -using ConfectioneryView; + using Microsoft.Extensions.Logging; using PrecastConcretePlantContracts.BindingModels; using PrecastConcretePlantContracts.BusinessLogicsContracts; diff --git a/PrecastConcretePlant/PrecastConcretePlant/FormReinforcedShop.Designer.cs b/PrecastConcretePlant/PrecastConcretePlant/FormReinforcedShop.Designer.cs index abe81e2..ece5061 100644 --- a/PrecastConcretePlant/PrecastConcretePlant/FormReinforcedShop.Designer.cs +++ b/PrecastConcretePlant/PrecastConcretePlant/FormReinforcedShop.Designer.cs @@ -1,4 +1,4 @@ -namespace ConfectioneryView +namespace PrecastConcretePlantView { partial class FormReinforcedShop { diff --git a/PrecastConcretePlant/PrecastConcretePlant/FormReinforcedShop.cs b/PrecastConcretePlant/PrecastConcretePlant/FormReinforcedShop.cs index 565cc8c..e8122ce 100644 --- a/PrecastConcretePlant/PrecastConcretePlant/FormReinforcedShop.cs +++ b/PrecastConcretePlant/PrecastConcretePlant/FormReinforcedShop.cs @@ -12,7 +12,7 @@ using System.Text; using System.Threading.Tasks; using System.Windows.Forms; -namespace ConfectioneryView +namespace PrecastConcretePlantView { public partial class FormReinforcedShop : Form { diff --git a/PrecastConcretePlant/PrecastConcretePlant/FormShop.Designer.cs b/PrecastConcretePlant/PrecastConcretePlant/FormShop.Designer.cs index ca6cec6..00602f5 100644 --- a/PrecastConcretePlant/PrecastConcretePlant/FormShop.Designer.cs +++ b/PrecastConcretePlant/PrecastConcretePlant/FormShop.Designer.cs @@ -1,4 +1,4 @@ -namespace ConfectioneryView +namespace PrecastConcretePlantView { partial class FormShop { diff --git a/PrecastConcretePlant/PrecastConcretePlant/FormShop.cs b/PrecastConcretePlant/PrecastConcretePlant/FormShop.cs index 5f8fdc0..e1a4b16 100644 --- a/PrecastConcretePlant/PrecastConcretePlant/FormShop.cs +++ b/PrecastConcretePlant/PrecastConcretePlant/FormShop.cs @@ -16,7 +16,7 @@ using System.Text; using System.Threading.Tasks; using System.Windows.Forms; -namespace ConfectioneryView +namespace PrecastConcretePlantView { public partial class FormShop : Form { @@ -72,7 +72,7 @@ namespace ConfectioneryView var model = new ShopBindingModel { Id = _id ?? 0, - ShopName = comboBoxShop.Text, + Name = comboBoxShop.Text, Address = textBoxAddress.Text, DateOpening = textBoxDateOpening.Value.Date, ReinforcedMaxCount = (int)VolumeNumericUpDown.Value @@ -112,7 +112,7 @@ namespace ConfectioneryView }); if (view != null) { - comboBoxShop.Text = view.ShopName; + comboBoxShop.Text = view.Name; textBoxAddress.Text = view.Address; textBoxDateOpening.Text = view.DateOpening.ToString(); VolumeNumericUpDown.Value = view.ReinforcedMaxCount; diff --git a/PrecastConcretePlant/PrecastConcretePlant/FormShops.Designer.cs b/PrecastConcretePlant/PrecastConcretePlant/FormShops.Designer.cs index d2ce2f6..c9657ae 100644 --- a/PrecastConcretePlant/PrecastConcretePlant/FormShops.Designer.cs +++ b/PrecastConcretePlant/PrecastConcretePlant/FormShops.Designer.cs @@ -1,4 +1,4 @@ -namespace ConfectioneryView +namespace PrecastConcretePlantView { partial class FormShops { diff --git a/PrecastConcretePlant/PrecastConcretePlant/FormShops.cs b/PrecastConcretePlant/PrecastConcretePlant/FormShops.cs index c00af8d..b3fb52f 100644 --- a/PrecastConcretePlant/PrecastConcretePlant/FormShops.cs +++ b/PrecastConcretePlant/PrecastConcretePlant/FormShops.cs @@ -3,7 +3,7 @@ using PrecastConcretePlantContracts.BindingModels; using PrecastConcretePlantContracts.BusinessLogicsContracts; using PrecastConcretePlantView; -namespace ConfectioneryView +namespace PrecastConcretePlantView { public partial class FormShops : Form { diff --git a/PrecastConcretePlant/PrecastConcretePlantBusinessLogic/BusinessLogic/ShopLogic.cs b/PrecastConcretePlant/PrecastConcretePlantBusinessLogic/BusinessLogic/ShopLogic.cs index 58c1e0e..4e6aaa7 100644 --- a/PrecastConcretePlant/PrecastConcretePlantBusinessLogic/BusinessLogic/ShopLogic.cs +++ b/PrecastConcretePlant/PrecastConcretePlantBusinessLogic/BusinessLogic/ShopLogic.cs @@ -26,7 +26,7 @@ namespace PrecastConcretePlantBusinessLogic.BusinessLogic public List? ReadList(ShopSearchModel? model) { _logger.LogInformation("ReadList. Name:{Name}.Id:{ Id} ", - model?.ShopName, model?.Id); + model?.Name, model?.Id); var list = (model == null) ? _shopStorage.GetFullList() : _shopStorage.GetFilteredList(model); if (list == null) @@ -44,7 +44,7 @@ namespace PrecastConcretePlantBusinessLogic.BusinessLogic throw new ArgumentNullException(nameof(model)); } _logger.LogInformation("ReadElement. Name:{Name}.Id:{ Id}", - model.ShopName, model.Id); + model.Name, model.Id); var element = _shopStorage.GetElement(model); if (element == null) { @@ -72,10 +72,10 @@ namespace PrecastConcretePlantBusinessLogic.BusinessLogic public bool Update(ShopBindingModel model) { CheckModel(model, false); - if (string.IsNullOrEmpty(model.ShopName)) + if (string.IsNullOrEmpty(model.Name)) { throw new ArgumentNullException("Нет названия магазина", - nameof(model.ShopName)); + nameof(model.Name)); } if (_shopStorage.Update(model) == null) @@ -106,22 +106,22 @@ namespace PrecastConcretePlantBusinessLogic.BusinessLogic { return; } - if (string.IsNullOrEmpty(model.ShopName)) + if (string.IsNullOrEmpty(model.Name)) { throw new ArgumentNullException("Нет названия магазина", - nameof(model.ShopName)); + nameof(model.Name)); } if (model.ReinforcedMaxCount < 0) { throw new ArgumentException("Максимальное количество изделий в магазине не может быть меньше нуля", nameof(model.ReinforcedMaxCount)); } _logger.LogInformation("Shop. Name:{0}.Address:{1}. Id: {2}", - model.ShopName, model.Address, model.Id); + model.Name, model.Address, model.Id); var element = _shopStorage.GetElement(new ShopSearchModel { - ShopName = model.ShopName + Name = model.Name }); - if (element != null && element.Id != model.Id && element.ShopName == model.ShopName) + if (element != null && element.Id != model.Id && element.Name == model.Name) { throw new InvalidOperationException("Магазин с таким названием уже есть"); } @@ -139,7 +139,7 @@ namespace PrecastConcretePlantBusinessLogic.BusinessLogic throw new ArgumentException("Количество изделий должно быть больше 0", nameof(count)); } - _logger.LogInformation("AddReinforced. Name:{Name}.Id:{ Id}", model.ShopName, model.Id); + _logger.LogInformation("AddReinforced. Name:{Name}.Id:{ Id}", model.Name, model.Id); var element = _shopStorage.GetElement(model); if (element == null) @@ -158,19 +158,19 @@ namespace PrecastConcretePlantBusinessLogic.BusinessLogic if (element.ShopReinforcedies.TryGetValue(reinforced.Id, out var pair)) { element.ShopReinforcedies[reinforced.Id] = (reinforced, count + pair.Item2); - _logger.LogInformation("AddReinforced. Added {count} {reinforced} to '{Name}' shop", count, reinforced.ReinforcedName, element.ShopName); + _logger.LogInformation("AddReinforced. Added {count} {reinforced} to '{Name}' shop", count, reinforced.ReinforcedName, element.Name); } else { element.ShopReinforcedies[reinforced.Id] = (reinforced, count); - _logger.LogInformation("AddReinforced. Added {count} new reinforced {reinforced} to '{Name}' shop", count, reinforced.ReinforcedName, element.ShopName); + _logger.LogInformation("AddReinforced. Added {count} new reinforced {reinforced} to '{Name}' shop", count, reinforced.ReinforcedName, element.Name); } _shopStorage.Update(new() { Id = element.Id, Address = element.Address, - ShopName = element.ShopName, + Name = element.Name, DateOpening = element.DateOpening, ReinforcedMaxCount = element.ReinforcedMaxCount, ShopReinforcedies = element.ShopReinforcedies, diff --git a/PrecastConcretePlant/PrecastConcretePlantContracts/BindingModels/ShopBindingModel.cs b/PrecastConcretePlant/PrecastConcretePlantContracts/BindingModels/ShopBindingModel.cs index 854bf31..9d4213f 100644 --- a/PrecastConcretePlant/PrecastConcretePlantContracts/BindingModels/ShopBindingModel.cs +++ b/PrecastConcretePlant/PrecastConcretePlantContracts/BindingModels/ShopBindingModel.cs @@ -9,7 +9,7 @@ namespace PrecastConcretePlantContracts.BindingModels { public class ShopBindingModel : IShopModel { - public string ShopName { get; set; } = string.Empty; + public string Name { get; set; } = string.Empty; public string Address { get; set; } = string.Empty; public int ReinforcedMaxCount { get; set; } diff --git a/PrecastConcretePlant/PrecastConcretePlantContracts/SearchModels/ShopSearchModel.cs b/PrecastConcretePlant/PrecastConcretePlantContracts/SearchModels/ShopSearchModel.cs index b46f4a9..c08ab42 100644 --- a/PrecastConcretePlant/PrecastConcretePlantContracts/SearchModels/ShopSearchModel.cs +++ b/PrecastConcretePlant/PrecastConcretePlantContracts/SearchModels/ShopSearchModel.cs @@ -9,6 +9,6 @@ namespace PrecastConcretePlantContracts.SearchModels public class ShopSearchModel { public int? Id { get; set; } - public string? ShopName { get; set; } + public string? Name { get; set; } } } diff --git a/PrecastConcretePlant/PrecastConcretePlantContracts/ViewModels/ShopViewModel.cs b/PrecastConcretePlant/PrecastConcretePlantContracts/ViewModels/ShopViewModel.cs index c079c2f..1708dfc 100644 --- a/PrecastConcretePlant/PrecastConcretePlantContracts/ViewModels/ShopViewModel.cs +++ b/PrecastConcretePlant/PrecastConcretePlantContracts/ViewModels/ShopViewModel.cs @@ -11,7 +11,7 @@ namespace PrecastConcretePlantContracts.ViewModels public class ShopViewModel : IShopModel { [DisplayName("Название магазина")] - public string ShopName { get; set; } = string.Empty; + public string Name { get; set; } = string.Empty; [DisplayName("Адрес магазина")] public string Address { get; set; } = string.Empty; diff --git a/PrecastConcretePlant/PrecastConcretePlantDataModels/Models/IShopModel.cs b/PrecastConcretePlant/PrecastConcretePlantDataModels/Models/IShopModel.cs index fb03ab3..5d055cf 100644 --- a/PrecastConcretePlant/PrecastConcretePlantDataModels/Models/IShopModel.cs +++ b/PrecastConcretePlant/PrecastConcretePlantDataModels/Models/IShopModel.cs @@ -8,7 +8,7 @@ namespace PrecastConcretePlantDataModels.Models { public interface IShopModel : IId { - string ShopName { get; } + string Name { get; } string Address { get; } public int ReinforcedMaxCount { get; } DateTime DateOpening { get; } diff --git a/PrecastConcretePlant/PrecastConcretePlantDatabaseImplement/Implements/ShopStorage.cs b/PrecastConcretePlant/PrecastConcretePlantDatabaseImplement/Implements/ShopStorage.cs index ede4607..184e57a 100644 --- a/PrecastConcretePlant/PrecastConcretePlantDatabaseImplement/Implements/ShopStorage.cs +++ b/PrecastConcretePlant/PrecastConcretePlantDatabaseImplement/Implements/ShopStorage.cs @@ -28,7 +28,7 @@ namespace PrecastConcretePlantDatabaseImplement.Implements public List GetFilteredList(ShopSearchModel model) { - if (string.IsNullOrEmpty(model.ShopName)) + if (string.IsNullOrEmpty(model.Name)) { return new(); } @@ -36,7 +36,7 @@ namespace PrecastConcretePlantDatabaseImplement.Implements return context.Shops .Include(x => x.Reinforcedies) .ThenInclude(x => x.Reinforced) - .Where(x => x.ShopName.Contains(model.ShopName)) + .Where(x => x.Name.Contains(model.Name)) .ToList() .Select(x => x.GetViewModel) .ToList(); @@ -44,7 +44,7 @@ namespace PrecastConcretePlantDatabaseImplement.Implements public ShopViewModel? GetElement(ShopSearchModel model) { - if (string.IsNullOrEmpty(model.ShopName) && !model.Id.HasValue) + if (string.IsNullOrEmpty(model.Name) && !model.Id.HasValue) { return null; } @@ -52,7 +52,7 @@ namespace PrecastConcretePlantDatabaseImplement.Implements return context.Shops .Include(x => x.Reinforcedies) .ThenInclude(x => x.Reinforced) - .FirstOrDefault(x => (!string.IsNullOrEmpty(model.ShopName) && x.ShopName == model.ShopName) || + .FirstOrDefault(x => (!string.IsNullOrEmpty(model.Name) && x.Name == model.Name) || (model.Id.HasValue && x.Id == model.Id))?.GetViewModel; } diff --git a/PrecastConcretePlant/PrecastConcretePlantDatabaseImplement/Migrations/20230409150055_FirstMigr.Designer.cs b/PrecastConcretePlant/PrecastConcretePlantDatabaseImplement/Migrations/20230409150055_FirstMigr.Designer.cs new file mode 100644 index 0000000..150bb1c --- /dev/null +++ b/PrecastConcretePlant/PrecastConcretePlantDatabaseImplement/Migrations/20230409150055_FirstMigr.Designer.cs @@ -0,0 +1,252 @@ +// +using System; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Metadata; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; +using PrecastConcretePlantDatabaseImplement; + +#nullable disable + +namespace PrecastConcretePlantDatabaseImplement.Migrations +{ + [DbContext(typeof(PrecastConcretePlantDataBase))] + [Migration("20230409150055_FirstMigr")] + partial class FirstMigr + { + /// + 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("PrecastConcretePlantDatabaseImplement.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("PrecastConcretePlantDatabaseImplement.Models.Order", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("Count") + .HasColumnType("int"); + + b.Property("DateCreate") + .HasColumnType("datetime2"); + + b.Property("DateImplement") + .HasColumnType("datetime2"); + + b.Property("ReinforcedId") + .HasColumnType("int"); + + b.Property("ReinforcedName") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Status") + .HasColumnType("int"); + + b.Property("Sum") + .HasColumnType("float"); + + b.HasKey("Id"); + + b.HasIndex("ReinforcedId"); + + b.ToTable("Orders"); + }); + + modelBuilder.Entity("PrecastConcretePlantDatabaseImplement.Models.Reinforced", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("Price") + .HasColumnType("float"); + + b.Property("ReinforcedName") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.HasKey("Id"); + + b.ToTable("Reinforcedies"); + }); + + modelBuilder.Entity("PrecastConcretePlantDatabaseImplement.Models.ReinforcedComponent", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("ComponentId") + .HasColumnType("int"); + + b.Property("Count") + .HasColumnType("int"); + + b.Property("ReinforcedId") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.HasIndex("ComponentId"); + + b.HasIndex("ReinforcedId"); + + b.ToTable("ReinforcedComponents"); + }); + + modelBuilder.Entity("PrecastConcretePlantDatabaseImplement.Models.Shop", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("Address") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("DateOpening") + .HasColumnType("datetime2"); + + b.Property("Name") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("ReinforcedMaxCount") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.ToTable("Shops"); + }); + + modelBuilder.Entity("PrecastConcretePlantDatabaseImplement.Models.ShopReinforced", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("Count") + .HasColumnType("int"); + + b.Property("ReinforcedId") + .HasColumnType("int"); + + b.Property("ShopId") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.HasIndex("ReinforcedId"); + + b.HasIndex("ShopId"); + + b.ToTable("ShopReinforcedies"); + }); + + modelBuilder.Entity("PrecastConcretePlantDatabaseImplement.Models.Order", b => + { + b.HasOne("PrecastConcretePlantDatabaseImplement.Models.Reinforced", "Reinforced") + .WithMany("Orders") + .HasForeignKey("ReinforcedId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Reinforced"); + }); + + modelBuilder.Entity("PrecastConcretePlantDatabaseImplement.Models.ReinforcedComponent", b => + { + b.HasOne("PrecastConcretePlantDatabaseImplement.Models.Component", "Component") + .WithMany("ReinforcedComponents") + .HasForeignKey("ComponentId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("PrecastConcretePlantDatabaseImplement.Models.Reinforced", "Reinforced") + .WithMany("Components") + .HasForeignKey("ReinforcedId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Component"); + + b.Navigation("Reinforced"); + }); + + modelBuilder.Entity("PrecastConcretePlantDatabaseImplement.Models.ShopReinforced", b => + { + b.HasOne("PrecastConcretePlantDatabaseImplement.Models.Reinforced", "Reinforced") + .WithMany() + .HasForeignKey("ReinforcedId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("PrecastConcretePlantDatabaseImplement.Models.Shop", "Shop") + .WithMany("Reinforcedies") + .HasForeignKey("ShopId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Reinforced"); + + b.Navigation("Shop"); + }); + + modelBuilder.Entity("PrecastConcretePlantDatabaseImplement.Models.Component", b => + { + b.Navigation("ReinforcedComponents"); + }); + + modelBuilder.Entity("PrecastConcretePlantDatabaseImplement.Models.Reinforced", b => + { + b.Navigation("Components"); + + b.Navigation("Orders"); + }); + + modelBuilder.Entity("PrecastConcretePlantDatabaseImplement.Models.Shop", b => + { + b.Navigation("Reinforcedies"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/PrecastConcretePlant/PrecastConcretePlantDatabaseImplement/Migrations/20230409150055_FirstMigr.cs b/PrecastConcretePlant/PrecastConcretePlantDatabaseImplement/Migrations/20230409150055_FirstMigr.cs new file mode 100644 index 0000000..14e43b1 --- /dev/null +++ b/PrecastConcretePlant/PrecastConcretePlantDatabaseImplement/Migrations/20230409150055_FirstMigr.cs @@ -0,0 +1,185 @@ +using System; +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +namespace PrecastConcretePlantDatabaseImplement.Migrations +{ + /// + public partial class FirstMigr : Migration + { + /// + protected override void Up(MigrationBuilder migrationBuilder) + { + 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: "Reinforcedies", + columns: table => new + { + Id = table.Column(type: "int", nullable: false) + .Annotation("SqlServer:Identity", "1, 1"), + ReinforcedName = table.Column(type: "nvarchar(max)", nullable: false), + Price = table.Column(type: "float", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Reinforcedies", x => x.Id); + }); + + migrationBuilder.CreateTable( + name: "Shops", + columns: table => new + { + Id = table.Column(type: "int", nullable: false) + .Annotation("SqlServer:Identity", "1, 1"), + Name = table.Column(type: "nvarchar(max)", nullable: false), + Address = table.Column(type: "nvarchar(max)", nullable: false), + DateOpening = table.Column(type: "datetime2", nullable: false), + ReinforcedMaxCount = 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"), + ReinforcedId = table.Column(type: "int", nullable: false), + ReinforcedName = table.Column(type: "nvarchar(max)", 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_Reinforcedies_ReinforcedId", + column: x => x.ReinforcedId, + principalTable: "Reinforcedies", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateTable( + name: "ReinforcedComponents", + columns: table => new + { + Id = table.Column(type: "int", nullable: false) + .Annotation("SqlServer:Identity", "1, 1"), + ReinforcedId = table.Column(type: "int", nullable: false), + ComponentId = table.Column(type: "int", nullable: false), + Count = table.Column(type: "int", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_ReinforcedComponents", x => x.Id); + table.ForeignKey( + name: "FK_ReinforcedComponents_Components_ComponentId", + column: x => x.ComponentId, + principalTable: "Components", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + table.ForeignKey( + name: "FK_ReinforcedComponents_Reinforcedies_ReinforcedId", + column: x => x.ReinforcedId, + principalTable: "Reinforcedies", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateTable( + name: "ShopReinforcedies", + columns: table => new + { + Id = table.Column(type: "int", nullable: false) + .Annotation("SqlServer:Identity", "1, 1"), + ReinforcedId = 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_ShopReinforcedies", x => x.Id); + table.ForeignKey( + name: "FK_ShopReinforcedies_Reinforcedies_ReinforcedId", + column: x => x.ReinforcedId, + principalTable: "Reinforcedies", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + table.ForeignKey( + name: "FK_ShopReinforcedies_Shops_ShopId", + column: x => x.ShopId, + principalTable: "Shops", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateIndex( + name: "IX_Orders_ReinforcedId", + table: "Orders", + column: "ReinforcedId"); + + migrationBuilder.CreateIndex( + name: "IX_ReinforcedComponents_ComponentId", + table: "ReinforcedComponents", + column: "ComponentId"); + + migrationBuilder.CreateIndex( + name: "IX_ReinforcedComponents_ReinforcedId", + table: "ReinforcedComponents", + column: "ReinforcedId"); + + migrationBuilder.CreateIndex( + name: "IX_ShopReinforcedies_ReinforcedId", + table: "ShopReinforcedies", + column: "ReinforcedId"); + + migrationBuilder.CreateIndex( + name: "IX_ShopReinforcedies_ShopId", + table: "ShopReinforcedies", + column: "ShopId"); + } + + /// + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropTable( + name: "Orders"); + + migrationBuilder.DropTable( + name: "ReinforcedComponents"); + + migrationBuilder.DropTable( + name: "ShopReinforcedies"); + + migrationBuilder.DropTable( + name: "Components"); + + migrationBuilder.DropTable( + name: "Reinforcedies"); + + migrationBuilder.DropTable( + name: "Shops"); + } + } +} diff --git a/PrecastConcretePlant/PrecastConcretePlantDatabaseImplement/Migrations/PrecastConcretePlantDataBaseModelSnapshot.cs b/PrecastConcretePlant/PrecastConcretePlantDatabaseImplement/Migrations/PrecastConcretePlantDataBaseModelSnapshot.cs new file mode 100644 index 0000000..1f2e84a --- /dev/null +++ b/PrecastConcretePlant/PrecastConcretePlantDatabaseImplement/Migrations/PrecastConcretePlantDataBaseModelSnapshot.cs @@ -0,0 +1,249 @@ +// +using System; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Metadata; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; +using PrecastConcretePlantDatabaseImplement; + +#nullable disable + +namespace PrecastConcretePlantDatabaseImplement.Migrations +{ + [DbContext(typeof(PrecastConcretePlantDataBase))] + partial class PrecastConcretePlantDataBaseModelSnapshot : 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("PrecastConcretePlantDatabaseImplement.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("PrecastConcretePlantDatabaseImplement.Models.Order", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("Count") + .HasColumnType("int"); + + b.Property("DateCreate") + .HasColumnType("datetime2"); + + b.Property("DateImplement") + .HasColumnType("datetime2"); + + b.Property("ReinforcedId") + .HasColumnType("int"); + + b.Property("ReinforcedName") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Status") + .HasColumnType("int"); + + b.Property("Sum") + .HasColumnType("float"); + + b.HasKey("Id"); + + b.HasIndex("ReinforcedId"); + + b.ToTable("Orders"); + }); + + modelBuilder.Entity("PrecastConcretePlantDatabaseImplement.Models.Reinforced", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("Price") + .HasColumnType("float"); + + b.Property("ReinforcedName") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.HasKey("Id"); + + b.ToTable("Reinforcedies"); + }); + + modelBuilder.Entity("PrecastConcretePlantDatabaseImplement.Models.ReinforcedComponent", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("ComponentId") + .HasColumnType("int"); + + b.Property("Count") + .HasColumnType("int"); + + b.Property("ReinforcedId") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.HasIndex("ComponentId"); + + b.HasIndex("ReinforcedId"); + + b.ToTable("ReinforcedComponents"); + }); + + modelBuilder.Entity("PrecastConcretePlantDatabaseImplement.Models.Shop", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("Address") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("DateOpening") + .HasColumnType("datetime2"); + + b.Property("Name") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("ReinforcedMaxCount") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.ToTable("Shops"); + }); + + modelBuilder.Entity("PrecastConcretePlantDatabaseImplement.Models.ShopReinforced", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("Count") + .HasColumnType("int"); + + b.Property("ReinforcedId") + .HasColumnType("int"); + + b.Property("ShopId") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.HasIndex("ReinforcedId"); + + b.HasIndex("ShopId"); + + b.ToTable("ShopReinforcedies"); + }); + + modelBuilder.Entity("PrecastConcretePlantDatabaseImplement.Models.Order", b => + { + b.HasOne("PrecastConcretePlantDatabaseImplement.Models.Reinforced", "Reinforced") + .WithMany("Orders") + .HasForeignKey("ReinforcedId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Reinforced"); + }); + + modelBuilder.Entity("PrecastConcretePlantDatabaseImplement.Models.ReinforcedComponent", b => + { + b.HasOne("PrecastConcretePlantDatabaseImplement.Models.Component", "Component") + .WithMany("ReinforcedComponents") + .HasForeignKey("ComponentId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("PrecastConcretePlantDatabaseImplement.Models.Reinforced", "Reinforced") + .WithMany("Components") + .HasForeignKey("ReinforcedId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Component"); + + b.Navigation("Reinforced"); + }); + + modelBuilder.Entity("PrecastConcretePlantDatabaseImplement.Models.ShopReinforced", b => + { + b.HasOne("PrecastConcretePlantDatabaseImplement.Models.Reinforced", "Reinforced") + .WithMany() + .HasForeignKey("ReinforcedId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("PrecastConcretePlantDatabaseImplement.Models.Shop", "Shop") + .WithMany("Reinforcedies") + .HasForeignKey("ShopId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Reinforced"); + + b.Navigation("Shop"); + }); + + modelBuilder.Entity("PrecastConcretePlantDatabaseImplement.Models.Component", b => + { + b.Navigation("ReinforcedComponents"); + }); + + modelBuilder.Entity("PrecastConcretePlantDatabaseImplement.Models.Reinforced", b => + { + b.Navigation("Components"); + + b.Navigation("Orders"); + }); + + modelBuilder.Entity("PrecastConcretePlantDatabaseImplement.Models.Shop", b => + { + b.Navigation("Reinforcedies"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/PrecastConcretePlant/PrecastConcretePlantDatabaseImplement/Models/Shop.cs b/PrecastConcretePlant/PrecastConcretePlantDatabaseImplement/Models/Shop.cs index a551341..4b737e8 100644 --- a/PrecastConcretePlant/PrecastConcretePlantDatabaseImplement/Models/Shop.cs +++ b/PrecastConcretePlant/PrecastConcretePlantDatabaseImplement/Models/Shop.cs @@ -15,7 +15,7 @@ namespace PrecastConcretePlantDatabaseImplement.Models { public int Id { get; set; } [Required] - public string ShopName { get; set; } = string.Empty; + public string Name { get; set; } = string.Empty; [Required] public string Address { get; set; } = string.Empty; [Required] @@ -44,7 +44,7 @@ namespace PrecastConcretePlantDatabaseImplement.Models return new Shop() { Id = model.Id, - ShopName = model.ShopName, + Name = model.Name, Address = model.Address, DateOpening = model.DateOpening, ReinforcedMaxCount = model.ReinforcedMaxCount, @@ -58,7 +58,7 @@ namespace PrecastConcretePlantDatabaseImplement.Models public void Update(ShopBindingModel model) { - ShopName = model.ShopName; + Name = model.Name; Address = model.Address; DateOpening = model.DateOpening; ReinforcedMaxCount = model.ReinforcedMaxCount; @@ -67,7 +67,7 @@ namespace PrecastConcretePlantDatabaseImplement.Models public ShopViewModel GetViewModel => new() { Id = Id, - ShopName = ShopName, + Name = Name, Address = Address, DateOpening = DateOpening, ReinforcedMaxCount = ReinforcedMaxCount, diff --git a/PrecastConcretePlant/PrecastConcretePlantDatabaseImplement/PrecastConcretePlantDataBase.cs b/PrecastConcretePlant/PrecastConcretePlantDatabaseImplement/PrecastConcretePlantDataBase.cs index 7403d77..320c1e6 100644 --- a/PrecastConcretePlant/PrecastConcretePlantDatabaseImplement/PrecastConcretePlantDataBase.cs +++ b/PrecastConcretePlant/PrecastConcretePlantDatabaseImplement/PrecastConcretePlantDataBase.cs @@ -14,7 +14,7 @@ namespace PrecastConcretePlantDatabaseImplement { if (optionsBuilder.IsConfigured == false) { - optionsBuilder.UseSqlServer(@"Data Source=MAKSIM\SQLEXPRESS;Initial Catalog=PrecastConcretePlantDataBaseFull;Integrated Security=True;MultipleActiveResultSets=True;;TrustServerCertificate=True"); + optionsBuilder.UseSqlServer(@"Data Source=MAKSIM\SQLEXPRESS;Initial Catalog=PrecastConcretePlantDataBaseFullHard;Integrated Security=True;MultipleActiveResultSets=True;;TrustServerCertificate=True"); } base.OnConfiguring(optionsBuilder); } diff --git a/PrecastConcretePlant/PrecastConcretePlantFileImplement/Implements/ShopStorage.cs b/PrecastConcretePlant/PrecastConcretePlantFileImplement/Implements/ShopStorage.cs index 2a95924..19f21ac 100644 --- a/PrecastConcretePlant/PrecastConcretePlantFileImplement/Implements/ShopStorage.cs +++ b/PrecastConcretePlant/PrecastConcretePlantFileImplement/Implements/ShopStorage.cs @@ -34,22 +34,22 @@ namespace PrecastConcretePlantFileImplement.Implements public ShopViewModel? GetElement(ShopSearchModel model) { - if (string.IsNullOrEmpty(model.ShopName) && !model.Id.HasValue) + if (string.IsNullOrEmpty(model.Name) && !model.Id.HasValue) { return null; } return source.Shops.FirstOrDefault(x => - (!string.IsNullOrEmpty(model.ShopName) && x.ShopName == - model.ShopName) || (model.Id.HasValue && x.Id == model.Id))?.GetViewModel; + (!string.IsNullOrEmpty(model.Name) && x.Name == + model.Name) || (model.Id.HasValue && x.Id == model.Id))?.GetViewModel; } public List GetFilteredList(ShopSearchModel model) { - if (string.IsNullOrEmpty(model.ShopName)) + if (string.IsNullOrEmpty(model.Name)) { return new(); } - return source.Shops.Where(x => x.ShopName.Contains(model.ShopName)).Select(x => x.GetViewModel).ToList(); + return source.Shops.Where(x => x.Name.Contains(model.Name)).Select(x => x.GetViewModel).ToList(); } public List GetFullList() @@ -72,21 +72,21 @@ namespace PrecastConcretePlantFileImplement.Implements public bool SellReinforced(IReinforcedModel model, int quantity) { - if (source.Shops.Select(x => x.Reinforcedies.FirstOrDefault(y => y.Key == model.Id).Value.Item2).Sum() < quantity) + if (source.Shops.Select(x => x.ShopReinforcedies.FirstOrDefault(y => y.Key == model.Id).Value.Item2).Sum() < quantity) { return false; } - foreach (var shop in source.Shops.Where(x => x.Reinforcedies.ContainsKey(model.Id))) + foreach (var shop in source.Shops.Where(x => x.ShopReinforcedies.ContainsKey(model.Id))) { - int QuantityInCurrentShop = shop.Reinforcedies[model.Id].Item2; + int QuantityInCurrentShop = shop.ShopReinforcedies[model.Id].Item2; if (QuantityInCurrentShop <= quantity) { - shop.Reinforcedies.Remove(model.Id); + shop.ShopReinforcedies.Remove(model.Id); quantity -= QuantityInCurrentShop; } else { - shop.Reinforcedies[model.Id] = (shop.Reinforcedies[model.Id].Item1, QuantityInCurrentShop - quantity); + shop.ShopReinforcedies[model.Id] = (shop.ShopReinforcedies[model.Id].Item1, QuantityInCurrentShop - quantity); quantity = 0; } if (quantity == 0) diff --git a/PrecastConcretePlant/PrecastConcretePlantFileImplement/Models/Shop.cs b/PrecastConcretePlant/PrecastConcretePlantFileImplement/Models/Shop.cs index b39ab4e..d262c11 100644 --- a/PrecastConcretePlant/PrecastConcretePlantFileImplement/Models/Shop.cs +++ b/PrecastConcretePlant/PrecastConcretePlantFileImplement/Models/Shop.cs @@ -12,7 +12,7 @@ namespace PrecastConcretePlantFileImplement.Models { public class Shop : IShopModel { - public string ShopName { get; private set; } = string.Empty; + public string Name { get; private set; } = string.Empty; public string Address { get; private set; } = string.Empty; public DateTime DateOpening { get; private set; } @@ -45,7 +45,7 @@ namespace PrecastConcretePlantFileImplement.Models return new Shop() { Id = model.Id, - ShopName = model.ShopName, + Name = model.Name, Address = model.Address, ReinforcedMaxCount = model.ReinforcedMaxCount, DateOpening = model.DateOpening, @@ -61,7 +61,7 @@ namespace PrecastConcretePlantFileImplement.Models return new() { Id = Convert.ToInt32(element.Attribute("Id")!.Value), - ShopName = element.Element("Name")!.Value, + Name = element.Element("Name")!.Value, Address = element.Element("Address")!.Value, DateOpening = Convert.ToDateTime(element.Element("DateOpening")!.Value), ReinforcedMaxCount = Convert.ToInt32(element.Element("ReinforcedMaxCount")!.Value), @@ -76,7 +76,7 @@ namespace PrecastConcretePlantFileImplement.Models { return; } - ShopName = model.ShopName; + Name = model.Name; Address = model.Address; DateOpening = model.DateOpening; ReinforcedMaxCount = model.ReinforcedMaxCount; @@ -86,15 +86,15 @@ namespace PrecastConcretePlantFileImplement.Models public ShopViewModel GetViewModel => new() { Id = Id, - ShopName = ShopName, + Name = Name, Address = Address, - ShopReinforcedies = Reinforcedies, + ShopReinforcedies = ShopReinforcedies, DateOpening = DateOpening, ReinforcedMaxCount = ReinforcedMaxCount, }; public XElement GetXElement => new("Shop", new XAttribute("Id", Id), - new XElement("Name", ShopName), + new XElement("Name", Name), new XElement("Address", Address), new XElement("DateOpening", DateOpening), new XElement("ReinforcedMaxCount", ReinforcedMaxCount), diff --git a/PrecastConcretePlant/PrecastConcretePlantListImplement/Implements/ShopStorage.cs b/PrecastConcretePlant/PrecastConcretePlantListImplement/Implements/ShopStorage.cs index cdd8b15..5a8cbb5 100644 --- a/PrecastConcretePlant/PrecastConcretePlantListImplement/Implements/ShopStorage.cs +++ b/PrecastConcretePlant/PrecastConcretePlantListImplement/Implements/ShopStorage.cs @@ -39,14 +39,14 @@ namespace PrecastConcretePlantListImplement.Implements } public ShopViewModel? GetElement(ShopSearchModel model) { - if (string.IsNullOrEmpty(model.ShopName) && !model.Id.HasValue) + if (string.IsNullOrEmpty(model.Name) && !model.Id.HasValue) { return null; } foreach (var shop in _source.Shops) { - if ((!string.IsNullOrEmpty(model.ShopName) && - shop.ShopName == model.ShopName) || + if ((!string.IsNullOrEmpty(model.Name) && + shop.Name == model.Name) || (model.Id.HasValue && shop.Id == model.Id)) { return shop.GetViewModel; @@ -58,13 +58,13 @@ namespace PrecastConcretePlantListImplement.Implements public List GetFilteredList(ShopSearchModel model) { var result = new List(); - if (string.IsNullOrEmpty(model.ShopName)) + if (string.IsNullOrEmpty(model.Name)) { return result; } foreach (var shop in _source.Shops) { - if (shop.ShopName.Contains(model.ShopName ?? string.Empty)) + if (shop.Name.Contains(model.Name ?? string.Empty)) { result.Add(shop.GetViewModel); } diff --git a/PrecastConcretePlant/PrecastConcretePlantListImplement/Models/Shop.cs b/PrecastConcretePlant/PrecastConcretePlantListImplement/Models/Shop.cs index a1fb8e0..a8895f2 100644 --- a/PrecastConcretePlant/PrecastConcretePlantListImplement/Models/Shop.cs +++ b/PrecastConcretePlant/PrecastConcretePlantListImplement/Models/Shop.cs @@ -11,7 +11,7 @@ namespace PrecastConcretePlantListImplement.Models { public class Shop : IShopModel { - public string ShopName { get; private set; } = string.Empty; + public string Name { get; private set; } = string.Empty; public string Address { get; private set; } = string.Empty; @@ -30,7 +30,7 @@ namespace PrecastConcretePlantListImplement.Models return new Shop() { Id = model.Id, - ShopName = model.ShopName, + Name = model.Name, Address = model.Address, DateOpening = model.DateOpening, ShopReinforcedies = new() @@ -42,7 +42,7 @@ namespace PrecastConcretePlantListImplement.Models { return; } - ShopName = model.ShopName; + Name = model.Name; Address = model.Address; DateOpening = model.DateOpening; ShopReinforcedies = model.ShopReinforcedies; @@ -50,7 +50,7 @@ namespace PrecastConcretePlantListImplement.Models public ShopViewModel GetViewModel => new() { Id = Id, - ShopName = ShopName, + Name = Name, Address = Address, ShopReinforcedies = ShopReinforcedies, DateOpening = DateOpening,