From 879d0d858b00b4e56a7b4c3a3928f9765a1b55d7 Mon Sep 17 00:00:00 2001 From: dasha Date: Sat, 8 Apr 2023 16:56:53 +0400 Subject: [PATCH] =?UTF-8?q?=D0=9F=D1=80=D0=BE=D0=BC=D0=B5=D0=B6=D1=83?= =?UTF-8?q?=D1=82=D0=BE=D1=87=D0=BD=D1=8B=D0=B5=20=D0=B8=D0=B7=D0=BC=D0=B5?= =?UTF-8?q?=D0=BD=D0=B5=D0=BD=D0=B8=D1=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Storekeeper/ReportStorekeeperLogic.cs | 8 ++++---- .../BusinessLogics/Worker/WorkerReportLogic.cs | 8 +------- .../BindingModels/BuildBindingModel.cs | 2 +- .../BindingModels/CommentBindingModel.cs | 1 - .../BindingModels/GoodBindingModel.cs | 8 ++++---- .../BindingModels/PurchaseBindingModel.cs | 2 +- .../BindingModels/UserBindingModel.cs | 4 ++-- .../BusinessLogicsContracts/IUserLogic.cs | 4 ---- .../SearchModels/BuildSearchModel.cs | 3 +-- .../SearchModels/CommentSearchModel.cs | 5 +---- .../SearchModels/OrderSearchModel.cs | 2 -- .../SearchModels/PurchaseSearchModel.cs | 6 +----- .../SearchModels/UserSearchModel.cs | 9 +-------- .../StoragesContracts/ICommentStorage.cs | 5 ----- .../StoragesContracts/IPurchaseStorage.cs | 1 - .../ViewModels/OrderViewModel.cs | 10 +++++----- .../ViewModels/ReportBuildGoodViewModel.cs | 14 +++++++------- .../ViewModels/ReportComponentsViewModel.cs | 4 ++-- .../ReportPurchaseComponentViewModel.cs | 8 +------- .../ViewModels/ReportPurchaseViewModel.cs | 8 +------- .../ViewModels/UserViewModel.cs | 4 ++-- .../Models/IBuildModel.cs | 9 +-------- .../Models/ICommentModel.cs | 8 +------- .../HardwareShopDatabase.cs | 3 ++- .../Implements/Storekeeper/OrderStorage.cs | 18 +++++++++--------- .../Implements/Worker/BuildStorage.cs | 2 +- .../Implements/Worker/PurchaseStorage.cs | 6 ++---- .../Migrations/20230408110229_Init.cs | 3 +-- .../Models/Storekeeper/Good.cs | 2 +- .../Models/User.cs | 10 +++++----- .../Models/Worker/Build.cs | 13 +++++-------- .../Models/Worker/Comment.cs | 5 +---- .../Models/Worker/Purchase.cs | 8 +++----- 33 files changed, 67 insertions(+), 136 deletions(-) diff --git a/HardwareShop/HardwareShopBusinessLogic/BusinessLogics/Storekeeper/ReportStorekeeperLogic.cs b/HardwareShop/HardwareShopBusinessLogic/BusinessLogics/Storekeeper/ReportStorekeeperLogic.cs index e10369e..1f7237a 100644 --- a/HardwareShop/HardwareShopBusinessLogic/BusinessLogics/Storekeeper/ReportStorekeeperLogic.cs +++ b/HardwareShop/HardwareShopBusinessLogic/BusinessLogics/Storekeeper/ReportStorekeeperLogic.cs @@ -5,7 +5,7 @@ using HardwareShopContracts.ViewModels; namespace HardwareShopBusinessLogic.BusinessLogics.Storekeeper { - public class ReportStorekeeperLogic : IReportStorekeeperLogic + public class ReportStorekeeperLogic : IReportStorekeeperLogic { private readonly IComponentStorage _componentStorage; @@ -39,9 +39,9 @@ namespace HardwareShopBusinessLogic.BusinessLogics.Storekeeper /// Получение сведений по комплектующим за период, /// с указанием в каких товарах и сборках они использовались public List GetComponents(UserBindingModel user, ReportBindingModel model) - { + { var result = new List(); - var components = _componentStorage.GetFilteredList(new() + var components = _componentStorage.GetFilteredList(new() { UserId = user.Id, DateFrom = model.DateFrom, @@ -69,5 +69,5 @@ namespace HardwareShopBusinessLogic.BusinessLogics.Storekeeper } return result; } - } + } } diff --git a/HardwareShop/HardwareShopBusinessLogic/BusinessLogics/Worker/WorkerReportLogic.cs b/HardwareShop/HardwareShopBusinessLogic/BusinessLogics/Worker/WorkerReportLogic.cs index f228690..f4931b7 100644 --- a/HardwareShop/HardwareShopBusinessLogic/BusinessLogics/Worker/WorkerReportLogic.cs +++ b/HardwareShop/HardwareShopBusinessLogic/BusinessLogics/Worker/WorkerReportLogic.cs @@ -3,12 +3,6 @@ using HardwareShopContracts.BindingModels; using HardwareShopContracts.SearchModels; using HardwareShopContracts.StoragesContracts; using HardwareShopContracts.ViewModels; -using HardwareShopDatabaseImplement.Implements.Storekeeper; -using HardwareShopDatabaseImplement.Implements.Worker; -using HardwareShopDatabaseImplement.Models.Storekeeper; -using HardwareShopDatabaseImplement.Models.Worker; -using System.Collections.Generic; -using System.ComponentModel; namespace HardwareShopContracts.BusinessLogicsContracts { @@ -87,7 +81,7 @@ namespace HardwareShopContracts.BusinessLogicsContracts { componentList.Add(new(component.Value.Item1.ComponentName, component.Value.Item2)); } - record.Builds.Add(new (build.Value.Item1.BuildName, build.Value.Item2, commentList, componentList)); + record.Builds.Add(new(build.Value.Item1.BuildName, build.Value.Item2, commentList, componentList)); } list.Add(record); } diff --git a/HardwareShop/HardwareShopContracts/BindingModels/BuildBindingModel.cs b/HardwareShop/HardwareShopContracts/BindingModels/BuildBindingModel.cs index 2897d2e..6ab643e 100644 --- a/HardwareShop/HardwareShopContracts/BindingModels/BuildBindingModel.cs +++ b/HardwareShop/HardwareShopContracts/BindingModels/BuildBindingModel.cs @@ -1,5 +1,5 @@ using HardwareShopDataModels.Models; -using System.ComponentModel; + namespace HardwareShopContracts.BindingModels { public class BuildBindingModel : IBuildModel diff --git a/HardwareShop/HardwareShopContracts/BindingModels/CommentBindingModel.cs b/HardwareShop/HardwareShopContracts/BindingModels/CommentBindingModel.cs index a759df4..50754a4 100644 --- a/HardwareShop/HardwareShopContracts/BindingModels/CommentBindingModel.cs +++ b/HardwareShop/HardwareShopContracts/BindingModels/CommentBindingModel.cs @@ -1,5 +1,4 @@ using HardwareShopDataModels.Models; -using System.ComponentModel; namespace HardwareShopContracts.BindingModels { diff --git a/HardwareShop/HardwareShopContracts/BindingModels/GoodBindingModel.cs b/HardwareShop/HardwareShopContracts/BindingModels/GoodBindingModel.cs index 098d088..553d3ee 100644 --- a/HardwareShop/HardwareShopContracts/BindingModels/GoodBindingModel.cs +++ b/HardwareShop/HardwareShopContracts/BindingModels/GoodBindingModel.cs @@ -12,10 +12,10 @@ namespace HardwareShopContracts.BindingModels public int UserId { get; set; } - public Dictionary GoodComponents - { - get; - set; + public Dictionary GoodComponents + { + get; + set; } = new(); } } diff --git a/HardwareShop/HardwareShopContracts/BindingModels/PurchaseBindingModel.cs b/HardwareShop/HardwareShopContracts/BindingModels/PurchaseBindingModel.cs index 3a52f0f..cbabb52 100644 --- a/HardwareShop/HardwareShopContracts/BindingModels/PurchaseBindingModel.cs +++ b/HardwareShop/HardwareShopContracts/BindingModels/PurchaseBindingModel.cs @@ -1,6 +1,6 @@ using HardwareShopDataModels.Enums; using HardwareShopDataModels.Models; -using System.ComponentModel; + namespace HardwareShopContracts.BindingModels { public class PurchaseBindingModel : IPurchaseModel diff --git a/HardwareShop/HardwareShopContracts/BindingModels/UserBindingModel.cs b/HardwareShop/HardwareShopContracts/BindingModels/UserBindingModel.cs index 74cf91e..4eb3c2a 100644 --- a/HardwareShop/HardwareShopContracts/BindingModels/UserBindingModel.cs +++ b/HardwareShop/HardwareShopContracts/BindingModels/UserBindingModel.cs @@ -1,5 +1,5 @@ -using HardwareShopDataModels.Models; -using HardwareShopDataModels.Enums; +using HardwareShopDataModels.Enums; +using HardwareShopDataModels.Models; namespace HardwareShopContracts.BindingModels { diff --git a/HardwareShop/HardwareShopContracts/BusinessLogicsContracts/IUserLogic.cs b/HardwareShop/HardwareShopContracts/BusinessLogicsContracts/IUserLogic.cs index ced688a..b9a15b2 100644 --- a/HardwareShop/HardwareShopContracts/BusinessLogicsContracts/IUserLogic.cs +++ b/HardwareShop/HardwareShopContracts/BusinessLogicsContracts/IUserLogic.cs @@ -7,13 +7,9 @@ namespace HardwareShopContracts.BusinessLogicsContracts public interface IUserLogic { List? ReadList(UserSearchModel? model); - UserViewModel? ReadElement(UserSearchModel model); - bool Create(UserBindingModel model); - bool Update(UserBindingModel model); - bool Delete(UserBindingModel model); } } \ No newline at end of file diff --git a/HardwareShop/HardwareShopContracts/SearchModels/BuildSearchModel.cs b/HardwareShop/HardwareShopContracts/SearchModels/BuildSearchModel.cs index 3d5caee..e42cdaf 100644 --- a/HardwareShop/HardwareShopContracts/SearchModels/BuildSearchModel.cs +++ b/HardwareShop/HardwareShopContracts/SearchModels/BuildSearchModel.cs @@ -1,5 +1,4 @@ -using System.ComponentModel; -namespace HardwareShopContracts.SearchModels +namespace HardwareShopContracts.SearchModels { public class BuildSearchModel { diff --git a/HardwareShop/HardwareShopContracts/SearchModels/CommentSearchModel.cs b/HardwareShop/HardwareShopContracts/SearchModels/CommentSearchModel.cs index 2c82c3e..5a0ecaf 100644 --- a/HardwareShop/HardwareShopContracts/SearchModels/CommentSearchModel.cs +++ b/HardwareShop/HardwareShopContracts/SearchModels/CommentSearchModel.cs @@ -1,7 +1,4 @@ - -using System.ComponentModel; - -namespace HardwareShopContracts.SearchModels +namespace HardwareShopContracts.SearchModels { public class CommentSearchModel { diff --git a/HardwareShop/HardwareShopContracts/SearchModels/OrderSearchModel.cs b/HardwareShop/HardwareShopContracts/SearchModels/OrderSearchModel.cs index b701f9b..6b3bd09 100644 --- a/HardwareShop/HardwareShopContracts/SearchModels/OrderSearchModel.cs +++ b/HardwareShop/HardwareShopContracts/SearchModels/OrderSearchModel.cs @@ -3,8 +3,6 @@ public class OrderSearchModel { public int? Id { get; set; } - public DateTime? DateFrom { get; set; } - public DateTime? DateTo { get; set; } public int? UserId { get; set; } } } diff --git a/HardwareShop/HardwareShopContracts/SearchModels/PurchaseSearchModel.cs b/HardwareShop/HardwareShopContracts/SearchModels/PurchaseSearchModel.cs index 00897a1..baa5b71 100644 --- a/HardwareShop/HardwareShopContracts/SearchModels/PurchaseSearchModel.cs +++ b/HardwareShop/HardwareShopContracts/SearchModels/PurchaseSearchModel.cs @@ -1,18 +1,14 @@  using HardwareShopDataModels.Enums; -using System.ComponentModel; + namespace HardwareShopContracts.SearchModels { public class PurchaseSearchModel { public int? Id { get; set; } - public int? UserId { get; set; } - public PurchaseStatus? PurchaseStatus { get; set; } - public DateTime? DateFrom { get; set; } - public DateTime? DateTo { get; set; } } } diff --git a/HardwareShop/HardwareShopContracts/SearchModels/UserSearchModel.cs b/HardwareShop/HardwareShopContracts/SearchModels/UserSearchModel.cs index 12b7779..c2e6def 100644 --- a/HardwareShop/HardwareShopContracts/SearchModels/UserSearchModel.cs +++ b/HardwareShop/HardwareShopContracts/SearchModels/UserSearchModel.cs @@ -1,17 +1,10 @@ -using HardwareShopDataModels.Enums; - -namespace HardwareShopContracts.SearchModels +namespace HardwareShopContracts.SearchModels { public class UserSearchModel { public int? Id { get; set; } - public string? Login { get; set; } = string.Empty; - public string? Email { get; set; } = string.Empty; - public string? Password { get; set; } = string.Empty; - - public UserRole? Role { get; set; } = UserRole.Неизвестен; } } \ No newline at end of file diff --git a/HardwareShop/HardwareShopContracts/StoragesContracts/ICommentStorage.cs b/HardwareShop/HardwareShopContracts/StoragesContracts/ICommentStorage.cs index 66ffe52..1358c16 100644 --- a/HardwareShop/HardwareShopContracts/StoragesContracts/ICommentStorage.cs +++ b/HardwareShop/HardwareShopContracts/StoragesContracts/ICommentStorage.cs @@ -7,15 +7,10 @@ namespace HardwareShopContracts.StoragesContracts public interface ICommentStorage { List GetFullList(); - List GetFilteredList(CommentSearchModel model); - CommentViewModel? GetElement(CommentSearchModel model); - CommentViewModel? Insert(CommentBindingModel model); - CommentViewModel? Update(CommentBindingModel model); - CommentViewModel? Delete(CommentBindingModel model); } } \ No newline at end of file diff --git a/HardwareShop/HardwareShopContracts/StoragesContracts/IPurchaseStorage.cs b/HardwareShop/HardwareShopContracts/StoragesContracts/IPurchaseStorage.cs index 50a1ad4..7a60b86 100644 --- a/HardwareShop/HardwareShopContracts/StoragesContracts/IPurchaseStorage.cs +++ b/HardwareShop/HardwareShopContracts/StoragesContracts/IPurchaseStorage.cs @@ -1,7 +1,6 @@ using HardwareShopContracts.BindingModels; using HardwareShopContracts.SearchModels; using HardwareShopContracts.ViewModels; -using HardwareShopDataModels.Models; namespace HardwareShopContracts.StoragesContracts { diff --git a/HardwareShop/HardwareShopContracts/ViewModels/OrderViewModel.cs b/HardwareShop/HardwareShopContracts/ViewModels/OrderViewModel.cs index dd9f359..147faa7 100644 --- a/HardwareShop/HardwareShopContracts/ViewModels/OrderViewModel.cs +++ b/HardwareShop/HardwareShopContracts/ViewModels/OrderViewModel.cs @@ -13,14 +13,14 @@ namespace HardwareShopContracts.ViewModels [DisplayName("Товар")] public string GoodName { get; set; } = string.Empty; [DisplayName("Количество")] - public int Count{ get; set; } + public int Count { get; set; } [DisplayName("Сумма")] - public double Sum{ get; set; } + public double Sum { get; set; } [DisplayName("Статус")] - public OrderStatus Status{ get; set; } + public OrderStatus Status { get; set; } [DisplayName("Дата создания")] - public DateTime DateCreate{ get; set; } + public DateTime DateCreate { get; set; } [DisplayName("Дата выполнения")] - public DateTime? DateImplement{ get; set; } + public DateTime? DateImplement { get; set; } } } diff --git a/HardwareShop/HardwareShopContracts/ViewModels/ReportBuildGoodViewModel.cs b/HardwareShop/HardwareShopContracts/ViewModels/ReportBuildGoodViewModel.cs index 5bb6a22..51bee1c 100644 --- a/HardwareShop/HardwareShopContracts/ViewModels/ReportBuildGoodViewModel.cs +++ b/HardwareShop/HardwareShopContracts/ViewModels/ReportBuildGoodViewModel.cs @@ -1,12 +1,12 @@ namespace HardwareShopContracts.ViewModels { - public class ReportBuildGoodViewModel - { - public string GoodName { get; set; } = string.Empty; + public class ReportBuildGoodViewModel + { + public string GoodName { get; set; } = string.Empty; public List Builds - { - get; - set; - } = new(); + { + get; + set; + } = new(); } } diff --git a/HardwareShop/HardwareShopContracts/ViewModels/ReportComponentsViewModel.cs b/HardwareShop/HardwareShopContracts/ViewModels/ReportComponentsViewModel.cs index 634f0e0..9c01ffc 100644 --- a/HardwareShop/HardwareShopContracts/ViewModels/ReportComponentsViewModel.cs +++ b/HardwareShop/HardwareShopContracts/ViewModels/ReportComponentsViewModel.cs @@ -1,7 +1,7 @@ namespace HardwareShopContracts.ViewModels { - public class ReportComponentsViewModel - { + public class ReportComponentsViewModel + { public string ComponentName { get; set; } = string.Empty; public int TotalCount { get; set; } diff --git a/HardwareShop/HardwareShopContracts/ViewModels/ReportPurchaseComponentViewModel.cs b/HardwareShop/HardwareShopContracts/ViewModels/ReportPurchaseComponentViewModel.cs index 1bb327e..badd778 100644 --- a/HardwareShop/HardwareShopContracts/ViewModels/ReportPurchaseComponentViewModel.cs +++ b/HardwareShop/HardwareShopContracts/ViewModels/ReportPurchaseComponentViewModel.cs @@ -1,10 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace HardwareShopContracts.ViewModels +namespace HardwareShopContracts.ViewModels { public class ReportPurchaseComponentViewModel { diff --git a/HardwareShop/HardwareShopContracts/ViewModels/ReportPurchaseViewModel.cs b/HardwareShop/HardwareShopContracts/ViewModels/ReportPurchaseViewModel.cs index ec1fb2f..b39605d 100644 --- a/HardwareShop/HardwareShopContracts/ViewModels/ReportPurchaseViewModel.cs +++ b/HardwareShop/HardwareShopContracts/ViewModels/ReportPurchaseViewModel.cs @@ -1,10 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace HardwareShopContracts.ViewModels +namespace HardwareShopContracts.ViewModels { public class ReportPurchaseViewModel { diff --git a/HardwareShop/HardwareShopContracts/ViewModels/UserViewModel.cs b/HardwareShop/HardwareShopContracts/ViewModels/UserViewModel.cs index 2a486c6..bb9f785 100644 --- a/HardwareShop/HardwareShopContracts/ViewModels/UserViewModel.cs +++ b/HardwareShop/HardwareShopContracts/ViewModels/UserViewModel.cs @@ -1,5 +1,5 @@ -using HardwareShopDataModels.Models; -using HardwareShopDataModels.Enums; +using HardwareShopDataModels.Enums; +using HardwareShopDataModels.Models; using System.ComponentModel; namespace HardwareShopContracts.ViewModels diff --git a/HardwareShop/HardwareShopDataModels/Models/IBuildModel.cs b/HardwareShop/HardwareShopDataModels/Models/IBuildModel.cs index 0327a66..c7fadee 100644 --- a/HardwareShop/HardwareShopDataModels/Models/IBuildModel.cs +++ b/HardwareShop/HardwareShopDataModels/Models/IBuildModel.cs @@ -1,11 +1,4 @@ -using HardwareShopDataModels.Enums; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace HardwareShopDataModels.Models +namespace HardwareShopDataModels.Models { public interface IBuildModel : IId { diff --git a/HardwareShop/HardwareShopDataModels/Models/ICommentModel.cs b/HardwareShop/HardwareShopDataModels/Models/ICommentModel.cs index 34c055c..f4241b9 100644 --- a/HardwareShop/HardwareShopDataModels/Models/ICommentModel.cs +++ b/HardwareShop/HardwareShopDataModels/Models/ICommentModel.cs @@ -1,10 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace HardwareShopDataModels.Models +namespace HardwareShopDataModels.Models { public interface ICommentModel : IId { diff --git a/HardwareShop/HardwareShopDatabaseImplement/HardwareShopDatabase.cs b/HardwareShop/HardwareShopDatabaseImplement/HardwareShopDatabase.cs index ead5724..5bb2507 100644 --- a/HardwareShop/HardwareShopDatabaseImplement/HardwareShopDatabase.cs +++ b/HardwareShop/HardwareShopDatabaseImplement/HardwareShopDatabase.cs @@ -21,7 +21,8 @@ namespace HardwareShopDatabaseImplement modelBuilder.Entity().HasKey(x => new { x.PurchaseId, x.GoodId }); modelBuilder.Entity().HasKey(x => new { x.GoodId, x.ComponentId }); - modelBuilder.Entity(entity => { + modelBuilder.Entity(entity => + { entity.HasIndex(e => e.Login).IsUnique(); entity.HasIndex(e => e.Email).IsUnique(); }); diff --git a/HardwareShop/HardwareShopDatabaseImplement/Implements/Storekeeper/OrderStorage.cs b/HardwareShop/HardwareShopDatabaseImplement/Implements/Storekeeper/OrderStorage.cs index ce13a4a..da290fb 100644 --- a/HardwareShop/HardwareShopDatabaseImplement/Implements/Storekeeper/OrderStorage.cs +++ b/HardwareShop/HardwareShopDatabaseImplement/Implements/Storekeeper/OrderStorage.cs @@ -39,16 +39,16 @@ namespace HardwareShopDatabaseImplement.Implements.Storekeeper public List GetFilteredList(OrderSearchModel model) { - if (!model.Id.HasValue) - { - return new(); - } using var context = new HardwareShopDatabase(); - return context.Orders - .Include(x => x.Good) - .Where(x => x.Id == model.Id) - .Select(x => x.GetViewModel) - .ToList(); + if (model.UserId.HasValue) + { + return context.Orders + .Include(x => x.Good) + .Where(x => x.UserId == model.UserId) + .Select(x => x.GetViewModel) + .ToList(); + } + return new(); } public List GetFullList() diff --git a/HardwareShop/HardwareShopDatabaseImplement/Implements/Worker/BuildStorage.cs b/HardwareShop/HardwareShopDatabaseImplement/Implements/Worker/BuildStorage.cs index 34e12c6..33fa8e3 100644 --- a/HardwareShop/HardwareShopDatabaseImplement/Implements/Worker/BuildStorage.cs +++ b/HardwareShop/HardwareShopDatabaseImplement/Implements/Worker/BuildStorage.cs @@ -57,7 +57,7 @@ namespace HardwareShopDatabaseImplement.Implements.Worker .Include(x => x.Purchases) .ThenInclude(x => x.Purchase) .Where(x => x.Id == model.Id) - .FirstOrDefault(x => (!string.IsNullOrEmpty(model.BuildName) && x.BuildName == model.BuildName) || + .FirstOrDefault(x => (!string.IsNullOrEmpty(model.BuildName) && x.BuildName == model.BuildName) || (model.Id.HasValue && x.Id == model.Id)) ?.GetViewModel; } diff --git a/HardwareShop/HardwareShopDatabaseImplement/Implements/Worker/PurchaseStorage.cs b/HardwareShop/HardwareShopDatabaseImplement/Implements/Worker/PurchaseStorage.cs index 1a11fe8..513349f 100644 --- a/HardwareShop/HardwareShopDatabaseImplement/Implements/Worker/PurchaseStorage.cs +++ b/HardwareShop/HardwareShopDatabaseImplement/Implements/Worker/PurchaseStorage.cs @@ -2,9 +2,7 @@ using HardwareShopContracts.SearchModels; using HardwareShopContracts.StoragesContracts; using HardwareShopContracts.ViewModels; -using HardwareShopDatabaseImplement.Models.ManyToMany; using HardwareShopDatabaseImplement.Models.Worker; -using HardwareShopDataModels.Models; using Microsoft.EntityFrameworkCore; namespace HardwareShopDatabaseImplement.Implements.Worker @@ -34,7 +32,7 @@ namespace HardwareShopDatabaseImplement.Implements.Worker .Include(x => x.Builds) .ThenInclude(x => x.Build) .ThenInclude(x => x.Comments) - .Where(x => x.UserId == model.UserId && x.DatePurchase >= model.DateFrom && x.DatePurchase <= model.DateTo ) + .Where(x => x.UserId == model.UserId && x.DatePurchase >= model.DateFrom && x.DatePurchase <= model.DateTo) .Select(x => x.GetViewModel) .ToList(); } @@ -60,7 +58,7 @@ namespace HardwareShopDatabaseImplement.Implements.Worker using var context = new HardwareShopDatabase(); if (!model.UserId.HasValue) { - return null; + return new(); } return context.Purchases .Include(x => x.Builds) diff --git a/HardwareShop/HardwareShopDatabaseImplement/Migrations/20230408110229_Init.cs b/HardwareShop/HardwareShopDatabaseImplement/Migrations/20230408110229_Init.cs index 9b4fbf8..03137de 100644 --- a/HardwareShop/HardwareShopDatabaseImplement/Migrations/20230408110229_Init.cs +++ b/HardwareShop/HardwareShopDatabaseImplement/Migrations/20230408110229_Init.cs @@ -1,5 +1,4 @@ -using System; -using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Migrations; using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; #nullable disable diff --git a/HardwareShop/HardwareShopDatabaseImplement/Models/Storekeeper/Good.cs b/HardwareShop/HardwareShopDatabaseImplement/Models/Storekeeper/Good.cs index 0914995..69089c2 100644 --- a/HardwareShop/HardwareShopDatabaseImplement/Models/Storekeeper/Good.cs +++ b/HardwareShop/HardwareShopDatabaseImplement/Models/Storekeeper/Good.cs @@ -32,7 +32,7 @@ namespace HardwareShopDatabaseImplement.Models.Storekeeper public virtual List Purchases { get; set; } = new(); [NotMapped] - public Dictionary GoodComponents + public Dictionary GoodComponents { get { diff --git a/HardwareShop/HardwareShopDatabaseImplement/Models/User.cs b/HardwareShop/HardwareShopDatabaseImplement/Models/User.cs index 8057cfb..69f878a 100644 --- a/HardwareShop/HardwareShopDatabaseImplement/Models/User.cs +++ b/HardwareShop/HardwareShopDatabaseImplement/Models/User.cs @@ -1,11 +1,11 @@ -using HardwareShopDataModels.Models; -using HardwareShopDataModels.Enums; -using HardwareShopContracts.BindingModels; +using HardwareShopContracts.BindingModels; using HardwareShopContracts.ViewModels; using HardwareShopDatabaseImplement.Models.Storekeeper; -using System.ComponentModel.DataAnnotations.Schema; -using System.ComponentModel.DataAnnotations; using HardwareShopDatabaseImplement.Models.Worker; +using HardwareShopDataModels.Enums; +using HardwareShopDataModels.Models; +using System.ComponentModel.DataAnnotations; +using System.ComponentModel.DataAnnotations.Schema; namespace HardwareShopDatabaseImplement.Models { diff --git a/HardwareShop/HardwareShopDatabaseImplement/Models/Worker/Build.cs b/HardwareShop/HardwareShopDatabaseImplement/Models/Worker/Build.cs index 4a944b9..2c5c742 100644 --- a/HardwareShop/HardwareShopDatabaseImplement/Models/Worker/Build.cs +++ b/HardwareShop/HardwareShopDatabaseImplement/Models/Worker/Build.cs @@ -4,7 +4,6 @@ using HardwareShopDatabaseImplement.Models.ManyToMany; using HardwareShopDataModels.Models; using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations.Schema; -using System.Diagnostics; namespace HardwareShopDatabaseImplement.Models.Worker { @@ -21,19 +20,16 @@ namespace HardwareShopDatabaseImplement.Models.Worker [Required] public int UserId { get; set; } - public virtual User User { get; set; } - [ForeignKey("BuildId")] public virtual List Comments { get; set; } = new(); [ForeignKey("BuildId")] public virtual List Components { get; set; } = new(); - [ForeignKey("BuildId")] public virtual List Purchases { get; set; } = new(); - private Dictionary _buildComments = null; + private Dictionary _buildComments = null!; [NotMapped] public Dictionary BuildComments @@ -42,13 +38,13 @@ namespace HardwareShopDatabaseImplement.Models.Worker { if (_buildComments == null) { - _buildComments = Comments.ToDictionary(recBC=> recBC.Id, recBC => recBC as ICommentModel); + _buildComments = Comments.ToDictionary(recBC => recBC.Id, recBC => recBC as ICommentModel); } return _buildComments; } } - private Dictionary? _buildComponents = null; + private Dictionary _buildComponents = null!; [NotMapped] public Dictionary BuildComponents @@ -63,7 +59,7 @@ namespace HardwareShopDatabaseImplement.Models.Worker } } - private Dictionary? _buildPurchases = null; + private Dictionary _buildPurchases = null!; [NotMapped] public Dictionary BuildPurchases @@ -113,6 +109,7 @@ namespace HardwareShopDatabaseImplement.Models.Worker { // удалили те в бд, которых нет в модели context.PurchasesBuilds.RemoveRange(buildPurchases.Where(rec => !model.BuildPurchases.ContainsKey(rec.PurchaseId))); context.SaveChanges(); + buildPurchases = context.PurchasesBuilds.Where(rec => rec.BuildId == model.Id).ToList(); // обновили количество у существующих записей foreach (var updateComponent in buildPurchases) { diff --git a/HardwareShop/HardwareShopDatabaseImplement/Models/Worker/Comment.cs b/HardwareShop/HardwareShopDatabaseImplement/Models/Worker/Comment.cs index cd529a9..4bcedbb 100644 --- a/HardwareShop/HardwareShopDatabaseImplement/Models/Worker/Comment.cs +++ b/HardwareShop/HardwareShopDatabaseImplement/Models/Worker/Comment.cs @@ -1,7 +1,6 @@ using HardwareShopContracts.BindingModels; using HardwareShopContracts.ViewModels; using HardwareShopDataModels.Models; -using System.ComponentModel; using System.ComponentModel.DataAnnotations; namespace HardwareShopDatabaseImplement.Models.Worker @@ -16,13 +15,11 @@ namespace HardwareShopDatabaseImplement.Models.Worker [Required] public int BuildId { get; set; } - public virtual Build Build { get; set; } + public virtual Build Build { get; set; } = null!; [Required] public int UserId { get; set; } - public virtual User User { get; set; } - public static Comment? Create(CommentBindingModel? model) { if (model == null) diff --git a/HardwareShop/HardwareShopDatabaseImplement/Models/Worker/Purchase.cs b/HardwareShop/HardwareShopDatabaseImplement/Models/Worker/Purchase.cs index 4f589cd..0a24f77 100644 --- a/HardwareShop/HardwareShopDatabaseImplement/Models/Worker/Purchase.cs +++ b/HardwareShop/HardwareShopDatabaseImplement/Models/Worker/Purchase.cs @@ -5,7 +5,6 @@ using HardwareShopDataModels.Enums; using HardwareShopDataModels.Models; using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations.Schema; -using System.Diagnostics; namespace HardwareShopDatabaseImplement.Models.Worker { @@ -24,15 +23,13 @@ namespace HardwareShopDatabaseImplement.Models.Worker [Required] public int UserId { get; set; } - public virtual User User { get; set; } - [ForeignKey("PurchaseId")] public virtual List Builds { get; set; } = new(); [ForeignKey("PurchaseId")] public virtual List Goods { get; set; } = new(); - private Dictionary? _purchaseGoods = null; + private Dictionary _purchaseGoods = null!; [NotMapped] public Dictionary PurchaseGoods @@ -47,7 +44,7 @@ namespace HardwareShopDatabaseImplement.Models.Worker } } - private Dictionary? _purchaseBuilds = null; + private Dictionary _purchaseBuilds = null!; [NotMapped] public Dictionary PurchaseBuilds @@ -104,6 +101,7 @@ namespace HardwareShopDatabaseImplement.Models.Worker { // удалили те в бд, которых нет в модели context.PurchasesGoods.RemoveRange(purchaseGoods.Where(rec => !model.PurchaseGoods.ContainsKey(rec.GoodId))); context.SaveChanges(); + purchaseGoods = context.PurchasesGoods.Where(rec => rec.PurchaseId == model.Id).ToList(); // обновили количество у существующих записей foreach (var updateGood in purchaseGoods) {