Очень странный фикс. Миграций не работали из за FileImplements и еще какой то прикол с формами

This commit is contained in:
Кашин Максим 2023-04-09 19:05:11 +04:00
parent ff8c9169cb
commit d8c56a9723
22 changed files with 747 additions and 61 deletions

View File

@ -1,4 +1,4 @@
using ConfectioneryView;

using Microsoft.Extensions.Logging;
using PrecastConcretePlantContracts.BindingModels;
using PrecastConcretePlantContracts.BusinessLogicsContracts;

View File

@ -1,4 +1,4 @@
namespace ConfectioneryView
namespace PrecastConcretePlantView
{
partial class FormReinforcedShop
{

View File

@ -12,7 +12,7 @@ using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace ConfectioneryView
namespace PrecastConcretePlantView
{
public partial class FormReinforcedShop : Form
{

View File

@ -1,4 +1,4 @@
namespace ConfectioneryView
namespace PrecastConcretePlantView
{
partial class FormShop
{

View File

@ -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;

View File

@ -1,4 +1,4 @@
namespace ConfectioneryView
namespace PrecastConcretePlantView
{
partial class FormShops
{

View File

@ -3,7 +3,7 @@ using PrecastConcretePlantContracts.BindingModels;
using PrecastConcretePlantContracts.BusinessLogicsContracts;
using PrecastConcretePlantView;
namespace ConfectioneryView
namespace PrecastConcretePlantView
{
public partial class FormShops : Form
{

View File

@ -26,7 +26,7 @@ namespace PrecastConcretePlantBusinessLogic.BusinessLogic
public List<ShopViewModel>? 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,

View File

@ -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; }

View File

@ -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; }
}
}

View File

@ -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;

View File

@ -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; }

View File

@ -28,7 +28,7 @@ namespace PrecastConcretePlantDatabaseImplement.Implements
public List<ShopViewModel> 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;
}

View File

@ -0,0 +1,252 @@
// <auto-generated />
using System;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Metadata;
using Microsoft.EntityFrameworkCore.Migrations;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
using PrecastConcretePlantDatabaseImplement;
#nullable disable
namespace PrecastConcretePlantDatabaseImplement.Migrations
{
[DbContext(typeof(PrecastConcretePlantDataBase))]
[Migration("20230409150055_FirstMigr")]
partial class FirstMigr
{
/// <inheritdoc />
protected override void BuildTargetModel(ModelBuilder modelBuilder)
{
#pragma warning disable 612, 618
modelBuilder
.HasAnnotation("ProductVersion", "7.0.3")
.HasAnnotation("Relational:MaxIdentifierLength", 128);
SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder);
modelBuilder.Entity("PrecastConcretePlantDatabaseImplement.Models.Component", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<string>("ComponentName")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<double>("Cost")
.HasColumnType("float");
b.HasKey("Id");
b.ToTable("Components");
});
modelBuilder.Entity("PrecastConcretePlantDatabaseImplement.Models.Order", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<int>("Count")
.HasColumnType("int");
b.Property<DateTime>("DateCreate")
.HasColumnType("datetime2");
b.Property<DateTime?>("DateImplement")
.HasColumnType("datetime2");
b.Property<int>("ReinforcedId")
.HasColumnType("int");
b.Property<string>("ReinforcedName")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<int>("Status")
.HasColumnType("int");
b.Property<double>("Sum")
.HasColumnType("float");
b.HasKey("Id");
b.HasIndex("ReinforcedId");
b.ToTable("Orders");
});
modelBuilder.Entity("PrecastConcretePlantDatabaseImplement.Models.Reinforced", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<double>("Price")
.HasColumnType("float");
b.Property<string>("ReinforcedName")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.HasKey("Id");
b.ToTable("Reinforcedies");
});
modelBuilder.Entity("PrecastConcretePlantDatabaseImplement.Models.ReinforcedComponent", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<int>("ComponentId")
.HasColumnType("int");
b.Property<int>("Count")
.HasColumnType("int");
b.Property<int>("ReinforcedId")
.HasColumnType("int");
b.HasKey("Id");
b.HasIndex("ComponentId");
b.HasIndex("ReinforcedId");
b.ToTable("ReinforcedComponents");
});
modelBuilder.Entity("PrecastConcretePlantDatabaseImplement.Models.Shop", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<string>("Address")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<DateTime>("DateOpening")
.HasColumnType("datetime2");
b.Property<string>("Name")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<int>("ReinforcedMaxCount")
.HasColumnType("int");
b.HasKey("Id");
b.ToTable("Shops");
});
modelBuilder.Entity("PrecastConcretePlantDatabaseImplement.Models.ShopReinforced", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<int>("Count")
.HasColumnType("int");
b.Property<int>("ReinforcedId")
.HasColumnType("int");
b.Property<int>("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
}
}
}

View File

