From e948a1c60f261181e64cb6bd942dd013fde3deae Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9D=D0=B8=D0=BA=D0=BE=D0=BB=D0=B0=D0=B9?= Date: Sat, 1 Apr 2023 16:27:37 +0400 Subject: [PATCH 1/4] =?UTF-8?q?=D1=80=D0=B5=D0=B0=D0=BB=D0=B8=D0=B7=D0=BE?= =?UTF-8?q?=D0=B2=D0=B0=D0=BD=D0=BD=D1=8B=20=D0=B2=D1=81=D0=B5=20=D0=BC?= =?UTF-8?q?=D0=BE=D0=B4=D0=B5=D0=BB=D0=B8=20=D0=91=D0=94=20=20=D0=B4=D0=BB?= =?UTF-8?q?=D1=8F=20=D1=81=D1=83=D1=89=D0=BD=D0=BE=D1=81=D1=82=D0=B8=20?= =?UTF-8?q?=D0=A0=D0=B0=D0=B1=D0=BE=D1=82=D0=BD=D0=B8=D0=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../HardwareShopDatabase.cs | 2 +- .../Models/Purchase.cs | 140 ++++++++++++++++-- 2 files changed, 131 insertions(+), 11 deletions(-) diff --git a/HardwareShop/HardwareShopDatabaseImplement/HardwareShopDatabase.cs b/HardwareShop/HardwareShopDatabaseImplement/HardwareShopDatabase.cs index ef5e47a..2bbe3d7 100644 --- a/HardwareShop/HardwareShopDatabaseImplement/HardwareShopDatabase.cs +++ b/HardwareShop/HardwareShopDatabaseImplement/HardwareShopDatabase.cs @@ -33,7 +33,7 @@ namespace HardwareShopDatabaseImplement public virtual DbSet Orders { set; get; } - public virtual DbSet Purchase { set; get; } + public virtual DbSet Purchases { set; get; } public virtual DbSet PurchasesBuilds { set; get; } diff --git a/HardwareShop/HardwareShopDatabaseImplement/Models/Purchase.cs b/HardwareShop/HardwareShopDatabaseImplement/Models/Purchase.cs index 890a348..0a35865 100644 --- a/HardwareShop/HardwareShopDatabaseImplement/Models/Purchase.cs +++ b/HardwareShop/HardwareShopDatabaseImplement/Models/Purchase.cs @@ -1,8 +1,9 @@ -using HardwareShopDataModels.Enums; +using HardwareShopContracts.BindingModels; +using HardwareShopContracts.ViewModels; +using HardwareShopDataModels.Enums; using HardwareShopDataModels.Models; -using HardwareShopDataModels.Models; -using System.ComponentModel; using System.ComponentModel.DataAnnotations.Schema; +using System.Diagnostics; namespace HardwareShopDatabaseImplement.Models { @@ -20,18 +21,137 @@ namespace HardwareShopDatabaseImplement.Models public virtual User User { get; set; } - [NotMapped] - public Dictionary? PurchaseBuilds { get; set; } - - [NotMapped] - public Dictionary PurchaseGoods { get; set; } = new(); - - [ForeignKey("PurchaseId")] public virtual List? Builds { get; set; } + public Dictionary? _purchaseBuilds = null; + + [NotMapped] + public Dictionary? PurchaseBuilds + { + get + { + if (_purchaseBuilds == null) + { + _purchaseBuilds = Builds.ToDictionary(recPB => recPB.BuildID, recPB => (recPB.Build as IBuildModel, recPB.Count)); + } + return _purchaseBuilds; + } + } + [ForeignKey("PurchaseId")] public virtual List Goods { get; set; } = new(); + public Dictionary? _purchaseGoods = null; + [NotMapped] + public Dictionary? PurchaseGoods + { + get + { + if (_purchaseGoods == null) + { + _purchaseGoods = Goods.ToDictionary(recPG => recPG.GoodID, recPG => (recPG.Good as IGoodModel, recPG.Count)); + } + return _purchaseGoods; + } + } + + public static Purchase Create(HardwareShopDatabase context, PurchaseBindingModel model) + { + return new Purchase() + { + Id = model.Id, + Sum = model.Sum, + PurchaseStatus = model.PurchaseStatus, + DatePurchase = model.DatePurchase, + UserID = model.UserID, + Builds = model.PurchaseBuilds.Select(x => new PurchaseBuild + { + Build = context.Builds.First(y => y.Id == x.Key), + Count = x.Value.Item2 + }).ToList(), + Goods = model.PurchaseGoods.Select(x => new PurchaseGood + { + Good = context.Goods.First(y => y.Id == x.Key), + Count = x.Value.Item2 + }).ToList() + }; + } + + public void Update(PurchaseBindingModel model) + { + PurchaseStatus = model.PurchaseStatus; + DatePurchase = model.DatePurchase; + } + + public PurchaseViewModel GetViewModel => new() + { + Id = Id, + Sum = Sum, + PurchaseStatus = PurchaseStatus, + DatePurchase = DatePurchase, + UserID = UserID, + UserEmail = User.Email, + PurchaseBuilds = PurchaseBuilds, + PurchaseGoods = PurchaseGoods + }; + + public void UpdateBuilds(HardwareShopDatabase context, PurchaseBindingModel model) + { + var purchaseBuilds = context.PurchasesBuilds.Where(rec => rec.PurchaseID == model.Id).ToList(); + if (purchaseBuilds != null && purchaseBuilds.Count > 0) + { + context.PurchasesBuilds.RemoveRange(purchaseBuilds.Where(rec => !model.PurchaseBuilds.ContainsKey(rec.BuildID))); + context.SaveChanges(); + foreach (var updateBuild in purchaseBuilds) + { + updateBuild.Count = model.PurchaseBuilds[updateBuild.BuildID].Item2; + model.PurchaseBuilds.Remove(updateBuild.BuildID); + } + context.SaveChanges(); + } + var purchase = context.Purchases.First(x => x.Id == Id); + foreach (var dc in model.PurchaseBuilds) + { + context.PurchasesBuilds.Add(new PurchaseBuild + { + Purchase = purchase, + Build = context.Builds.First(x => x.Id == dc.Key), + Count = dc.Value.Item2 + }); + context.SaveChanges(); + } + _purchaseBuilds = null; + } + + public void UpdateGoods(HardwareShopDatabase context, PurchaseBindingModel model) + { + var purchaseGoods = context.PurchasesGoods.Where(rec => rec.PurchaseID == model.Id).ToList(); + if (purchaseGoods != null && purchaseGoods.Count > 0) + { // удалили те в бд, которых нет в модели + context.PurchasesGoods.RemoveRange(purchaseGoods.Where(rec => !model.PurchaseGoods.ContainsKey(rec.GoodID))); + context.SaveChanges(); + // обновили количество у существующих записей + foreach (var updateGood in purchaseGoods) + { + updateGood.Count = model.PurchaseGoods[updateGood.GoodID].Item2; + model.PurchaseGoods.Remove(updateGood.GoodID); + } + context.SaveChanges(); + } + var purchase = context.Purchases.First(x => x.Id == Id); + //добавляем в бд блюда которые есть в моделе, но ещё нет в бд + foreach (var dc in model.PurchaseGoods) + { + context.PurchasesGoods.Add(new PurchaseGood + { + Purchase = purchase, + Good = context.Goods.First(x => x.Id == dc.Key), + Count = dc.Value.Item2 + }); + context.SaveChanges(); + } + _purchaseGoods = null; + } } } From 98151dc3939d26245d96d3bb328948c381585a02 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9D=D0=B8=D0=BA=D0=BE=D0=BB=D0=B0=D0=B9?= Date: Sat, 1 Apr 2023 16:33:26 +0400 Subject: [PATCH 2/4] =?UTF-8?q?=D0=A3=D0=B4=D0=BE=D0=B1=D0=BD=D0=BE=D0=B5?= =?UTF-8?q?=20=D1=80=D0=B0=D0=B7=D0=BC=D0=B5=D1=89=D0=B5=D0=BD=D0=B8=D0=B5?= =?UTF-8?q?=20=D0=BF=D0=BE=20=D0=BF=D0=B0=D0=BF=D0=BA=D0=B0=D0=BC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../HardwareShopDatabaseImplement/HardwareShopDatabase.cs | 2 ++ .../HardwareShopDatabaseImplement.csproj | 4 ++++ .../Models/{ => ModelsManyToMany}/BuildComponent.cs | 3 ++- .../Models/{ => ModelsManyToMany}/PurchaseBuild.cs | 2 +- .../Models/{ => ModelsManyToMany}/PurchaseGood.cs | 3 ++- .../Models/{ => ModelsStorekeeper}/Component.cs | 2 +- .../Models/{ => ModelsStorekeeper}/Good.cs | 2 +- .../Models/{ => ModelsStorekeeper}/Order.cs | 2 +- .../Models/{ => ModelsWorker}/Build.cs | 4 ++-- .../Models/{ => ModelsWorker}/Comment.cs | 2 +- .../Models/{ => ModelsWorker}/Purchase.cs | 3 ++- 11 files changed, 19 insertions(+), 10 deletions(-) rename HardwareShop/HardwareShopDatabaseImplement/Models/{ => ModelsManyToMany}/BuildComponent.cs (81%) rename HardwareShop/HardwareShopDatabaseImplement/Models/{ => ModelsManyToMany}/PurchaseBuild.cs (89%) rename HardwareShop/HardwareShopDatabaseImplement/Models/{ => ModelsManyToMany}/PurchaseGood.cs (80%) rename HardwareShop/HardwareShopDatabaseImplement/Models/{ => ModelsStorekeeper}/Component.cs (82%) rename HardwareShop/HardwareShopDatabaseImplement/Models/{ => ModelsStorekeeper}/Good.cs (83%) rename HardwareShop/HardwareShopDatabaseImplement/Models/{ => ModelsStorekeeper}/Order.cs (81%) rename HardwareShop/HardwareShopDatabaseImplement/Models/{ => ModelsWorker}/Build.cs (97%) rename HardwareShop/HardwareShopDatabaseImplement/Models/{ => ModelsWorker}/Comment.cs (95%) rename HardwareShop/HardwareShopDatabaseImplement/Models/{ => ModelsWorker}/Purchase.cs (98%) diff --git a/HardwareShop/HardwareShopDatabaseImplement/HardwareShopDatabase.cs b/HardwareShop/HardwareShopDatabaseImplement/HardwareShopDatabase.cs index 2bbe3d7..648429e 100644 --- a/HardwareShop/HardwareShopDatabaseImplement/HardwareShopDatabase.cs +++ b/HardwareShop/HardwareShopDatabaseImplement/HardwareShopDatabase.cs @@ -1,4 +1,6 @@ using HardwareShopDatabaseImplement.Models; +using HardwareShopDatabaseImplement.Models.ModelsManyToMany; +using HardwareShopDatabaseImplement.Models.ModelsStorekeeper; using Microsoft.EntityFrameworkCore; namespace HardwareShopDatabaseImplement diff --git a/HardwareShop/HardwareShopDatabaseImplement/HardwareShopDatabaseImplement.csproj b/HardwareShop/HardwareShopDatabaseImplement/HardwareShopDatabaseImplement.csproj index 841ba20..47df5db 100644 --- a/HardwareShop/HardwareShopDatabaseImplement/HardwareShopDatabaseImplement.csproj +++ b/HardwareShop/HardwareShopDatabaseImplement/HardwareShopDatabaseImplement.csproj @@ -20,4 +20,8 @@ + + + + diff --git a/HardwareShop/HardwareShopDatabaseImplement/Models/BuildComponent.cs b/HardwareShop/HardwareShopDatabaseImplement/Models/ModelsManyToMany/BuildComponent.cs similarity index 81% rename from HardwareShop/HardwareShopDatabaseImplement/Models/BuildComponent.cs rename to HardwareShop/HardwareShopDatabaseImplement/Models/ModelsManyToMany/BuildComponent.cs index e0dc8e5..5543221 100644 --- a/HardwareShop/HardwareShopDatabaseImplement/Models/BuildComponent.cs +++ b/HardwareShop/HardwareShopDatabaseImplement/Models/ModelsManyToMany/BuildComponent.cs @@ -5,8 +5,9 @@ using System.ComponentModel.DataAnnotations.Schema; using System.Linq; using System.Text; using System.Threading.Tasks; +using HardwareShopDatabaseImplement.Models.ModelsStorekeeper; -namespace HardwareShopDatabaseImplement.Models +namespace HardwareShopDatabaseImplement.Models.ModelsManyToMany { public class BuildComponent { diff --git a/HardwareShop/HardwareShopDatabaseImplement/Models/PurchaseBuild.cs b/HardwareShop/HardwareShopDatabaseImplement/Models/ModelsManyToMany/PurchaseBuild.cs similarity index 89% rename from HardwareShop/HardwareShopDatabaseImplement/Models/PurchaseBuild.cs rename to HardwareShop/HardwareShopDatabaseImplement/Models/ModelsManyToMany/PurchaseBuild.cs index 8c27dac..11d128f 100644 --- a/HardwareShop/HardwareShopDatabaseImplement/Models/PurchaseBuild.cs +++ b/HardwareShop/HardwareShopDatabaseImplement/Models/ModelsManyToMany/PurchaseBuild.cs @@ -6,7 +6,7 @@ using System.Linq; using System.Text; using System.Threading.Tasks; -namespace HardwareShopDatabaseImplement.Models +namespace HardwareShopDatabaseImplement.Models.ModelsManyToMany { public class PurchaseBuild { diff --git a/HardwareShop/HardwareShopDatabaseImplement/Models/PurchaseGood.cs b/HardwareShop/HardwareShopDatabaseImplement/Models/ModelsManyToMany/PurchaseGood.cs similarity index 80% rename from HardwareShop/HardwareShopDatabaseImplement/Models/PurchaseGood.cs rename to HardwareShop/HardwareShopDatabaseImplement/Models/ModelsManyToMany/PurchaseGood.cs index e0c1f49..6a12faf 100644 --- a/HardwareShop/HardwareShopDatabaseImplement/Models/PurchaseGood.cs +++ b/HardwareShop/HardwareShopDatabaseImplement/Models/ModelsManyToMany/PurchaseGood.cs @@ -5,8 +5,9 @@ using System.ComponentModel.DataAnnotations.Schema; using System.Linq; using System.Text; using System.Threading.Tasks; +using HardwareShopDatabaseImplement.Models.ModelsStorekeeper; -namespace HardwareShopDatabaseImplement.Models +namespace HardwareShopDatabaseImplement.Models.ModelsManyToMany { public class PurchaseGood { diff --git a/HardwareShop/HardwareShopDatabaseImplement/Models/Component.cs b/HardwareShop/HardwareShopDatabaseImplement/Models/ModelsStorekeeper/Component.cs similarity index 82% rename from HardwareShop/HardwareShopDatabaseImplement/Models/Component.cs rename to HardwareShop/HardwareShopDatabaseImplement/Models/ModelsStorekeeper/Component.cs index c62f457..10cdb6b 100644 --- a/HardwareShop/HardwareShopDatabaseImplement/Models/Component.cs +++ b/HardwareShop/HardwareShopDatabaseImplement/Models/ModelsStorekeeper/Component.cs @@ -5,7 +5,7 @@ using System.Linq; using System.Text; using System.Threading.Tasks; -namespace HardwareShopDatabaseImplement.Models +namespace HardwareShopDatabaseImplement.Models.ModelsStorekeeper { public class Component : IComponentModel { diff --git a/HardwareShop/HardwareShopDatabaseImplement/Models/Good.cs b/HardwareShop/HardwareShopDatabaseImplement/Models/ModelsStorekeeper/Good.cs similarity index 83% rename from HardwareShop/HardwareShopDatabaseImplement/Models/Good.cs rename to HardwareShop/HardwareShopDatabaseImplement/Models/ModelsStorekeeper/Good.cs index 4de3950..2d6ee18 100644 --- a/HardwareShop/HardwareShopDatabaseImplement/Models/Good.cs +++ b/HardwareShop/HardwareShopDatabaseImplement/Models/ModelsStorekeeper/Good.cs @@ -6,7 +6,7 @@ using System.Linq; using System.Text; using System.Threading.Tasks; -namespace HardwareShopDatabaseImplement.Models +namespace HardwareShopDatabaseImplement.Models.ModelsStorekeeper { public class Good : IGoodModel { diff --git a/HardwareShop/HardwareShopDatabaseImplement/Models/Order.cs b/HardwareShop/HardwareShopDatabaseImplement/Models/ModelsStorekeeper/Order.cs similarity index 81% rename from HardwareShop/HardwareShopDatabaseImplement/Models/Order.cs rename to HardwareShop/HardwareShopDatabaseImplement/Models/ModelsStorekeeper/Order.cs index 1ee8524..48946a8 100644 --- a/HardwareShop/HardwareShopDatabaseImplement/Models/Order.cs +++ b/HardwareShop/HardwareShopDatabaseImplement/Models/ModelsStorekeeper/Order.cs @@ -2,7 +2,7 @@ using HardwareShopDataModels.Models; using HardwareShopDataModels.Models; using System.ComponentModel; -namespace HardwareShopDatabaseImplement.Models +namespace HardwareShopDatabaseImplement.Models.ModelsStorekeeper { public class Order : IOrderModel { diff --git a/HardwareShop/HardwareShopDatabaseImplement/Models/Build.cs b/HardwareShop/HardwareShopDatabaseImplement/Models/ModelsWorker/Build.cs similarity index 97% rename from HardwareShop/HardwareShopDatabaseImplement/Models/Build.cs rename to HardwareShop/HardwareShopDatabaseImplement/Models/ModelsWorker/Build.cs index 1f333b8..206657d 100644 --- a/HardwareShop/HardwareShopDatabaseImplement/Models/Build.cs +++ b/HardwareShop/HardwareShopDatabaseImplement/Models/ModelsWorker/Build.cs @@ -1,11 +1,11 @@ using HardwareShopContracts.BindingModels; using HardwareShopContracts.ViewModels; +using HardwareShopDatabaseImplement.Models.ModelsManyToMany; using HardwareShopDataModels.Models; -using System.ComponentModel; using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations.Schema; -namespace HardwareShopDatabaseImplement.Models +namespace HardwareShopDatabaseImplement.Models.ModelsWorker { public class Build : IBuildModel { diff --git a/HardwareShop/HardwareShopDatabaseImplement/Models/Comment.cs b/HardwareShop/HardwareShopDatabaseImplement/Models/ModelsWorker/Comment.cs similarity index 95% rename from HardwareShop/HardwareShopDatabaseImplement/Models/Comment.cs rename to HardwareShop/HardwareShopDatabaseImplement/Models/ModelsWorker/Comment.cs index d041dc3..36bbe96 100644 --- a/HardwareShop/HardwareShopDatabaseImplement/Models/Comment.cs +++ b/HardwareShop/HardwareShopDatabaseImplement/Models/ModelsWorker/Comment.cs @@ -4,7 +4,7 @@ using HardwareShopDataModels.Models; using System.ComponentModel; using System.ComponentModel.DataAnnotations; -namespace HardwareShopDatabaseImplement.Models +namespace HardwareShopDatabaseImplement.Models.ModelsWorker { public class Comment : ICommentModel { diff --git a/HardwareShop/HardwareShopDatabaseImplement/Models/Purchase.cs b/HardwareShop/HardwareShopDatabaseImplement/Models/ModelsWorker/Purchase.cs similarity index 98% rename from HardwareShop/HardwareShopDatabaseImplement/Models/Purchase.cs rename to HardwareShop/HardwareShopDatabaseImplement/Models/ModelsWorker/Purchase.cs index 0a35865..6263bcb 100644 --- a/HardwareShop/HardwareShopDatabaseImplement/Models/Purchase.cs +++ b/HardwareShop/HardwareShopDatabaseImplement/Models/ModelsWorker/Purchase.cs @@ -1,11 +1,12 @@ using HardwareShopContracts.BindingModels; using HardwareShopContracts.ViewModels; +using HardwareShopDatabaseImplement.Models.ModelsManyToMany; using HardwareShopDataModels.Enums; using HardwareShopDataModels.Models; using System.ComponentModel.DataAnnotations.Schema; using System.Diagnostics; -namespace HardwareShopDatabaseImplement.Models +namespace HardwareShopDatabaseImplement.Models.ModelsWorker { public class Purchase : IPurchaseModel { From bda574f0feb4a037384a43d94d9ffccce9cd7f4c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9D=D0=B8=D0=BA=D0=BE=D0=BB=D0=B0=D0=B9?= Date: Sat, 1 Apr 2023 16:34:06 +0400 Subject: [PATCH 3/4] rename --- .../BindingModels/BuildBindingModel.cs | 2 +- .../BindingModels/CommentBindingModel.cs | 2 +- .../BindingModels/PurchaseBindingModel.cs | 2 +- .../ViewModels/BuildViewModel.cs | 2 +- .../ViewModels/CommentViewModel.cs | 2 +- .../ViewModels/PurchaseViewModel.cs | 2 +- .../Models/IBuildModel.cs | 2 +- .../Models/ICommentModel.cs | 2 +- .../Models/IPurchaseModel.cs | 2 +- .../HardwareShopDatabase.cs | 6 +-- .../20230401103551_init.Designer.cs | 34 +++++++------- .../Migrations/20230401103551_init.cs | 46 +++++++++---------- .../HardwareShopDatabaseModelSnapshot.cs | 34 +++++++------- .../Models/ModelsManyToMany/BuildComponent.cs | 2 +- .../Models/ModelsManyToMany/PurchaseBuild.cs | 4 +- .../Models/ModelsManyToMany/PurchaseGood.cs | 4 +- 16 files changed, 74 insertions(+), 74 deletions(-) diff --git a/HardwareShop/HardwareShopContracts/BindingModels/BuildBindingModel.cs b/HardwareShop/HardwareShopContracts/BindingModels/BuildBindingModel.cs index 4ce382d..5726e43 100644 --- a/HardwareShop/HardwareShopContracts/BindingModels/BuildBindingModel.cs +++ b/HardwareShop/HardwareShopContracts/BindingModels/BuildBindingModel.cs @@ -11,7 +11,7 @@ namespace HardwareShopContracts.BindingModels public string BuildName { get; set; } = string.Empty; - public int UserID { get; set; } + public int UserId { get; set; } public Dictionary? BuildComponents { get; set; } } diff --git a/HardwareShop/HardwareShopContracts/BindingModels/CommentBindingModel.cs b/HardwareShop/HardwareShopContracts/BindingModels/CommentBindingModel.cs index 7f6175d..09991f9 100644 --- a/HardwareShop/HardwareShopContracts/BindingModels/CommentBindingModel.cs +++ b/HardwareShop/HardwareShopContracts/BindingModels/CommentBindingModel.cs @@ -10,6 +10,6 @@ namespace HardwareShopContracts.BindingModels public string Text { get; set; } = string.Empty; - public int BuildID { get; set; } + public int BuildId { get; set; } } } diff --git a/HardwareShop/HardwareShopContracts/BindingModels/PurchaseBindingModel.cs b/HardwareShop/HardwareShopContracts/BindingModels/PurchaseBindingModel.cs index c5ce128..378629c 100644 --- a/HardwareShop/HardwareShopContracts/BindingModels/PurchaseBindingModel.cs +++ b/HardwareShop/HardwareShopContracts/BindingModels/PurchaseBindingModel.cs @@ -14,7 +14,7 @@ namespace HardwareShopContracts.BindingModels public DateTime? DatePurchase { get; set; } - public int UserID { get; set; } + public int UserId { get; set; } public Dictionary? PurchaseBuilds { get; set; } diff --git a/HardwareShop/HardwareShopContracts/ViewModels/BuildViewModel.cs b/HardwareShop/HardwareShopContracts/ViewModels/BuildViewModel.cs index 186a85b..8dcd7c2 100644 --- a/HardwareShop/HardwareShopContracts/ViewModels/BuildViewModel.cs +++ b/HardwareShop/HardwareShopContracts/ViewModels/BuildViewModel.cs @@ -15,7 +15,7 @@ namespace HardwareShopContracts.ViewModels [DisplayName("Клиент")] public string UserEmail { get; set; } = string.Empty; - public int UserID { get; set; } + public int UserId { get; set; } public Dictionary? BuildComponents { get; set; } } diff --git a/HardwareShop/HardwareShopContracts/ViewModels/CommentViewModel.cs b/HardwareShop/HardwareShopContracts/ViewModels/CommentViewModel.cs index 04fce82..e6f9be8 100644 --- a/HardwareShop/HardwareShopContracts/ViewModels/CommentViewModel.cs +++ b/HardwareShop/HardwareShopContracts/ViewModels/CommentViewModel.cs @@ -13,6 +13,6 @@ namespace HardwareShopContracts.ViewModels [DisplayName("Название сборки")] public string BuildName { get; set; } = string.Empty; - public int BuildID { get; set; } + public int BuildId { get; set; } } } diff --git a/HardwareShop/HardwareShopContracts/ViewModels/PurchaseViewModel.cs b/HardwareShop/HardwareShopContracts/ViewModels/PurchaseViewModel.cs index 485ad15..7e31133 100644 --- a/HardwareShop/HardwareShopContracts/ViewModels/PurchaseViewModel.cs +++ b/HardwareShop/HardwareShopContracts/ViewModels/PurchaseViewModel.cs @@ -16,7 +16,7 @@ namespace HardwareShopContracts.ViewModels [DisplayName("Дата оплаты")] public DateTime? DatePurchase { get; set; } - public int UserID { get; set; } + public int UserId { get; set; } [DisplayName("Email клиента")] public string UserEmail { get; set; } = string.Empty; diff --git a/HardwareShop/HardwareShopDataModels/Models/IBuildModel.cs b/HardwareShop/HardwareShopDataModels/Models/IBuildModel.cs index 9bccda5..0540675 100644 --- a/HardwareShop/HardwareShopDataModels/Models/IBuildModel.cs +++ b/HardwareShop/HardwareShopDataModels/Models/IBuildModel.cs @@ -13,7 +13,7 @@ namespace HardwareShopDataModels.Models string BuildName { get; } - int UserID { get; } + int UserId { get; } Dictionary? BuildComponents { get; } } diff --git a/HardwareShop/HardwareShopDataModels/Models/ICommentModel.cs b/HardwareShop/HardwareShopDataModels/Models/ICommentModel.cs index 9f57aab..dc59c3f 100644 --- a/HardwareShop/HardwareShopDataModels/Models/ICommentModel.cs +++ b/HardwareShop/HardwareShopDataModels/Models/ICommentModel.cs @@ -10,6 +10,6 @@ namespace HardwareShopDataModels.Models { string Text { get; } - int BuildID { get; } + int BuildId { get; } } } diff --git a/HardwareShop/HardwareShopDataModels/Models/IPurchaseModel.cs b/HardwareShop/HardwareShopDataModels/Models/IPurchaseModel.cs index 3301105..69d4ef4 100644 --- a/HardwareShop/HardwareShopDataModels/Models/IPurchaseModel.cs +++ b/HardwareShop/HardwareShopDataModels/Models/IPurchaseModel.cs @@ -11,7 +11,7 @@ namespace HardwareShopDataModels.Models //через "?" обозначается что поле может быть null DateTime? DatePurchase { get; } - int UserID { get; } + int UserId { get; } Dictionary? PurchaseBuilds { get; } diff --git a/HardwareShop/HardwareShopDatabaseImplement/HardwareShopDatabase.cs b/HardwareShop/HardwareShopDatabaseImplement/HardwareShopDatabase.cs index 648429e..388217d 100644 --- a/HardwareShop/HardwareShopDatabaseImplement/HardwareShopDatabase.cs +++ b/HardwareShop/HardwareShopDatabaseImplement/HardwareShopDatabase.cs @@ -18,9 +18,9 @@ namespace HardwareShopDatabaseImplement protected override void OnModelCreating(ModelBuilder modelBuilder) { - modelBuilder.Entity().HasKey(x => new { x.ComponentId, x.BuildID }); - modelBuilder.Entity().HasKey(x => new { x.PurchaseID, x.BuildID }); - modelBuilder.Entity().HasKey(x => new { x.PurchaseID, x.GoodID }); + modelBuilder.Entity().HasKey(x => new { x.ComponentId, x.BuildId }); + modelBuilder.Entity().HasKey(x => new { x.PurchaseId, x.BuildId }); + modelBuilder.Entity().HasKey(x => new { x.PurchaseId, x.GoodId }); } public virtual DbSet Builds { set; get; } diff --git a/HardwareShop/HardwareShopDatabaseImplement/Migrations/20230401103551_init.Designer.cs b/HardwareShop/HardwareShopDatabaseImplement/Migrations/20230401103551_init.Designer.cs index 0677209..d00517d 100644 --- a/HardwareShop/HardwareShopDatabaseImplement/Migrations/20230401103551_init.Designer.cs +++ b/HardwareShop/HardwareShopDatabaseImplement/Migrations/20230401103551_init.Designer.cs @@ -40,7 +40,7 @@ namespace HardwareShopDatabaseImplement.Migrations b.Property("Price") .HasColumnType("decimal(18,2)"); - b.Property("UserID") + b.Property("UserId") .HasColumnType("int"); b.HasKey("Id"); @@ -53,7 +53,7 @@ namespace HardwareShopDatabaseImplement.Migrations b.Property("ComponentId") .HasColumnType("int"); - b.Property("BuildID") + b.Property("BuildId") .HasColumnType("int"); b.Property("BuildId") @@ -62,7 +62,7 @@ namespace HardwareShopDatabaseImplement.Migrations b.Property("Count") .HasColumnType("int"); - b.HasKey("ComponentId", "BuildID"); + b.HasKey("ComponentId", "BuildId"); b.HasIndex("BuildId"); @@ -77,7 +77,7 @@ namespace HardwareShopDatabaseImplement.Migrations SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); - b.Property("BuildID") + b.Property("BuildId") .HasColumnType("int"); b.Property("BuildName") @@ -90,7 +90,7 @@ namespace HardwareShopDatabaseImplement.Migrations b.HasKey("Id"); - b.HasIndex("BuildID"); + b.HasIndex("BuildId"); b.ToTable("Comments"); }); @@ -151,22 +151,22 @@ namespace HardwareShopDatabaseImplement.Migrations b.Property("Sum") .HasColumnType("decimal(18,2)"); - b.Property("UserID") + b.Property("UserId") .HasColumnType("int"); b.HasKey("Id"); - b.HasIndex("UserID"); + b.HasIndex("UserId"); b.ToTable("Purchase"); }); modelBuilder.Entity("HardwareShopDatabaseImplement.Models.PurchaseBuild", b => { - b.Property("PurchaseID") + b.Property("PurchaseId") .HasColumnType("int"); - b.Property("BuildID") + b.Property("BuildId") .HasColumnType("int"); b.Property("BuildId") @@ -178,7 +178,7 @@ namespace HardwareShopDatabaseImplement.Migrations b.Property("PurchaseId") .HasColumnType("int"); - b.HasKey("PurchaseID", "BuildID"); + b.HasKey("PurchaseId", "BuildId"); b.HasIndex("BuildId"); @@ -189,10 +189,10 @@ namespace HardwareShopDatabaseImplement.Migrations modelBuilder.Entity("HardwareShopDatabaseImplement.Models.PurchaseGood", b => { - b.Property("PurchaseID") + b.Property("PurchaseId") .HasColumnType("int"); - b.Property("GoodID") + b.Property("GoodId") .HasColumnType("int"); b.Property("Count") @@ -201,9 +201,9 @@ namespace HardwareShopDatabaseImplement.Migrations b.Property("PurchaseId") .HasColumnType("int"); - b.HasKey("PurchaseID", "GoodID"); + b.HasKey("PurchaseId", "GoodId"); - b.HasIndex("GoodID"); + b.HasIndex("GoodId"); b.HasIndex("PurchaseId"); @@ -261,7 +261,7 @@ namespace HardwareShopDatabaseImplement.Migrations { b.HasOne("HardwareShopDatabaseImplement.Models.Build", "Build") .WithMany() - .HasForeignKey("BuildID") + .HasForeignKey("BuildId") .OnDelete(DeleteBehavior.Cascade) .IsRequired(); @@ -272,7 +272,7 @@ namespace HardwareShopDatabaseImplement.Migrations { b.HasOne("HardwareShopDatabaseImplement.Models.User", "User") .WithMany() - .HasForeignKey("UserID") + .HasForeignKey("UserId") .OnDelete(DeleteBehavior.Cascade) .IsRequired(); @@ -302,7 +302,7 @@ namespace HardwareShopDatabaseImplement.Migrations { b.HasOne("HardwareShopDatabaseImplement.Models.Good", "Good") .WithMany() - .HasForeignKey("GoodID") + .HasForeignKey("GoodId") .OnDelete(DeleteBehavior.Cascade) .IsRequired(); diff --git a/HardwareShop/HardwareShopDatabaseImplement/Migrations/20230401103551_init.cs b/HardwareShop/HardwareShopDatabaseImplement/Migrations/20230401103551_init.cs index 3802537..53c95ac 100644 --- a/HardwareShop/HardwareShopDatabaseImplement/Migrations/20230401103551_init.cs +++ b/HardwareShop/HardwareShopDatabaseImplement/Migrations/20230401103551_init.cs @@ -19,7 +19,7 @@ namespace HardwareShopDatabaseImplement.Migrations .Annotation("SqlServer:Identity", "1, 1"), Price = table.Column(type: "decimal(18,2)", nullable: false), BuildName = table.Column(type: "nvarchar(max)", nullable: false), - UserID = table.Column(type: "int", nullable: false) + UserId = table.Column(type: "int", nullable: false) }, constraints: table => { @@ -86,14 +86,14 @@ namespace HardwareShopDatabaseImplement.Migrations .Annotation("SqlServer:Identity", "1, 1"), Text = table.Column(type: "nvarchar(max)", nullable: false), BuildName = table.Column(type: "nvarchar(max)", nullable: false), - BuildID = table.Column(type: "int", nullable: false) + BuildId = table.Column(type: "int", nullable: false) }, constraints: table => { table.PrimaryKey("PK_Comments", x => x.Id); table.ForeignKey( - name: "FK_Comments_Builds_BuildID", - column: x => x.BuildID, + name: "FK_Comments_Builds_BuildId", + column: x => x.BuildId, principalTable: "Builds", principalColumn: "Id", onDelete: ReferentialAction.Cascade); @@ -103,14 +103,14 @@ namespace HardwareShopDatabaseImplement.Migrations name: "BuildComponent", columns: table => new { - BuildID = table.Column(type: "int", nullable: false), + BuildId = table.Column(type: "int", nullable: false), ComponentId = table.Column(type: "int", nullable: false), Count = table.Column(type: "int", nullable: false), BuildId = table.Column(type: "int", nullable: false) }, constraints: table => { - table.PrimaryKey("PK_BuildComponent", x => new { x.ComponentId, x.BuildID }); + table.PrimaryKey("PK_BuildComponent", x => new { x.ComponentId, x.BuildId }); table.ForeignKey( name: "FK_BuildComponent_Builds_BuildId", column: x => x.BuildId, @@ -134,14 +134,14 @@ namespace HardwareShopDatabaseImplement.Migrations Sum = table.Column(type: "decimal(18,2)", nullable: false), PurchaseStatus = table.Column(type: "int", nullable: false), DatePurchase = table.Column(type: "datetime2", nullable: true), - UserID = table.Column(type: "int", nullable: false) + UserId = table.Column(type: "int", nullable: false) }, constraints: table => { table.PrimaryKey("PK_Purchase", x => x.Id); table.ForeignKey( - name: "FK_Purchase_Users_UserID", - column: x => x.UserID, + name: "FK_Purchase_Users_UserId", + column: x => x.UserId, principalTable: "Users", principalColumn: "Id", onDelete: ReferentialAction.Cascade); @@ -151,15 +151,15 @@ namespace HardwareShopDatabaseImplement.Migrations name: "PurchasesBuilds", columns: table => new { - BuildID = table.Column(type: "int", nullable: false), - PurchaseID = table.Column(type: "int", nullable: false), + BuildId = table.Column(type: "int", nullable: false), + PurchaseId = table.Column(type: "int", nullable: false), Count = table.Column(type: "int", nullable: false), BuildId = table.Column(type: "int", nullable: false), PurchaseId = table.Column(type: "int", nullable: false) }, constraints: table => { - table.PrimaryKey("PK_PurchasesBuilds", x => new { x.PurchaseID, x.BuildID }); + table.PrimaryKey("PK_PurchasesBuilds", x => new { x.PurchaseId, x.BuildId }); table.ForeignKey( name: "FK_PurchasesBuilds_Builds_BuildId", column: x => x.BuildId, @@ -178,17 +178,17 @@ namespace HardwareShopDatabaseImplement.Migrations name: "PurchasesGoods", columns: table => new { - PurchaseID = table.Column(type: "int", nullable: false), - GoodID = table.Column(type: "int", nullable: false), + PurchaseId = table.Column(type: "int", nullable: false), + GoodId = table.Column(type: "int", nullable: false), Count = table.Column(type: "int", nullable: false), PurchaseId = table.Column(type: "int", nullable: false) }, constraints: table => { - table.PrimaryKey("PK_PurchasesGoods", x => new { x.PurchaseID, x.GoodID }); + table.PrimaryKey("PK_PurchasesGoods", x => new { x.PurchaseId, x.GoodId }); table.ForeignKey( - name: "FK_PurchasesGoods_Goods_GoodID", - column: x => x.GoodID, + name: "FK_PurchasesGoods_Goods_GoodId", + column: x => x.GoodId, principalTable: "Goods", principalColumn: "Id", onDelete: ReferentialAction.Cascade); @@ -206,14 +206,14 @@ namespace HardwareShopDatabaseImplement.Migrations column: "BuildId"); migrationBuilder.CreateIndex( - name: "IX_Comments_BuildID", + name: "IX_Comments_BuildId", table: "Comments", - column: "BuildID"); + column: "BuildId"); migrationBuilder.CreateIndex( - name: "IX_Purchase_UserID", + name: "IX_Purchase_UserId", table: "Purchase", - column: "UserID"); + column: "UserId"); migrationBuilder.CreateIndex( name: "IX_PurchasesBuilds_BuildId", @@ -226,9 +226,9 @@ namespace HardwareShopDatabaseImplement.Migrations column: "PurchaseId"); migrationBuilder.CreateIndex( - name: "IX_PurchasesGoods_GoodID", + name: "IX_PurchasesGoods_GoodId", table: "PurchasesGoods", - column: "GoodID"); + column: "GoodId"); migrationBuilder.CreateIndex( name: "IX_PurchasesGoods_PurchaseId", diff --git a/HardwareShop/HardwareShopDatabaseImplement/Migrations/HardwareShopDatabaseModelSnapshot.cs b/HardwareShop/HardwareShopDatabaseImplement/Migrations/HardwareShopDatabaseModelSnapshot.cs index fe453d0..af9407c 100644 --- a/HardwareShop/HardwareShopDatabaseImplement/Migrations/HardwareShopDatabaseModelSnapshot.cs +++ b/HardwareShop/HardwareShopDatabaseImplement/Migrations/HardwareShopDatabaseModelSnapshot.cs @@ -37,7 +37,7 @@ namespace HardwareShopDatabaseImplement.Migrations b.Property("Price") .HasColumnType("decimal(18,2)"); - b.Property("UserID") + b.Property("UserId") .HasColumnType("int"); b.HasKey("Id"); @@ -50,7 +50,7 @@ namespace HardwareShopDatabaseImplement.Migrations b.Property("ComponentId") .HasColumnType("int"); - b.Property("BuildID") + b.Property("BuildId") .HasColumnType("int"); b.Property("BuildId") @@ -59,7 +59,7 @@ namespace HardwareShopDatabaseImplement.Migrations b.Property("Count") .HasColumnType("int"); - b.HasKey("ComponentId", "BuildID"); + b.HasKey("ComponentId", "BuildId"); b.HasIndex("BuildId"); @@ -74,7 +74,7 @@ namespace HardwareShopDatabaseImplement.Migrations SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); - b.Property("BuildID") + b.Property("BuildId") .HasColumnType("int"); b.Property("BuildName") @@ -87,7 +87,7 @@ namespace HardwareShopDatabaseImplement.Migrations b.HasKey("Id"); - b.HasIndex("BuildID"); + b.HasIndex("BuildId"); b.ToTable("Comments"); }); @@ -148,22 +148,22 @@ namespace HardwareShopDatabaseImplement.Migrations b.Property("Sum") .HasColumnType("decimal(18,2)"); - b.Property("UserID") + b.Property("UserId") .HasColumnType("int"); b.HasKey("Id"); - b.HasIndex("UserID"); + b.HasIndex("UserId"); b.ToTable("Purchase"); }); modelBuilder.Entity("HardwareShopDatabaseImplement.Models.PurchaseBuild", b => { - b.Property("PurchaseID") + b.Property("PurchaseId") .HasColumnType("int"); - b.Property("BuildID") + b.Property("BuildId") .HasColumnType("int"); b.Property("BuildId") @@ -175,7 +175,7 @@ namespace HardwareShopDatabaseImplement.Migrations b.Property("PurchaseId") .HasColumnType("int"); - b.HasKey("PurchaseID", "BuildID"); + b.HasKey("PurchaseId", "BuildId"); b.HasIndex("BuildId"); @@ -186,10 +186,10 @@ namespace HardwareShopDatabaseImplement.Migrations modelBuilder.Entity("HardwareShopDatabaseImplement.Models.PurchaseGood", b => { - b.Property("PurchaseID") + b.Property("PurchaseId") .HasColumnType("int"); - b.Property("GoodID") + b.Property("GoodId") .HasColumnType("int"); b.Property("Count") @@ -198,9 +198,9 @@ namespace HardwareShopDatabaseImplement.Migrations b.Property("PurchaseId") .HasColumnType("int"); - b.HasKey("PurchaseID", "GoodID"); + b.HasKey("PurchaseId", "GoodId"); - b.HasIndex("GoodID"); + b.HasIndex("GoodId"); b.HasIndex("PurchaseId"); @@ -258,7 +258,7 @@ namespace HardwareShopDatabaseImplement.Migrations { b.HasOne("HardwareShopDatabaseImplement.Models.Build", "Build") .WithMany() - .HasForeignKey("BuildID") + .HasForeignKey("BuildId") .OnDelete(DeleteBehavior.Cascade) .IsRequired(); @@ -269,7 +269,7 @@ namespace HardwareShopDatabaseImplement.Migrations { b.HasOne("HardwareShopDatabaseImplement.Models.User", "User") .WithMany() - .HasForeignKey("UserID") + .HasForeignKey("UserId") .OnDelete(DeleteBehavior.Cascade) .IsRequired(); @@ -299,7 +299,7 @@ namespace HardwareShopDatabaseImplement.Migrations { b.HasOne("HardwareShopDatabaseImplement.Models.Good", "Good") .WithMany() - .HasForeignKey("GoodID") + .HasForeignKey("GoodId") .OnDelete(DeleteBehavior.Cascade) .IsRequired(); diff --git a/HardwareShop/HardwareShopDatabaseImplement/Models/ModelsManyToMany/BuildComponent.cs b/HardwareShop/HardwareShopDatabaseImplement/Models/ModelsManyToMany/BuildComponent.cs index 5543221..3c28cd6 100644 --- a/HardwareShop/HardwareShopDatabaseImplement/Models/ModelsManyToMany/BuildComponent.cs +++ b/HardwareShop/HardwareShopDatabaseImplement/Models/ModelsManyToMany/BuildComponent.cs @@ -12,7 +12,7 @@ namespace HardwareShopDatabaseImplement.Models.ModelsManyToMany public class BuildComponent { - public int BuildID { get; set; } + public int BuildId { get; set; } public int ComponentId { get; set; } diff --git a/HardwareShop/HardwareShopDatabaseImplement/Models/ModelsManyToMany/PurchaseBuild.cs b/HardwareShop/HardwareShopDatabaseImplement/Models/ModelsManyToMany/PurchaseBuild.cs index 11d128f..6fd3692 100644 --- a/HardwareShop/HardwareShopDatabaseImplement/Models/ModelsManyToMany/PurchaseBuild.cs +++ b/HardwareShop/HardwareShopDatabaseImplement/Models/ModelsManyToMany/PurchaseBuild.cs @@ -11,9 +11,9 @@ namespace HardwareShopDatabaseImplement.Models.ModelsManyToMany public class PurchaseBuild { - public int BuildID { get; set; } + public int BuildId { get; set; } - public int PurchaseID { get; set; } + public int PurchaseId { get; set; } [Required] public int Count { get; set; } diff --git a/HardwareShop/HardwareShopDatabaseImplement/Models/ModelsManyToMany/PurchaseGood.cs b/HardwareShop/HardwareShopDatabaseImplement/Models/ModelsManyToMany/PurchaseGood.cs index 6a12faf..6cb8aaf 100644 --- a/HardwareShop/HardwareShopDatabaseImplement/Models/ModelsManyToMany/PurchaseGood.cs +++ b/HardwareShop/HardwareShopDatabaseImplement/Models/ModelsManyToMany/PurchaseGood.cs @@ -12,9 +12,9 @@ namespace HardwareShopDatabaseImplement.Models.ModelsManyToMany public class PurchaseGood { - public int PurchaseID { get; set; } + public int PurchaseId { get; set; } - public int GoodID { get; set; } + public int GoodId { get; set; } [Required] public int Count { get; set; } From 61d8d1170bc7e5f43610e054317fcb411995ac6f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9D=D0=B8=D0=BA=D0=BE=D0=BB=D0=B0=D0=B9?= Date: Sat, 1 Apr 2023 16:42:28 +0400 Subject: [PATCH 4/4] rename --- .../HardwareShopDatabase.cs | 5 +- ...er.cs => 20230401124213_init1.Designer.cs} | 383 ++++++++++-------- ...103551_init.cs => 20230401124213_init1.cs} | 244 ++++++----- .../HardwareShopDatabaseModelSnapshot.cs | 379 +++++++++-------- .../BuildComponent.cs | 7 +- .../PurchaseBuild.cs | 5 +- .../PurchaseGood.cs | 7 +- .../Component.cs | 2 +- .../Good.cs | 2 +- .../Order.cs | 2 +- .../Models/{ModelsWorker => Worker}/Build.cs | 12 +- .../{ModelsWorker => Worker}/Comment.cs | 8 +- .../{ModelsWorker => Worker}/Purchase.cs | 30 +- 13 files changed, 604 insertions(+), 482 deletions(-) rename HardwareShop/HardwareShopDatabaseImplement/Migrations/{20230401103551_init.Designer.cs => 20230401124213_init1.Designer.cs} (77%) rename HardwareShop/HardwareShopDatabaseImplement/Migrations/{20230401103551_init.cs => 20230401124213_init1.cs} (75%) rename HardwareShop/HardwareShopDatabaseImplement/Models/{ModelsManyToMany => ManyToMany}/BuildComponent.cs (74%) rename HardwareShop/HardwareShopDatabaseImplement/Models/{ModelsManyToMany => ManyToMany}/PurchaseBuild.cs (80%) rename HardwareShop/HardwareShopDatabaseImplement/Models/{ModelsManyToMany => ManyToMany}/PurchaseGood.cs (73%) rename HardwareShop/HardwareShopDatabaseImplement/Models/{ModelsStorekeeper => Storekeeper}/Component.cs (82%) rename HardwareShop/HardwareShopDatabaseImplement/Models/{ModelsStorekeeper => Storekeeper}/Good.cs (83%) rename HardwareShop/HardwareShopDatabaseImplement/Models/{ModelsStorekeeper => Storekeeper}/Order.cs (81%) rename HardwareShop/HardwareShopDatabaseImplement/Models/{ModelsWorker => Worker}/Build.cs (93%) rename HardwareShop/HardwareShopDatabaseImplement/Models/{ModelsWorker => Worker}/Comment.cs (86%) rename HardwareShop/HardwareShopDatabaseImplement/Models/{ModelsWorker => Worker}/Purchase.cs (88%) diff --git a/HardwareShop/HardwareShopDatabaseImplement/HardwareShopDatabase.cs b/HardwareShop/HardwareShopDatabaseImplement/HardwareShopDatabase.cs index 388217d..59867cc 100644 --- a/HardwareShop/HardwareShopDatabaseImplement/HardwareShopDatabase.cs +++ b/HardwareShop/HardwareShopDatabaseImplement/HardwareShopDatabase.cs @@ -1,6 +1,7 @@ using HardwareShopDatabaseImplement.Models; -using HardwareShopDatabaseImplement.Models.ModelsManyToMany; -using HardwareShopDatabaseImplement.Models.ModelsStorekeeper; +using HardwareShopDatabaseImplement.Models.ManyToMany; +using HardwareShopDatabaseImplement.Models.Storekeeper; +using HardwareShopDatabaseImplement.Models.Worker; using Microsoft.EntityFrameworkCore; namespace HardwareShopDatabaseImplement diff --git a/HardwareShop/HardwareShopDatabaseImplement/Migrations/20230401103551_init.Designer.cs b/HardwareShop/HardwareShopDatabaseImplement/Migrations/20230401124213_init1.Designer.cs similarity index 77% rename from HardwareShop/HardwareShopDatabaseImplement/Migrations/20230401103551_init.Designer.cs rename to HardwareShop/HardwareShopDatabaseImplement/Migrations/20230401124213_init1.Designer.cs index d00517d..50b9050 100644 --- a/HardwareShop/HardwareShopDatabaseImplement/Migrations/20230401103551_init.Designer.cs +++ b/HardwareShop/HardwareShopDatabaseImplement/Migrations/20230401124213_init1.Designer.cs @@ -12,8 +12,8 @@ using Microsoft.EntityFrameworkCore.Storage.ValueConversion; namespace HardwareShopDatabaseImplement.Migrations { [DbContext(typeof(HardwareShopDatabase))] - [Migration("20230401103551_init")] - partial class init + [Migration("20230401124213_init1")] + partial class init1 { /// protected override void BuildTargetModel(ModelBuilder modelBuilder) @@ -25,30 +25,7 @@ namespace HardwareShopDatabaseImplement.Migrations SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder); - modelBuilder.Entity("HardwareShopDatabaseImplement.Models.Build", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("int"); - - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); - - b.Property("BuildName") - .IsRequired() - .HasColumnType("nvarchar(max)"); - - b.Property("Price") - .HasColumnType("decimal(18,2)"); - - b.Property("UserId") - .HasColumnType("int"); - - b.HasKey("Id"); - - b.ToTable("Builds"); - }); - - modelBuilder.Entity("HardwareShopDatabaseImplement.Models.BuildComponent", b => + modelBuilder.Entity("HardwareShopDatabaseImplement.Models.ManyToMany.BuildComponent", b => { b.Property("ComponentId") .HasColumnType("int"); @@ -56,9 +33,6 @@ namespace HardwareShopDatabaseImplement.Migrations b.Property("BuildId") .HasColumnType("int"); - b.Property("BuildId") - .HasColumnType("int"); - b.Property("Count") .HasColumnType("int"); @@ -66,102 +40,10 @@ namespace HardwareShopDatabaseImplement.Migrations b.HasIndex("BuildId"); - b.ToTable("BuildComponent"); + b.ToTable("BuildsComponents"); }); - modelBuilder.Entity("HardwareShopDatabaseImplement.Models.Comment", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("int"); - - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); - - b.Property("BuildId") - .HasColumnType("int"); - - b.Property("BuildName") - .IsRequired() - .HasColumnType("nvarchar(max)"); - - b.Property("Text") - .IsRequired() - .HasColumnType("nvarchar(max)"); - - b.HasKey("Id"); - - b.HasIndex("BuildId"); - - b.ToTable("Comments"); - }); - - modelBuilder.Entity("HardwareShopDatabaseImplement.Models.Component", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("int"); - - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); - - b.HasKey("Id"); - - b.ToTable("Components"); - }); - - modelBuilder.Entity("HardwareShopDatabaseImplement.Models.Good", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("int"); - - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); - - b.HasKey("Id"); - - b.ToTable("Goods"); - }); - - modelBuilder.Entity("HardwareShopDatabaseImplement.Models.Order", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("int"); - - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); - - b.HasKey("Id"); - - b.ToTable("Orders"); - }); - - modelBuilder.Entity("HardwareShopDatabaseImplement.Models.Purchase", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("int"); - - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); - - b.Property("DatePurchase") - .HasColumnType("datetime2"); - - b.Property("PurchaseStatus") - .HasColumnType("int"); - - b.Property("Sum") - .HasColumnType("decimal(18,2)"); - - b.Property("UserId") - .HasColumnType("int"); - - b.HasKey("Id"); - - b.HasIndex("UserId"); - - b.ToTable("Purchase"); - }); - - modelBuilder.Entity("HardwareShopDatabaseImplement.Models.PurchaseBuild", b => + modelBuilder.Entity("HardwareShopDatabaseImplement.Models.ManyToMany.PurchaseBuild", b => { b.Property("PurchaseId") .HasColumnType("int"); @@ -169,25 +51,17 @@ namespace HardwareShopDatabaseImplement.Migrations b.Property("BuildId") .HasColumnType("int"); - b.Property("BuildId") - .HasColumnType("int"); - b.Property("Count") .HasColumnType("int"); - b.Property("PurchaseId") - .HasColumnType("int"); - b.HasKey("PurchaseId", "BuildId"); b.HasIndex("BuildId"); - b.HasIndex("PurchaseId"); - b.ToTable("PurchasesBuilds"); }); - modelBuilder.Entity("HardwareShopDatabaseImplement.Models.PurchaseGood", b => + modelBuilder.Entity("HardwareShopDatabaseImplement.Models.ManyToMany.PurchaseGood", b => { b.Property("PurchaseId") .HasColumnType("int"); @@ -198,18 +72,67 @@ namespace HardwareShopDatabaseImplement.Migrations b.Property("Count") .HasColumnType("int"); - b.Property("PurchaseId") - .HasColumnType("int"); - b.HasKey("PurchaseId", "GoodId"); b.HasIndex("GoodId"); - b.HasIndex("PurchaseId"); - b.ToTable("PurchasesGoods"); }); + modelBuilder.Entity("HardwareShopDatabaseImplement.Models.Storekeeper.Component", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("UserId") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.HasIndex("UserId"); + + b.ToTable("Components"); + }); + + modelBuilder.Entity("HardwareShopDatabaseImplement.Models.Storekeeper.Good", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("UserId") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.HasIndex("UserId"); + + b.ToTable("Goods"); + }); + + modelBuilder.Entity("HardwareShopDatabaseImplement.Models.Storekeeper.Order", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("UserId") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.HasIndex("UserId"); + + b.ToTable("Orders"); + }); + modelBuilder.Entity("HardwareShopDatabaseImplement.Models.User", b => { b.Property("Id") @@ -238,15 +161,89 @@ namespace HardwareShopDatabaseImplement.Migrations b.ToTable("Users"); }); - modelBuilder.Entity("HardwareShopDatabaseImplement.Models.BuildComponent", b => + modelBuilder.Entity("HardwareShopDatabaseImplement.Models.Worker.Build", b => { - b.HasOne("HardwareShopDatabaseImplement.Models.Build", "Build") + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("BuildName") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Price") + .HasColumnType("decimal(18,2)"); + + b.Property("UserId") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.HasIndex("UserId"); + + b.ToTable("Builds"); + }); + + modelBuilder.Entity("HardwareShopDatabaseImplement.Models.Worker.Comment", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("BuildId") + .HasColumnType("int"); + + b.Property("Text") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.HasKey("Id"); + + b.HasIndex("BuildId"); + + b.ToTable("Comments"); + }); + + modelBuilder.Entity("HardwareShopDatabaseImplement.Models.Worker.Purchase", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("DatePurchase") + .HasColumnType("datetime2"); + + b.Property("PurchaseStatus") + .HasColumnType("int"); + + b.Property("Sum") + .HasColumnType("decimal(18,2)"); + + b.Property("UserId") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.HasIndex("UserId"); + + b.ToTable("Purchases"); + }); + + modelBuilder.Entity("HardwareShopDatabaseImplement.Models.ManyToMany.BuildComponent", b => + { + b.HasOne("HardwareShopDatabaseImplement.Models.Worker.Build", "Build") .WithMany("Components") .HasForeignKey("BuildId") .OnDelete(DeleteBehavior.Cascade) .IsRequired(); - b.HasOne("HardwareShopDatabaseImplement.Models.Component", "Component") + b.HasOne("HardwareShopDatabaseImplement.Models.Storekeeper.Component", "Component") .WithMany() .HasForeignKey("ComponentId") .OnDelete(DeleteBehavior.Cascade) @@ -257,37 +254,15 @@ namespace HardwareShopDatabaseImplement.Migrations b.Navigation("Component"); }); - modelBuilder.Entity("HardwareShopDatabaseImplement.Models.Comment", b => + modelBuilder.Entity("HardwareShopDatabaseImplement.Models.ManyToMany.PurchaseBuild", b => { - b.HasOne("HardwareShopDatabaseImplement.Models.Build", "Build") - .WithMany() - .HasForeignKey("BuildId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.Navigation("Build"); - }); - - modelBuilder.Entity("HardwareShopDatabaseImplement.Models.Purchase", b => - { - b.HasOne("HardwareShopDatabaseImplement.Models.User", "User") - .WithMany() - .HasForeignKey("UserId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.Navigation("User"); - }); - - modelBuilder.Entity("HardwareShopDatabaseImplement.Models.PurchaseBuild", b => - { - b.HasOne("HardwareShopDatabaseImplement.Models.Build", "Build") + b.HasOne("HardwareShopDatabaseImplement.Models.Worker.Build", "Build") .WithMany("Purchases") .HasForeignKey("BuildId") .OnDelete(DeleteBehavior.Cascade) .IsRequired(); - b.HasOne("HardwareShopDatabaseImplement.Models.Purchase", "Purchase") + b.HasOne("HardwareShopDatabaseImplement.Models.Worker.Purchase", "Purchase") .WithMany("Builds") .HasForeignKey("PurchaseId") .OnDelete(DeleteBehavior.Cascade) @@ -298,15 +273,15 @@ namespace HardwareShopDatabaseImplement.Migrations b.Navigation("Purchase"); }); - modelBuilder.Entity("HardwareShopDatabaseImplement.Models.PurchaseGood", b => + modelBuilder.Entity("HardwareShopDatabaseImplement.Models.ManyToMany.PurchaseGood", b => { - b.HasOne("HardwareShopDatabaseImplement.Models.Good", "Good") + b.HasOne("HardwareShopDatabaseImplement.Models.Storekeeper.Good", "Good") .WithMany() .HasForeignKey("GoodId") .OnDelete(DeleteBehavior.Cascade) .IsRequired(); - b.HasOne("HardwareShopDatabaseImplement.Models.Purchase", "Purchase") + b.HasOne("HardwareShopDatabaseImplement.Models.Worker.Purchase", "Purchase") .WithMany("Goods") .HasForeignKey("PurchaseId") .OnDelete(DeleteBehavior.Cascade) @@ -317,14 +292,82 @@ namespace HardwareShopDatabaseImplement.Migrations b.Navigation("Purchase"); }); - modelBuilder.Entity("HardwareShopDatabaseImplement.Models.Build", b => + modelBuilder.Entity("HardwareShopDatabaseImplement.Models.Storekeeper.Component", b => { + b.HasOne("HardwareShopDatabaseImplement.Models.User", "User") + .WithMany() + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("User"); + }); + + modelBuilder.Entity("HardwareShopDatabaseImplement.Models.Storekeeper.Good", b => + { + b.HasOne("HardwareShopDatabaseImplement.Models.User", "User") + .WithMany() + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("User"); + }); + + modelBuilder.Entity("HardwareShopDatabaseImplement.Models.Storekeeper.Order", b => + { + b.HasOne("HardwareShopDatabaseImplement.Models.User", "User") + .WithMany() + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("User"); + }); + + modelBuilder.Entity("HardwareShopDatabaseImplement.Models.Worker.Build", b => + { + b.HasOne("HardwareShopDatabaseImplement.Models.User", "User") + .WithMany() + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("User"); + }); + + modelBuilder.Entity("HardwareShopDatabaseImplement.Models.Worker.Comment", b => + { + b.HasOne("HardwareShopDatabaseImplement.Models.Worker.Build", "Build") + .WithMany("Comments") + .HasForeignKey("BuildId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Build"); + }); + + modelBuilder.Entity("HardwareShopDatabaseImplement.Models.Worker.Purchase", b => + { + b.HasOne("HardwareShopDatabaseImplement.Models.User", "User") + .WithMany() + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("User"); + }); + + modelBuilder.Entity("HardwareShopDatabaseImplement.Models.Worker.Build", b => + { + b.Navigation("Comments"); + b.Navigation("Components"); b.Navigation("Purchases"); }); - modelBuilder.Entity("HardwareShopDatabaseImplement.Models.Purchase", b => + modelBuilder.Entity("HardwareShopDatabaseImplement.Models.Worker.Purchase", b => { b.Navigation("Builds"); diff --git a/HardwareShop/HardwareShopDatabaseImplement/Migrations/20230401103551_init.cs b/HardwareShop/HardwareShopDatabaseImplement/Migrations/20230401124213_init1.cs similarity index 75% rename from HardwareShop/HardwareShopDatabaseImplement/Migrations/20230401103551_init.cs rename to HardwareShop/HardwareShopDatabaseImplement/Migrations/20230401124213_init1.cs index 53c95ac..d03c65f 100644 --- a/HardwareShop/HardwareShopDatabaseImplement/Migrations/20230401103551_init.cs +++ b/HardwareShop/HardwareShopDatabaseImplement/Migrations/20230401124213_init1.cs @@ -6,62 +6,11 @@ using Microsoft.EntityFrameworkCore.Migrations; namespace HardwareShopDatabaseImplement.Migrations { /// - public partial class init : Migration + public partial class init1 : Migration { /// protected override void Up(MigrationBuilder migrationBuilder) { - migrationBuilder.CreateTable( - name: "Builds", - columns: table => new - { - Id = table.Column(type: "int", nullable: false) - .Annotation("SqlServer:Identity", "1, 1"), - Price = table.Column(type: "decimal(18,2)", nullable: false), - BuildName = table.Column(type: "nvarchar(max)", nullable: false), - UserId = table.Column(type: "int", nullable: false) - }, - constraints: table => - { - table.PrimaryKey("PK_Builds", x => x.Id); - }); - - migrationBuilder.CreateTable( - name: "Components", - columns: table => new - { - Id = table.Column(type: "int", nullable: false) - .Annotation("SqlServer:Identity", "1, 1") - }, - constraints: table => - { - table.PrimaryKey("PK_Components", x => x.Id); - }); - - migrationBuilder.CreateTable( - name: "Goods", - columns: table => new - { - Id = table.Column(type: "int", nullable: false) - .Annotation("SqlServer:Identity", "1, 1") - }, - constraints: table => - { - table.PrimaryKey("PK_Goods", x => x.Id); - }); - - migrationBuilder.CreateTable( - name: "Orders", - columns: table => new - { - Id = table.Column(type: "int", nullable: false) - .Annotation("SqlServer:Identity", "1, 1") - }, - constraints: table => - { - table.PrimaryKey("PK_Orders", x => x.Id); - }); - migrationBuilder.CreateTable( name: "Users", columns: table => new @@ -78,6 +27,106 @@ namespace HardwareShopDatabaseImplement.Migrations table.PrimaryKey("PK_Users", x => x.Id); }); + migrationBuilder.CreateTable( + name: "Builds", + columns: table => new + { + Id = table.Column(type: "int", nullable: false) + .Annotation("SqlServer:Identity", "1, 1"), + Price = table.Column(type: "decimal(18,2)", nullable: false), + BuildName = table.Column(type: "nvarchar(max)", nullable: false), + UserId = table.Column(type: "int", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Builds", x => x.Id); + table.ForeignKey( + name: "FK_Builds_Users_UserId", + column: x => x.UserId, + principalTable: "Users", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateTable( + name: "Components", + columns: table => new + { + Id = table.Column(type: "int", nullable: false) + .Annotation("SqlServer:Identity", "1, 1"), + UserId = table.Column(type: "int", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Components", x => x.Id); + table.ForeignKey( + name: "FK_Components_Users_UserId", + column: x => x.UserId, + principalTable: "Users", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateTable( + name: "Goods", + columns: table => new + { + Id = table.Column(type: "int", nullable: false) + .Annotation("SqlServer:Identity", "1, 1"), + UserId = table.Column(type: "int", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Goods", x => x.Id); + table.ForeignKey( + name: "FK_Goods_Users_UserId", + column: x => x.UserId, + principalTable: "Users", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateTable( + name: "Orders", + columns: table => new + { + Id = table.Column(type: "int", nullable: false) + .Annotation("SqlServer:Identity", "1, 1"), + UserId = table.Column(type: "int", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Orders", x => x.Id); + table.ForeignKey( + name: "FK_Orders_Users_UserId", + column: x => x.UserId, + principalTable: "Users", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateTable( + name: "Purchases", + columns: table => new + { + Id = table.Column(type: "int", nullable: false) + .Annotation("SqlServer:Identity", "1, 1"), + Sum = table.Column(type: "decimal(18,2)", nullable: false), + PurchaseStatus = table.Column(type: "int", nullable: false), + DatePurchase = table.Column(type: "datetime2", nullable: true), + UserId = table.Column(type: "int", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Purchases", x => x.Id); + table.ForeignKey( + name: "FK_Purchases_Users_UserId", + column: x => x.UserId, + principalTable: "Users", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + }); + migrationBuilder.CreateTable( name: "Comments", columns: table => new @@ -85,7 +134,6 @@ namespace HardwareShopDatabaseImplement.Migrations Id = table.Column(type: "int", nullable: false) .Annotation("SqlServer:Identity", "1, 1"), Text = table.Column(type: "nvarchar(max)", nullable: false), - BuildName = table.Column(type: "nvarchar(max)", nullable: false), BuildId = table.Column(type: "int", nullable: false) }, constraints: table => @@ -100,62 +148,37 @@ namespace HardwareShopDatabaseImplement.Migrations }); migrationBuilder.CreateTable( - name: "BuildComponent", + name: "BuildsComponents", columns: table => new { BuildId = table.Column(type: "int", nullable: false), ComponentId = table.Column(type: "int", nullable: false), - Count = table.Column(type: "int", nullable: false), - BuildId = table.Column(type: "int", nullable: false) + Count = table.Column(type: "int", nullable: false) }, constraints: table => { - table.PrimaryKey("PK_BuildComponent", x => new { x.ComponentId, x.BuildId }); + table.PrimaryKey("PK_BuildsComponents", x => new { x.ComponentId, x.BuildId }); table.ForeignKey( - name: "FK_BuildComponent_Builds_BuildId", + name: "FK_BuildsComponents_Builds_BuildId", column: x => x.BuildId, principalTable: "Builds", principalColumn: "Id", onDelete: ReferentialAction.Cascade); table.ForeignKey( - name: "FK_BuildComponent_Components_ComponentId", + name: "FK_BuildsComponents_Components_ComponentId", column: x => x.ComponentId, principalTable: "Components", principalColumn: "Id", onDelete: ReferentialAction.Cascade); }); - migrationBuilder.CreateTable( - name: "Purchase", - columns: table => new - { - Id = table.Column(type: "int", nullable: false) - .Annotation("SqlServer:Identity", "1, 1"), - Sum = table.Column(type: "decimal(18,2)", nullable: false), - PurchaseStatus = table.Column(type: "int", nullable: false), - DatePurchase = table.Column(type: "datetime2", nullable: true), - UserId = table.Column(type: "int", nullable: false) - }, - constraints: table => - { - table.PrimaryKey("PK_Purchase", x => x.Id); - table.ForeignKey( - name: "FK_Purchase_Users_UserId", - column: x => x.UserId, - principalTable: "Users", - principalColumn: "Id", - onDelete: ReferentialAction.Cascade); - }); - migrationBuilder.CreateTable( name: "PurchasesBuilds", columns: table => new { BuildId = table.Column(type: "int", nullable: false), PurchaseId = table.Column(type: "int", nullable: false), - Count = table.Column(type: "int", nullable: false), - BuildId = table.Column(type: "int", nullable: false), - PurchaseId = table.Column(type: "int", nullable: false) + Count = table.Column(type: "int", nullable: false) }, constraints: table => { @@ -167,9 +190,9 @@ namespace HardwareShopDatabaseImplement.Migrations principalColumn: "Id", onDelete: ReferentialAction.Cascade); table.ForeignKey( - name: "FK_PurchasesBuilds_Purchase_PurchaseId", + name: "FK_PurchasesBuilds_Purchases_PurchaseId", column: x => x.PurchaseId, - principalTable: "Purchase", + principalTable: "Purchases", principalColumn: "Id", onDelete: ReferentialAction.Cascade); }); @@ -180,8 +203,7 @@ namespace HardwareShopDatabaseImplement.Migrations { PurchaseId = table.Column(type: "int", nullable: false), GoodId = table.Column(type: "int", nullable: false), - Count = table.Column(type: "int", nullable: false), - PurchaseId = table.Column(type: "int", nullable: false) + Count = table.Column(type: "int", nullable: false) }, constraints: table => { @@ -193,16 +215,21 @@ namespace HardwareShopDatabaseImplement.Migrations principalColumn: "Id", onDelete: ReferentialAction.Cascade); table.ForeignKey( - name: "FK_PurchasesGoods_Purchase_PurchaseId", + name: "FK_PurchasesGoods_Purchases_PurchaseId", column: x => x.PurchaseId, - principalTable: "Purchase", + principalTable: "Purchases", principalColumn: "Id", onDelete: ReferentialAction.Cascade); }); migrationBuilder.CreateIndex( - name: "IX_BuildComponent_BuildId", - table: "BuildComponent", + name: "IX_Builds_UserId", + table: "Builds", + column: "UserId"); + + migrationBuilder.CreateIndex( + name: "IX_BuildsComponents_BuildId", + table: "BuildsComponents", column: "BuildId"); migrationBuilder.CreateIndex( @@ -211,8 +238,23 @@ namespace HardwareShopDatabaseImplement.Migrations column: "BuildId"); migrationBuilder.CreateIndex( - name: "IX_Purchase_UserId", - table: "Purchase", + name: "IX_Components_UserId", + table: "Components", + column: "UserId"); + + migrationBuilder.CreateIndex( + name: "IX_Goods_UserId", + table: "Goods", + column: "UserId"); + + migrationBuilder.CreateIndex( + name: "IX_Orders_UserId", + table: "Orders", + column: "UserId"); + + migrationBuilder.CreateIndex( + name: "IX_Purchases_UserId", + table: "Purchases", column: "UserId"); migrationBuilder.CreateIndex( @@ -220,27 +262,17 @@ namespace HardwareShopDatabaseImplement.Migrations table: "PurchasesBuilds", column: "BuildId"); - migrationBuilder.CreateIndex( - name: "IX_PurchasesBuilds_PurchaseId", - table: "PurchasesBuilds", - column: "PurchaseId"); - migrationBuilder.CreateIndex( name: "IX_PurchasesGoods_GoodId", table: "PurchasesGoods", column: "GoodId"); - - migrationBuilder.CreateIndex( - name: "IX_PurchasesGoods_PurchaseId", - table: "PurchasesGoods", - column: "PurchaseId"); } /// protected override void Down(MigrationBuilder migrationBuilder) { migrationBuilder.DropTable( - name: "BuildComponent"); + name: "BuildsComponents"); migrationBuilder.DropTable( name: "Comments"); @@ -264,7 +296,7 @@ namespace HardwareShopDatabaseImplement.Migrations name: "Goods"); migrationBuilder.DropTable( - name: "Purchase"); + name: "Purchases"); migrationBuilder.DropTable( name: "Users"); diff --git a/HardwareShop/HardwareShopDatabaseImplement/Migrations/HardwareShopDatabaseModelSnapshot.cs b/HardwareShop/HardwareShopDatabaseImplement/Migrations/HardwareShopDatabaseModelSnapshot.cs index af9407c..bf9e625 100644 --- a/HardwareShop/HardwareShopDatabaseImplement/Migrations/HardwareShopDatabaseModelSnapshot.cs +++ b/HardwareShop/HardwareShopDatabaseImplement/Migrations/HardwareShopDatabaseModelSnapshot.cs @@ -22,30 +22,7 @@ namespace HardwareShopDatabaseImplement.Migrations SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder); - modelBuilder.Entity("HardwareShopDatabaseImplement.Models.Build", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("int"); - - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); - - b.Property("BuildName") - .IsRequired() - .HasColumnType("nvarchar(max)"); - - b.Property("Price") - .HasColumnType("decimal(18,2)"); - - b.Property("UserId") - .HasColumnType("int"); - - b.HasKey("Id"); - - b.ToTable("Builds"); - }); - - modelBuilder.Entity("HardwareShopDatabaseImplement.Models.BuildComponent", b => + modelBuilder.Entity("HardwareShopDatabaseImplement.Models.ManyToMany.BuildComponent", b => { b.Property("ComponentId") .HasColumnType("int"); @@ -53,9 +30,6 @@ namespace HardwareShopDatabaseImplement.Migrations b.Property("BuildId") .HasColumnType("int"); - b.Property("BuildId") - .HasColumnType("int"); - b.Property("Count") .HasColumnType("int"); @@ -63,102 +37,10 @@ namespace HardwareShopDatabaseImplement.Migrations b.HasIndex("BuildId"); - b.ToTable("BuildComponent"); + b.ToTable("BuildsComponents"); }); - modelBuilder.Entity("HardwareShopDatabaseImplement.Models.Comment", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("int"); - - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); - - b.Property("BuildId") - .HasColumnType("int"); - - b.Property("BuildName") - .IsRequired() - .HasColumnType("nvarchar(max)"); - - b.Property("Text") - .IsRequired() - .HasColumnType("nvarchar(max)"); - - b.HasKey("Id"); - - b.HasIndex("BuildId"); - - b.ToTable("Comments"); - }); - - modelBuilder.Entity("HardwareShopDatabaseImplement.Models.Component", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("int"); - - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); - - b.HasKey("Id"); - - b.ToTable("Components"); - }); - - modelBuilder.Entity("HardwareShopDatabaseImplement.Models.Good", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("int"); - - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); - - b.HasKey("Id"); - - b.ToTable("Goods"); - }); - - modelBuilder.Entity("HardwareShopDatabaseImplement.Models.Order", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("int"); - - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); - - b.HasKey("Id"); - - b.ToTable("Orders"); - }); - - modelBuilder.Entity("HardwareShopDatabaseImplement.Models.Purchase", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("int"); - - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); - - b.Property("DatePurchase") - .HasColumnType("datetime2"); - - b.Property("PurchaseStatus") - .HasColumnType("int"); - - b.Property("Sum") - .HasColumnType("decimal(18,2)"); - - b.Property("UserId") - .HasColumnType("int"); - - b.HasKey("Id"); - - b.HasIndex("UserId"); - - b.ToTable("Purchase"); - }); - - modelBuilder.Entity("HardwareShopDatabaseImplement.Models.PurchaseBuild", b => + modelBuilder.Entity("HardwareShopDatabaseImplement.Models.ManyToMany.PurchaseBuild", b => { b.Property("PurchaseId") .HasColumnType("int"); @@ -166,25 +48,17 @@ namespace HardwareShopDatabaseImplement.Migrations b.Property("BuildId") .HasColumnType("int"); - b.Property("BuildId") - .HasColumnType("int"); - b.Property("Count") .HasColumnType("int"); - b.Property("PurchaseId") - .HasColumnType("int"); - b.HasKey("PurchaseId", "BuildId"); b.HasIndex("BuildId"); - b.HasIndex("PurchaseId"); - b.ToTable("PurchasesBuilds"); }); - modelBuilder.Entity("HardwareShopDatabaseImplement.Models.PurchaseGood", b => + modelBuilder.Entity("HardwareShopDatabaseImplement.Models.ManyToMany.PurchaseGood", b => { b.Property("PurchaseId") .HasColumnType("int"); @@ -195,18 +69,67 @@ namespace HardwareShopDatabaseImplement.Migrations b.Property("Count") .HasColumnType("int"); - b.Property("PurchaseId") - .HasColumnType("int"); - b.HasKey("PurchaseId", "GoodId"); b.HasIndex("GoodId"); - b.HasIndex("PurchaseId"); - b.ToTable("PurchasesGoods"); }); + modelBuilder.Entity("HardwareShopDatabaseImplement.Models.Storekeeper.Component", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("UserId") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.HasIndex("UserId"); + + b.ToTable("Components"); + }); + + modelBuilder.Entity("HardwareShopDatabaseImplement.Models.Storekeeper.Good", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("UserId") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.HasIndex("UserId"); + + b.ToTable("Goods"); + }); + + modelBuilder.Entity("HardwareShopDatabaseImplement.Models.Storekeeper.Order", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("UserId") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.HasIndex("UserId"); + + b.ToTable("Orders"); + }); + modelBuilder.Entity("HardwareShopDatabaseImplement.Models.User", b => { b.Property("Id") @@ -235,15 +158,89 @@ namespace HardwareShopDatabaseImplement.Migrations b.ToTable("Users"); }); - modelBuilder.Entity("HardwareShopDatabaseImplement.Models.BuildComponent", b => + modelBuilder.Entity("HardwareShopDatabaseImplement.Models.Worker.Build", b => { - b.HasOne("HardwareShopDatabaseImplement.Models.Build", "Build") + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("BuildName") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Price") + .HasColumnType("decimal(18,2)"); + + b.Property("UserId") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.HasIndex("UserId"); + + b.ToTable("Builds"); + }); + + modelBuilder.Entity("HardwareShopDatabaseImplement.Models.Worker.Comment", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("BuildId") + .HasColumnType("int"); + + b.Property("Text") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.HasKey("Id"); + + b.HasIndex("BuildId"); + + b.ToTable("Comments"); + }); + + modelBuilder.Entity("HardwareShopDatabaseImplement.Models.Worker.Purchase", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("DatePurchase") + .HasColumnType("datetime2"); + + b.Property("PurchaseStatus") + .HasColumnType("int"); + + b.Property("Sum") + .HasColumnType("decimal(18,2)"); + + b.Property("UserId") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.HasIndex("UserId"); + + b.ToTable("Purchases"); + }); + + modelBuilder.Entity("HardwareShopDatabaseImplement.Models.ManyToMany.BuildComponent", b => + { + b.HasOne("HardwareShopDatabaseImplement.Models.Worker.Build", "Build") .WithMany("Components") .HasForeignKey("BuildId") .OnDelete(DeleteBehavior.Cascade) .IsRequired(); - b.HasOne("HardwareShopDatabaseImplement.Models.Component", "Component") + b.HasOne("HardwareShopDatabaseImplement.Models.Storekeeper.Component", "Component") .WithMany() .HasForeignKey("ComponentId") .OnDelete(DeleteBehavior.Cascade) @@ -254,37 +251,15 @@ namespace HardwareShopDatabaseImplement.Migrations b.Navigation("Component"); }); - modelBuilder.Entity("HardwareShopDatabaseImplement.Models.Comment", b => + modelBuilder.Entity("HardwareShopDatabaseImplement.Models.ManyToMany.PurchaseBuild", b => { - b.HasOne("HardwareShopDatabaseImplement.Models.Build", "Build") - .WithMany() - .HasForeignKey("BuildId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.Navigation("Build"); - }); - - modelBuilder.Entity("HardwareShopDatabaseImplement.Models.Purchase", b => - { - b.HasOne("HardwareShopDatabaseImplement.Models.User", "User") - .WithMany() - .HasForeignKey("UserId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.Navigation("User"); - }); - - modelBuilder.Entity("HardwareShopDatabaseImplement.Models.PurchaseBuild", b => - { - b.HasOne("HardwareShopDatabaseImplement.Models.Build", "Build") + b.HasOne("HardwareShopDatabaseImplement.Models.Worker.Build", "Build") .WithMany("Purchases") .HasForeignKey("BuildId") .OnDelete(DeleteBehavior.Cascade) .IsRequired(); - b.HasOne("HardwareShopDatabaseImplement.Models.Purchase", "Purchase") + b.HasOne("HardwareShopDatabaseImplement.Models.Worker.Purchase", "Purchase") .WithMany("Builds") .HasForeignKey("PurchaseId") .OnDelete(DeleteBehavior.Cascade) @@ -295,15 +270,15 @@ namespace HardwareShopDatabaseImplement.Migrations b.Navigation("Purchase"); }); - modelBuilder.Entity("HardwareShopDatabaseImplement.Models.PurchaseGood", b => + modelBuilder.Entity("HardwareShopDatabaseImplement.Models.ManyToMany.PurchaseGood", b => { - b.HasOne("HardwareShopDatabaseImplement.Models.Good", "Good") + b.HasOne("HardwareShopDatabaseImplement.Models.Storekeeper.Good", "Good") .WithMany() .HasForeignKey("GoodId") .OnDelete(DeleteBehavior.Cascade) .IsRequired(); - b.HasOne("HardwareShopDatabaseImplement.Models.Purchase", "Purchase") + b.HasOne("HardwareShopDatabaseImplement.Models.Worker.Purchase", "Purchase") .WithMany("Goods") .HasForeignKey("PurchaseId") .OnDelete(DeleteBehavior.Cascade) @@ -314,14 +289,82 @@ namespace HardwareShopDatabaseImplement.Migrations b.Navigation("Purchase"); }); - modelBuilder.Entity("HardwareShopDatabaseImplement.Models.Build", b => + modelBuilder.Entity("HardwareShopDatabaseImplement.Models.Storekeeper.Component", b => { + b.HasOne("HardwareShopDatabaseImplement.Models.User", "User") + .WithMany() + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("User"); + }); + + modelBuilder.Entity("HardwareShopDatabaseImplement.Models.Storekeeper.Good", b => + { + b.HasOne("HardwareShopDatabaseImplement.Models.User", "User") + .WithMany() + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("User"); + }); + + modelBuilder.Entity("HardwareShopDatabaseImplement.Models.Storekeeper.Order", b => + { + b.HasOne("HardwareShopDatabaseImplement.Models.User", "User") + .WithMany() + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("User"); + }); + + modelBuilder.Entity("HardwareShopDatabaseImplement.Models.Worker.Build", b => + { + b.HasOne("HardwareShopDatabaseImplement.Models.User", "User") + .WithMany() + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("User"); + }); + + modelBuilder.Entity("HardwareShopDatabaseImplement.Models.Worker.Comment", b => + { + b.HasOne("HardwareShopDatabaseImplement.Models.Worker.Build", "Build") + .WithMany("Comments") + .HasForeignKey("BuildId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Build"); + }); + + modelBuilder.Entity("HardwareShopDatabaseImplement.Models.Worker.Purchase", b => + { + b.HasOne("HardwareShopDatabaseImplement.Models.User", "User") + .WithMany() + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("User"); + }); + + modelBuilder.Entity("HardwareShopDatabaseImplement.Models.Worker.Build", b => + { + b.Navigation("Comments"); + b.Navigation("Components"); b.Navigation("Purchases"); }); - modelBuilder.Entity("HardwareShopDatabaseImplement.Models.Purchase", b => + modelBuilder.Entity("HardwareShopDatabaseImplement.Models.Worker.Purchase", b => { b.Navigation("Builds"); diff --git a/HardwareShop/HardwareShopDatabaseImplement/Models/ModelsManyToMany/BuildComponent.cs b/HardwareShop/HardwareShopDatabaseImplement/Models/ManyToMany/BuildComponent.cs similarity index 74% rename from HardwareShop/HardwareShopDatabaseImplement/Models/ModelsManyToMany/BuildComponent.cs rename to HardwareShop/HardwareShopDatabaseImplement/Models/ManyToMany/BuildComponent.cs index 3c28cd6..371fc69 100644 --- a/HardwareShop/HardwareShopDatabaseImplement/Models/ModelsManyToMany/BuildComponent.cs +++ b/HardwareShop/HardwareShopDatabaseImplement/Models/ManyToMany/BuildComponent.cs @@ -1,13 +1,14 @@ -using System; +using HardwareShopDatabaseImplement.Models.Storekeeper; +using HardwareShopDatabaseImplement.Models.Worker; +using System; using System.Collections.Generic; using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations.Schema; using System.Linq; using System.Text; using System.Threading.Tasks; -using HardwareShopDatabaseImplement.Models.ModelsStorekeeper; -namespace HardwareShopDatabaseImplement.Models.ModelsManyToMany +namespace HardwareShopDatabaseImplement.Models.ManyToMany { public class BuildComponent { diff --git a/HardwareShop/HardwareShopDatabaseImplement/Models/ModelsManyToMany/PurchaseBuild.cs b/HardwareShop/HardwareShopDatabaseImplement/Models/ManyToMany/PurchaseBuild.cs similarity index 80% rename from HardwareShop/HardwareShopDatabaseImplement/Models/ModelsManyToMany/PurchaseBuild.cs rename to HardwareShop/HardwareShopDatabaseImplement/Models/ManyToMany/PurchaseBuild.cs index 6fd3692..248b4be 100644 --- a/HardwareShop/HardwareShopDatabaseImplement/Models/ModelsManyToMany/PurchaseBuild.cs +++ b/HardwareShop/HardwareShopDatabaseImplement/Models/ManyToMany/PurchaseBuild.cs @@ -1,4 +1,5 @@ -using System; +using HardwareShopDatabaseImplement.Models.Worker; +using System; using System.Collections.Generic; using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations.Schema; @@ -6,7 +7,7 @@ using System.Linq; using System.Text; using System.Threading.Tasks; -namespace HardwareShopDatabaseImplement.Models.ModelsManyToMany +namespace HardwareShopDatabaseImplement.Models.ManyToMany { public class PurchaseBuild { diff --git a/HardwareShop/HardwareShopDatabaseImplement/Models/ModelsManyToMany/PurchaseGood.cs b/HardwareShop/HardwareShopDatabaseImplement/Models/ManyToMany/PurchaseGood.cs similarity index 73% rename from HardwareShop/HardwareShopDatabaseImplement/Models/ModelsManyToMany/PurchaseGood.cs rename to HardwareShop/HardwareShopDatabaseImplement/Models/ManyToMany/PurchaseGood.cs index 6cb8aaf..dd11b99 100644 --- a/HardwareShop/HardwareShopDatabaseImplement/Models/ModelsManyToMany/PurchaseGood.cs +++ b/HardwareShop/HardwareShopDatabaseImplement/Models/ManyToMany/PurchaseGood.cs @@ -1,13 +1,14 @@ -using System; +using HardwareShopDatabaseImplement.Models.Storekeeper; +using HardwareShopDatabaseImplement.Models.Worker; +using System; using System.Collections.Generic; using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations.Schema; using System.Linq; using System.Text; using System.Threading.Tasks; -using HardwareShopDatabaseImplement.Models.ModelsStorekeeper; -namespace HardwareShopDatabaseImplement.Models.ModelsManyToMany +namespace HardwareShopDatabaseImplement.Models.ManyToMany { public class PurchaseGood { diff --git a/HardwareShop/HardwareShopDatabaseImplement/Models/ModelsStorekeeper/Component.cs b/HardwareShop/HardwareShopDatabaseImplement/Models/Storekeeper/Component.cs similarity index 82% rename from HardwareShop/HardwareShopDatabaseImplement/Models/ModelsStorekeeper/Component.cs rename to HardwareShop/HardwareShopDatabaseImplement/Models/Storekeeper/Component.cs index 10cdb6b..e930ffc 100644 --- a/HardwareShop/HardwareShopDatabaseImplement/Models/ModelsStorekeeper/Component.cs +++ b/HardwareShop/HardwareShopDatabaseImplement/Models/Storekeeper/Component.cs @@ -5,7 +5,7 @@ using System.Linq; using System.Text; using System.Threading.Tasks; -namespace HardwareShopDatabaseImplement.Models.ModelsStorekeeper +namespace HardwareShopDatabaseImplement.Models.Storekeeper { public class Component : IComponentModel { diff --git a/HardwareShop/HardwareShopDatabaseImplement/Models/ModelsStorekeeper/Good.cs b/HardwareShop/HardwareShopDatabaseImplement/Models/Storekeeper/Good.cs similarity index 83% rename from HardwareShop/HardwareShopDatabaseImplement/Models/ModelsStorekeeper/Good.cs rename to HardwareShop/HardwareShopDatabaseImplement/Models/Storekeeper/Good.cs index 2d6ee18..2f95404 100644 --- a/HardwareShop/HardwareShopDatabaseImplement/Models/ModelsStorekeeper/Good.cs +++ b/HardwareShop/HardwareShopDatabaseImplement/Models/Storekeeper/Good.cs @@ -6,7 +6,7 @@ using System.Linq; using System.Text; using System.Threading.Tasks; -namespace HardwareShopDatabaseImplement.Models.ModelsStorekeeper +namespace HardwareShopDatabaseImplement.Models.Storekeeper { public class Good : IGoodModel { diff --git a/HardwareShop/HardwareShopDatabaseImplement/Models/ModelsStorekeeper/Order.cs b/HardwareShop/HardwareShopDatabaseImplement/Models/Storekeeper/Order.cs similarity index 81% rename from HardwareShop/HardwareShopDatabaseImplement/Models/ModelsStorekeeper/Order.cs rename to HardwareShop/HardwareShopDatabaseImplement/Models/Storekeeper/Order.cs index 48946a8..2d35035 100644 --- a/HardwareShop/HardwareShopDatabaseImplement/Models/ModelsStorekeeper/Order.cs +++ b/HardwareShop/HardwareShopDatabaseImplement/Models/Storekeeper/Order.cs @@ -2,7 +2,7 @@ using HardwareShopDataModels.Models; using HardwareShopDataModels.Models; using System.ComponentModel; -namespace HardwareShopDatabaseImplement.Models.ModelsStorekeeper +namespace HardwareShopDatabaseImplement.Models.Storekeeper { public class Order : IOrderModel { diff --git a/HardwareShop/HardwareShopDatabaseImplement/Models/ModelsWorker/Build.cs b/HardwareShop/HardwareShopDatabaseImplement/Models/Worker/Build.cs similarity index 93% rename from HardwareShop/HardwareShopDatabaseImplement/Models/ModelsWorker/Build.cs rename to HardwareShop/HardwareShopDatabaseImplement/Models/Worker/Build.cs index 206657d..45e3ac5 100644 --- a/HardwareShop/HardwareShopDatabaseImplement/Models/ModelsWorker/Build.cs +++ b/HardwareShop/HardwareShopDatabaseImplement/Models/Worker/Build.cs @@ -1,11 +1,11 @@ using HardwareShopContracts.BindingModels; using HardwareShopContracts.ViewModels; -using HardwareShopDatabaseImplement.Models.ModelsManyToMany; +using HardwareShopDatabaseImplement.Models.ManyToMany; using HardwareShopDataModels.Models; using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations.Schema; -namespace HardwareShopDatabaseImplement.Models.ModelsWorker +namespace HardwareShopDatabaseImplement.Models.Worker { public class Build : IBuildModel { @@ -18,7 +18,7 @@ namespace HardwareShopDatabaseImplement.Models.ModelsWorker public string BuildName { get; set; } = string.Empty; [Required] - public int UserID { get; set; } + public int UserId { get; set; } public virtual User User { get; set; } @@ -55,7 +55,7 @@ namespace HardwareShopDatabaseImplement.Models.ModelsWorker Id = model.Id, Price = model.Price, BuildName = model.BuildName, - UserID = model.UserID, + UserId = model.UserId, Components = model.BuildComponents.Select(x => new BuildComponent { Component = context.Components.First(y => y.Id == x.Key), @@ -76,13 +76,13 @@ namespace HardwareShopDatabaseImplement.Models.ModelsWorker BuildName = BuildName, Price = Price, UserEmail = User.Email, - UserID = UserID, + UserId = UserId, BuildComponents = BuildComponents }; public void UpdateComponents(HardwareShopDatabase context, BuildBindingModel model) { - var buildComponents = context.BuildsComponents.Where(rec => rec.BuildID == model.Id).ToList(); + var buildComponents = context.BuildsComponents.Where(rec => rec.BuildId == model.Id).ToList(); if (buildComponents != null && buildComponents.Count > 0) { // удалили те в бд, которых нет в модели context.BuildsComponents.RemoveRange(buildComponents.Where(rec => !model.BuildComponents.ContainsKey(rec.ComponentId))); diff --git a/HardwareShop/HardwareShopDatabaseImplement/Models/ModelsWorker/Comment.cs b/HardwareShop/HardwareShopDatabaseImplement/Models/Worker/Comment.cs similarity index 86% rename from HardwareShop/HardwareShopDatabaseImplement/Models/ModelsWorker/Comment.cs rename to HardwareShop/HardwareShopDatabaseImplement/Models/Worker/Comment.cs index 36bbe96..5306cbc 100644 --- a/HardwareShop/HardwareShopDatabaseImplement/Models/ModelsWorker/Comment.cs +++ b/HardwareShop/HardwareShopDatabaseImplement/Models/Worker/Comment.cs @@ -4,7 +4,7 @@ using HardwareShopDataModels.Models; using System.ComponentModel; using System.ComponentModel.DataAnnotations; -namespace HardwareShopDatabaseImplement.Models.ModelsWorker +namespace HardwareShopDatabaseImplement.Models.Worker { public class Comment : ICommentModel { @@ -14,7 +14,7 @@ namespace HardwareShopDatabaseImplement.Models.ModelsWorker public string Text { get; set; } = string.Empty; [Required] - public int BuildID { get; set; } + public int BuildId { get; set; } public virtual Build Build { get; set; } @@ -28,7 +28,7 @@ namespace HardwareShopDatabaseImplement.Models.ModelsWorker { Id = model.Id, Text = model.Text, - BuildID = model.BuildID + BuildId = model.BuildId }; } public void Update(CommentBindingModel? model) @@ -43,7 +43,7 @@ namespace HardwareShopDatabaseImplement.Models.ModelsWorker { Id = Id, Text = Text, - BuildID = BuildID, + BuildId = BuildId, BuildName = Build.BuildName }; } diff --git a/HardwareShop/HardwareShopDatabaseImplement/Models/ModelsWorker/Purchase.cs b/HardwareShop/HardwareShopDatabaseImplement/Models/Worker/Purchase.cs similarity index 88% rename from HardwareShop/HardwareShopDatabaseImplement/Models/ModelsWorker/Purchase.cs rename to HardwareShop/HardwareShopDatabaseImplement/Models/Worker/Purchase.cs index 6263bcb..7fd502c 100644 --- a/HardwareShop/HardwareShopDatabaseImplement/Models/ModelsWorker/Purchase.cs +++ b/HardwareShop/HardwareShopDatabaseImplement/Models/Worker/Purchase.cs @@ -1,12 +1,12 @@ using HardwareShopContracts.BindingModels; using HardwareShopContracts.ViewModels; -using HardwareShopDatabaseImplement.Models.ModelsManyToMany; +using HardwareShopDatabaseImplement.Models.ManyToMany; using HardwareShopDataModels.Enums; using HardwareShopDataModels.Models; using System.ComponentModel.DataAnnotations.Schema; using System.Diagnostics; -namespace HardwareShopDatabaseImplement.Models.ModelsWorker +namespace HardwareShopDatabaseImplement.Models.Worker { public class Purchase : IPurchaseModel { @@ -18,7 +18,7 @@ namespace HardwareShopDatabaseImplement.Models.ModelsWorker public DateTime? DatePurchase { get; set; } - public int UserID { get; set; } + public int UserId { get; set; } public virtual User User { get; set; } @@ -34,7 +34,7 @@ namespace HardwareShopDatabaseImplement.Models.ModelsWorker { if (_purchaseBuilds == null) { - _purchaseBuilds = Builds.ToDictionary(recPB => recPB.BuildID, recPB => (recPB.Build as IBuildModel, recPB.Count)); + _purchaseBuilds = Builds.ToDictionary(recPB => recPB.BuildId, recPB => (recPB.Build as IBuildModel, recPB.Count)); } return _purchaseBuilds; } @@ -51,7 +51,7 @@ namespace HardwareShopDatabaseImplement.Models.ModelsWorker { if (_purchaseGoods == null) { - _purchaseGoods = Goods.ToDictionary(recPG => recPG.GoodID, recPG => (recPG.Good as IGoodModel, recPG.Count)); + _purchaseGoods = Goods.ToDictionary(recPG => recPG.GoodId, recPG => (recPG.Good as IGoodModel, recPG.Count)); } return _purchaseGoods; } @@ -65,7 +65,7 @@ namespace HardwareShopDatabaseImplement.Models.ModelsWorker Sum = model.Sum, PurchaseStatus = model.PurchaseStatus, DatePurchase = model.DatePurchase, - UserID = model.UserID, + UserId = model.UserId, Builds = model.PurchaseBuilds.Select(x => new PurchaseBuild { Build = context.Builds.First(y => y.Id == x.Key), @@ -91,7 +91,7 @@ namespace HardwareShopDatabaseImplement.Models.ModelsWorker Sum = Sum, PurchaseStatus = PurchaseStatus, DatePurchase = DatePurchase, - UserID = UserID, + UserId = UserId, UserEmail = User.Email, PurchaseBuilds = PurchaseBuilds, PurchaseGoods = PurchaseGoods @@ -99,15 +99,15 @@ namespace HardwareShopDatabaseImplement.Models.ModelsWorker public void UpdateBuilds(HardwareShopDatabase context, PurchaseBindingModel model) { - var purchaseBuilds = context.PurchasesBuilds.Where(rec => rec.PurchaseID == model.Id).ToList(); + var purchaseBuilds = context.PurchasesBuilds.Where(rec => rec.PurchaseId == model.Id).ToList(); if (purchaseBuilds != null && purchaseBuilds.Count > 0) { - context.PurchasesBuilds.RemoveRange(purchaseBuilds.Where(rec => !model.PurchaseBuilds.ContainsKey(rec.BuildID))); + context.PurchasesBuilds.RemoveRange(purchaseBuilds.Where(rec => !model.PurchaseBuilds.ContainsKey(rec.BuildId))); context.SaveChanges(); foreach (var updateBuild in purchaseBuilds) { - updateBuild.Count = model.PurchaseBuilds[updateBuild.BuildID].Item2; - model.PurchaseBuilds.Remove(updateBuild.BuildID); + updateBuild.Count = model.PurchaseBuilds[updateBuild.BuildId].Item2; + model.PurchaseBuilds.Remove(updateBuild.BuildId); } context.SaveChanges(); } @@ -127,16 +127,16 @@ namespace HardwareShopDatabaseImplement.Models.ModelsWorker public void UpdateGoods(HardwareShopDatabase context, PurchaseBindingModel model) { - var purchaseGoods = context.PurchasesGoods.Where(rec => rec.PurchaseID == model.Id).ToList(); + var purchaseGoods = context.PurchasesGoods.Where(rec => rec.PurchaseId == model.Id).ToList(); if (purchaseGoods != null && purchaseGoods.Count > 0) { // удалили те в бд, которых нет в модели - context.PurchasesGoods.RemoveRange(purchaseGoods.Where(rec => !model.PurchaseGoods.ContainsKey(rec.GoodID))); + context.PurchasesGoods.RemoveRange(purchaseGoods.Where(rec => !model.PurchaseGoods.ContainsKey(rec.GoodId))); context.SaveChanges(); // обновили количество у существующих записей foreach (var updateGood in purchaseGoods) { - updateGood.Count = model.PurchaseGoods[updateGood.GoodID].Item2; - model.PurchaseGoods.Remove(updateGood.GoodID); + updateGood.Count = model.PurchaseGoods[updateGood.GoodId].Item2; + model.PurchaseGoods.Remove(updateGood.GoodId); } context.SaveChanges(); }