@ -0,0 +1,185 @@
using System;
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace PrecastConcretePlantDatabaseImplement.Migrations
{
/// <inheritdoc />
public partial class FirstMigr : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.CreateTable(
name: "Components",
columns: table => new
{
Id = table.Column<int>(type: "int", nullable: false)
.Annotation("SqlServer:Identity", "1, 1"),
ComponentName = table.Column<string>(type: "nvarchar(max)", nullable: false),
Cost = table.Column<double>(type: "float", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Components", x => x.Id);
});
migrationBuilder.CreateTable(
name: "Reinforcedies",
columns: table => new
{
Id = table.Column<int>(type: "int", nullable: false)
.Annotation("SqlServer:Identity", "1, 1"),
ReinforcedName = table.Column<string>(type: "nvarchar(max)", nullable: false),
Price = table.Column<double>(type: "float", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Reinforcedies", x => x.Id);
});
migrationBuilder.CreateTable(
name: "Shops",
columns: table => new
{
Id = table.Column<int>(type: "int", nullable: false)
.Annotation("SqlServer:Identity", "1, 1"),
Name = table.Column<string>(type: "nvarchar(max)", nullable: false),
Address = table.Column<string>(type: "nvarchar(max)", nullable: false),
DateOpening = table.Column<DateTime>(type: "datetime2", nullable: false),
ReinforcedMaxCount = table.Column<int>(type: "int", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Shops", x => x.Id);
});
migrationBuilder.CreateTable(
name: "Orders",
columns: table => new
{
Id = table.Column<int>(type: "int", nullable: false)
.Annotation("SqlServer:Identity", "1, 1"),
ReinforcedId = table.Column<int>(type: "int", nullable: false),
ReinforcedName = table.Column<string>(type: "nvarchar(max)", nullable: false),
Count = table.Column<int>(type: "int", nullable: false),
Sum = table.Column<double>(type: "float", nullable: false),
Status = table.Column<int>(type: "int", nullable: false),
DateCreate = table.Column<DateTime>(type: "datetime2", nullable: false),
DateImplement = table.Column<DateTime>(type: "datetime2", nullable: true)
},
constraints: table =>
{
table.PrimaryKey("PK_Orders", x => x.Id);
table.ForeignKey(
name: "FK_Orders_Reinforcedies_ReinforcedId",
column: x => x.ReinforcedId,
principalTable: "Reinforcedies",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateTable(
name: "ReinforcedComponents",
columns: table => new
{
Id = table.Column<int>(type: "int", nullable: false)
.Annotation("SqlServer:Identity", "1, 1"),
ReinforcedId = table.Column<int>(type: "int", nullable: false),
ComponentId = table.Column<int>(type: "int", nullable: false),
Count = table.Column<int>(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<int>(type: "int", nullable: false)
.Annotation("SqlServer:Identity", "1, 1"),
ReinforcedId = table.Column<int>(type: "int", nullable: false),
ShopId = table.Column<int>(type: "int", nullable: false),
Count = table.Column<int>(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");
}
/// <inheritdoc />
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");
}
}
}

View File

@ -0,0 +1,249 @@
// <auto-generated />
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<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<string>("ComponentName")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<double>("Cost")
.HasColumnType("float");
b.HasKey("Id");
b.ToTable("Components");
});
modelBuilder.Entity("PrecastConcretePlantDatabaseImplement.Models.Order", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<int>("Count")
.HasColumnType("int");
b.Property<DateTime>("DateCreate")
.HasColumnType("datetime2");
b.Property<DateTime?>("DateImplement")
.HasColumnType("datetime2");
b.Property<int>("ReinforcedId")
.HasColumnType("int");
b.Property<string>("ReinforcedName")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<int>("Status")
.HasColumnType("int");
b.Property<double>("Sum")
.HasColumnType("float");
b.HasKey("Id");
b.HasIndex("ReinforcedId");
b.ToTable("Orders");
});
modelBuilder.Entity("PrecastConcretePlantDatabaseImplement.Models.Reinforced", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<double>("Price")
.HasColumnType("float");
b.Property<string>("ReinforcedName")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.HasKey("Id");
b.ToTable("Reinforcedies");
});
modelBuilder.Entity("PrecastConcretePlantDatabaseImplement.Models.ReinforcedComponent", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<int>("ComponentId")
.HasColumnType("int");
b.Property<int>("Count")
.HasColumnType("int");
b.Property<int>("ReinforcedId")
.HasColumnType("int");
b.HasKey("Id");
b.HasIndex("ComponentId");
b.HasIndex("ReinforcedId");
b.ToTable("ReinforcedComponents");
});
modelBuilder.Entity("PrecastConcretePlantDatabaseImplement.Models.Shop", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<string>("Address")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<DateTime>("DateOpening")
.HasColumnType("datetime2");
b.Property<string>("Name")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<int>("ReinforcedMaxCount")
.HasColumnType("int");
b.HasKey("Id");
b.ToTable("Shops");
});
modelBuilder.Entity("PrecastConcretePlantDatabaseImplement.Models.ShopReinforced", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<int>("Count")
.HasColumnType("int");
b.Property<int>("ReinforcedId")
.HasColumnType("int");
b.Property<int>("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
}
}
}

View File

@ -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,

View File

@ -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);
}

View File

@ -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<ShopViewModel> 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<ShopViewModel> 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)

View File

@ -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),

View File

@ -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<ShopViewModel> GetFilteredList(ShopSearchModel model)
{
var result = new List<ShopViewModel>();
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);
}

View File

@ -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,