Промежуточные изменения

This commit is contained in:
dasha 2023-04-08 16:56:53 +04:00
parent 923d110e40
commit 879d0d858b
33 changed files with 67 additions and 136 deletions

View File

@ -3,12 +3,6 @@ using HardwareShopContracts.BindingModels;
using HardwareShopContracts.SearchModels; using HardwareShopContracts.SearchModels;
using HardwareShopContracts.StoragesContracts; using HardwareShopContracts.StoragesContracts;
using HardwareShopContracts.ViewModels; 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 namespace HardwareShopContracts.BusinessLogicsContracts
{ {
@ -87,7 +81,7 @@ namespace HardwareShopContracts.BusinessLogicsContracts
{ {
componentList.Add(new(component.Value.Item1.ComponentName, component.Value.Item2)); 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); list.Add(record);
} }

View File

@ -1,5 +1,5 @@
using HardwareShopDataModels.Models; using HardwareShopDataModels.Models;
using System.ComponentModel;
namespace HardwareShopContracts.BindingModels namespace HardwareShopContracts.BindingModels
{ {
public class BuildBindingModel : IBuildModel public class BuildBindingModel : IBuildModel

View File

@ -1,5 +1,4 @@
using HardwareShopDataModels.Models; using HardwareShopDataModels.Models;
using System.ComponentModel;
namespace HardwareShopContracts.BindingModels namespace HardwareShopContracts.BindingModels
{ {

View File

@ -1,6 +1,6 @@
using HardwareShopDataModels.Enums; using HardwareShopDataModels.Enums;
using HardwareShopDataModels.Models; using HardwareShopDataModels.Models;
using System.ComponentModel;
namespace HardwareShopContracts.BindingModels namespace HardwareShopContracts.BindingModels
{ {
public class PurchaseBindingModel : IPurchaseModel public class PurchaseBindingModel : IPurchaseModel

View File

@ -1,5 +1,5 @@
using HardwareShopDataModels.Models; using HardwareShopDataModels.Enums;
using HardwareShopDataModels.Enums; using HardwareShopDataModels.Models;
namespace HardwareShopContracts.BindingModels namespace HardwareShopContracts.BindingModels
{ {

View File

@ -7,13 +7,9 @@ namespace HardwareShopContracts.BusinessLogicsContracts
public interface IUserLogic public interface IUserLogic
{ {
List<UserViewModel>? ReadList(UserSearchModel? model); List<UserViewModel>? ReadList(UserSearchModel? model);
UserViewModel? ReadElement(UserSearchModel model); UserViewModel? ReadElement(UserSearchModel model);
bool Create(UserBindingModel model); bool Create(UserBindingModel model);
bool Update(UserBindingModel model); bool Update(UserBindingModel model);
bool Delete(UserBindingModel model); bool Delete(UserBindingModel model);
} }
} }

View File

@ -1,5 +1,4 @@
using System.ComponentModel; namespace HardwareShopContracts.SearchModels
namespace HardwareShopContracts.SearchModels
{ {
public class BuildSearchModel public class BuildSearchModel
{ {

View File

@ -1,7 +1,4 @@
 namespace HardwareShopContracts.SearchModels
using System.ComponentModel;
namespace HardwareShopContracts.SearchModels
{ {
public class CommentSearchModel public class CommentSearchModel
{ {

View File

@ -3,8 +3,6 @@
public class OrderSearchModel public class OrderSearchModel
{ {
public int? Id { get; set; } public int? Id { get; set; }
public DateTime? DateFrom { get; set; }
public DateTime? DateTo { get; set; }
public int? UserId { get; set; } public int? UserId { get; set; }
} }
} }

View File

@ -1,18 +1,14 @@
 
using HardwareShopDataModels.Enums; using HardwareShopDataModels.Enums;
using System.ComponentModel;
namespace HardwareShopContracts.SearchModels namespace HardwareShopContracts.SearchModels
{ {
public class PurchaseSearchModel public class PurchaseSearchModel
{ {
public int? Id { get; set; } public int? Id { get; set; }
public int? UserId { get; set; } public int? UserId { get; set; }
public PurchaseStatus? PurchaseStatus { get; set; } public PurchaseStatus? PurchaseStatus { get; set; }
public DateTime? DateFrom { get; set; } public DateTime? DateFrom { get; set; }
public DateTime? DateTo { get; set; } public DateTime? DateTo { get; set; }
} }
} }

View File

@ -1,17 +1,10 @@
using HardwareShopDataModels.Enums; namespace HardwareShopContracts.SearchModels
namespace HardwareShopContracts.SearchModels
{ {
public class UserSearchModel public class UserSearchModel
{ {
public int? Id { get; set; } public int? Id { get; set; }
public string? Login { get; set; } = string.Empty; public string? Login { get; set; } = string.Empty;
public string? Email { get; set; } = string.Empty; public string? Email { get; set; } = string.Empty;
public string? Password { get; set; } = string.Empty; public string? Password { get; set; } = string.Empty;
public UserRole? Role { get; set; } = UserRole.Неизвестен;
} }
} }

View File

@ -7,15 +7,10 @@ namespace HardwareShopContracts.StoragesContracts
public interface ICommentStorage public interface ICommentStorage
{ {
List<CommentViewModel> GetFullList(); List<CommentViewModel> GetFullList();
List<CommentViewModel> GetFilteredList(CommentSearchModel model); List<CommentViewModel> GetFilteredList(CommentSearchModel model);
CommentViewModel? GetElement(CommentSearchModel model); CommentViewModel? GetElement(CommentSearchModel model);
CommentViewModel? Insert(CommentBindingModel model); CommentViewModel? Insert(CommentBindingModel model);
CommentViewModel? Update(CommentBindingModel model); CommentViewModel? Update(CommentBindingModel model);
CommentViewModel? Delete(CommentBindingModel model); CommentViewModel? Delete(CommentBindingModel model);
} }
} }

View File

@ -1,7 +1,6 @@
using HardwareShopContracts.BindingModels; using HardwareShopContracts.BindingModels;
using HardwareShopContracts.SearchModels; using HardwareShopContracts.SearchModels;
using HardwareShopContracts.ViewModels; using HardwareShopContracts.ViewModels;
using HardwareShopDataModels.Models;
namespace HardwareShopContracts.StoragesContracts namespace HardwareShopContracts.StoragesContracts
{ {

View File

@ -13,14 +13,14 @@ namespace HardwareShopContracts.ViewModels
[DisplayName("Товар")] [DisplayName("Товар")]
public string GoodName { get; set; } = string.Empty; public string GoodName { get; set; } = string.Empty;
[DisplayName("Количество")] [DisplayName("Количество")]
public int Count{ get; set; } public int Count { get; set; }
[DisplayName("Сумма")] [DisplayName("Сумма")]
public double Sum{ get; set; } public double Sum { get; set; }
[DisplayName("Статус")] [DisplayName("Статус")]
public OrderStatus Status{ get; set; } public OrderStatus Status { get; set; }
[DisplayName("Дата создания")] [DisplayName("Дата создания")]
public DateTime DateCreate{ get; set; } public DateTime DateCreate { get; set; }
[DisplayName("Дата выполнения")] [DisplayName("Дата выполнения")]
public DateTime? DateImplement{ get; set; } public DateTime? DateImplement { get; set; }
} }
} }

View File

@ -1,10 +1,4 @@
using System; namespace HardwareShopContracts.ViewModels
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace HardwareShopContracts.ViewModels
{ {
public class ReportPurchaseComponentViewModel public class ReportPurchaseComponentViewModel
{ {

View File

@ -1,10 +1,4 @@
using System; namespace HardwareShopContracts.ViewModels
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace HardwareShopContracts.ViewModels
{ {
public class ReportPurchaseViewModel public class ReportPurchaseViewModel
{ {

View File

@ -1,5 +1,5 @@
using HardwareShopDataModels.Models; using HardwareShopDataModels.Enums;
using HardwareShopDataModels.Enums; using HardwareShopDataModels.Models;
using System.ComponentModel; using System.ComponentModel;
namespace HardwareShopContracts.ViewModels namespace HardwareShopContracts.ViewModels

View File

@ -1,11 +1,4 @@
using HardwareShopDataModels.Enums; namespace HardwareShopDataModels.Models
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace HardwareShopDataModels.Models
{ {
public interface IBuildModel : IId public interface IBuildModel : IId
{ {

View File

@ -1,10 +1,4 @@
using System; namespace HardwareShopDataModels.Models
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace HardwareShopDataModels.Models
{ {
public interface ICommentModel : IId public interface ICommentModel : IId
{ {

View File

@ -21,7 +21,8 @@ namespace HardwareShopDatabaseImplement
modelBuilder.Entity<PurchaseGood>().HasKey(x => new { x.PurchaseId, x.GoodId }); modelBuilder.Entity<PurchaseGood>().HasKey(x => new { x.PurchaseId, x.GoodId });
modelBuilder.Entity<GoodComponent>().HasKey(x => new { x.GoodId, x.ComponentId }); modelBuilder.Entity<GoodComponent>().HasKey(x => new { x.GoodId, x.ComponentId });
modelBuilder.Entity<User>(entity => { modelBuilder.Entity<User>(entity =>
{
entity.HasIndex(e => e.Login).IsUnique(); entity.HasIndex(e => e.Login).IsUnique();
entity.HasIndex(e => e.Email).IsUnique(); entity.HasIndex(e => e.Email).IsUnique();
}); });

View File

@ -39,17 +39,17 @@ namespace HardwareShopDatabaseImplement.Implements.Storekeeper
public List<OrderViewModel> GetFilteredList(OrderSearchModel model) public List<OrderViewModel> GetFilteredList(OrderSearchModel model)
{ {
if (!model.Id.HasValue)
{
return new();
}
using var context = new HardwareShopDatabase(); using var context = new HardwareShopDatabase();
if (model.UserId.HasValue)
{
return context.Orders return context.Orders
.Include(x => x.Good) .Include(x => x.Good)
.Where(x => x.Id == model.Id) .Where(x => x.UserId == model.UserId)
.Select(x => x.GetViewModel) .Select(x => x.GetViewModel)
.ToList(); .ToList();
} }
return new();
}
public List<OrderViewModel> GetFullList() public List<OrderViewModel> GetFullList()
{ {

View File

@ -2,9 +2,7 @@
using HardwareShopContracts.SearchModels; using HardwareShopContracts.SearchModels;
using HardwareShopContracts.StoragesContracts; using HardwareShopContracts.StoragesContracts;
using HardwareShopContracts.ViewModels; using HardwareShopContracts.ViewModels;
using HardwareShopDatabaseImplement.Models.ManyToMany;
using HardwareShopDatabaseImplement.Models.Worker; using HardwareShopDatabaseImplement.Models.Worker;
using HardwareShopDataModels.Models;
using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore;
namespace HardwareShopDatabaseImplement.Implements.Worker namespace HardwareShopDatabaseImplement.Implements.Worker
@ -34,7 +32,7 @@ namespace HardwareShopDatabaseImplement.Implements.Worker
.Include(x => x.Builds) .Include(x => x.Builds)
.ThenInclude(x => x.Build) .ThenInclude(x => x.Build)
.ThenInclude(x => x.Comments) .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) .Select(x => x.GetViewModel)
.ToList(); .ToList();
} }
@ -60,7 +58,7 @@ namespace HardwareShopDatabaseImplement.Implements.Worker
using var context = new HardwareShopDatabase(); using var context = new HardwareShopDatabase();
if (!model.UserId.HasValue) if (!model.UserId.HasValue)
{ {
return null; return new();
} }
return context.Purchases return context.Purchases
.Include(x => x.Builds) .Include(x => x.Builds)

View File

@ -1,5 +1,4 @@
using System; using Microsoft.EntityFrameworkCore.Migrations;
using Microsoft.EntityFrameworkCore.Migrations;
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
#nullable disable #nullable disable

View File

@ -1,11 +1,11 @@
using HardwareShopDataModels.Models; using HardwareShopContracts.BindingModels;
using HardwareShopDataModels.Enums;
using HardwareShopContracts.BindingModels;
using HardwareShopContracts.ViewModels; using HardwareShopContracts.ViewModels;
using HardwareShopDatabaseImplement.Models.Storekeeper; using HardwareShopDatabaseImplement.Models.Storekeeper;
using System.ComponentModel.DataAnnotations.Schema;
using System.ComponentModel.DataAnnotations;
using HardwareShopDatabaseImplement.Models.Worker; using HardwareShopDatabaseImplement.Models.Worker;
using HardwareShopDataModels.Enums;
using HardwareShopDataModels.Models;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
namespace HardwareShopDatabaseImplement.Models namespace HardwareShopDatabaseImplement.Models
{ {

View File

@ -4,7 +4,6 @@ using HardwareShopDatabaseImplement.Models.ManyToMany;
using HardwareShopDataModels.Models; using HardwareShopDataModels.Models;
using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema; using System.ComponentModel.DataAnnotations.Schema;
using System.Diagnostics;
namespace HardwareShopDatabaseImplement.Models.Worker namespace HardwareShopDatabaseImplement.Models.Worker
{ {
@ -21,19 +20,16 @@ namespace HardwareShopDatabaseImplement.Models.Worker
[Required] [Required]
public int UserId { get; set; } public int UserId { get; set; }
public virtual User User { get; set; }
[ForeignKey("BuildId")] [ForeignKey("BuildId")]
public virtual List<Comment> Comments { get; set; } = new(); public virtual List<Comment> Comments { get; set; } = new();
[ForeignKey("BuildId")] [ForeignKey("BuildId")]
public virtual List<ComponentBuild> Components { get; set; } = new(); public virtual List<ComponentBuild> Components { get; set; } = new();
[ForeignKey("BuildId")] [ForeignKey("BuildId")]
public virtual List<PurchaseBuild> Purchases { get; set; } = new(); public virtual List<PurchaseBuild> Purchases { get; set; } = new();
private Dictionary<int, ICommentModel> _buildComments = null; private Dictionary<int, ICommentModel> _buildComments = null!;
[NotMapped] [NotMapped]
public Dictionary<int, ICommentModel> BuildComments public Dictionary<int, ICommentModel> BuildComments
@ -42,13 +38,13 @@ namespace HardwareShopDatabaseImplement.Models.Worker
{ {
if (_buildComments == null) 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; return _buildComments;
} }
} }
private Dictionary<int, (IComponentModel, int)>? _buildComponents = null; private Dictionary<int, (IComponentModel, int)> _buildComponents = null!;
[NotMapped] [NotMapped]
public Dictionary<int, (IComponentModel, int)> BuildComponents public Dictionary<int, (IComponentModel, int)> BuildComponents
@ -63,7 +59,7 @@ namespace HardwareShopDatabaseImplement.Models.Worker
} }
} }
private Dictionary<int, (IPurchaseModel, int)>? _buildPurchases = null; private Dictionary<int, (IPurchaseModel, int)> _buildPurchases = null!;
[NotMapped] [NotMapped]
public Dictionary<int, (IPurchaseModel, int)> BuildPurchases public Dictionary<int, (IPurchaseModel, int)> BuildPurchases
@ -113,6 +109,7 @@ namespace HardwareShopDatabaseImplement.Models.Worker
{ // удалили те в бд, которых нет в модели { // удалили те в бд, которых нет в модели
context.PurchasesBuilds.RemoveRange(buildPurchases.Where(rec => !model.BuildPurchases.ContainsKey(rec.PurchaseId))); context.PurchasesBuilds.RemoveRange(buildPurchases.Where(rec => !model.BuildPurchases.ContainsKey(rec.PurchaseId)));
context.SaveChanges(); context.SaveChanges();
buildPurchases = context.PurchasesBuilds.Where(rec => rec.BuildId == model.Id).ToList();
// обновили количество у существующих записей // обновили количество у существующих записей
foreach (var updateComponent in buildPurchases) foreach (var updateComponent in buildPurchases)
{ {

View File

@ -1,7 +1,6 @@
using HardwareShopContracts.BindingModels; using HardwareShopContracts.BindingModels;
using HardwareShopContracts.ViewModels; using HardwareShopContracts.ViewModels;
using HardwareShopDataModels.Models; using HardwareShopDataModels.Models;
using System.ComponentModel;
using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations;
namespace HardwareShopDatabaseImplement.Models.Worker namespace HardwareShopDatabaseImplement.Models.Worker
@ -16,13 +15,11 @@ namespace HardwareShopDatabaseImplement.Models.Worker
[Required] [Required]
public int BuildId { get; set; } public int BuildId { get; set; }
public virtual Build Build { get; set; } public virtual Build Build { get; set; } = null!;
[Required] [Required]
public int UserId { get; set; } public int UserId { get; set; }
public virtual User User { get; set; }
public static Comment? Create(CommentBindingModel? model) public static Comment? Create(CommentBindingModel? model)
{ {
if (model == null) if (model == null)

View File

@ -5,7 +5,6 @@ using HardwareShopDataModels.Enums;
using HardwareShopDataModels.Models; using HardwareShopDataModels.Models;
using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema; using System.ComponentModel.DataAnnotations.Schema;
using System.Diagnostics;
namespace HardwareShopDatabaseImplement.Models.Worker namespace HardwareShopDatabaseImplement.Models.Worker
{ {
@ -24,15 +23,13 @@ namespace HardwareShopDatabaseImplement.Models.Worker
[Required] [Required]
public int UserId { get; set; } public int UserId { get; set; }
public virtual User User { get; set; }
[ForeignKey("PurchaseId")] [ForeignKey("PurchaseId")]
public virtual List<PurchaseBuild> Builds { get; set; } = new(); public virtual List<PurchaseBuild> Builds { get; set; } = new();
[ForeignKey("PurchaseId")] [ForeignKey("PurchaseId")]
public virtual List<PurchaseGood> Goods { get; set; } = new(); public virtual List<PurchaseGood> Goods { get; set; } = new();
private Dictionary<int, (IGoodModel, int)>? _purchaseGoods = null; private Dictionary<int, (IGoodModel, int)> _purchaseGoods = null!;
[NotMapped] [NotMapped]
public Dictionary<int, (IGoodModel, int)> PurchaseGoods public Dictionary<int, (IGoodModel, int)> PurchaseGoods
@ -47,7 +44,7 @@ namespace HardwareShopDatabaseImplement.Models.Worker
} }
} }
private Dictionary<int, (IBuildModel, int)>? _purchaseBuilds = null; private Dictionary<int, (IBuildModel, int)> _purchaseBuilds = null!;
[NotMapped] [NotMapped]
public Dictionary<int, (IBuildModel, int)> PurchaseBuilds public Dictionary<int, (IBuildModel, int)> PurchaseBuilds
@ -104,6 +101,7 @@ namespace HardwareShopDatabaseImplement.Models.Worker
{ // удалили те в бд, которых нет в модели { // удалили те в бд, которых нет в модели
context.PurchasesGoods.RemoveRange(purchaseGoods.Where(rec => !model.PurchaseGoods.ContainsKey(rec.GoodId))); context.PurchasesGoods.RemoveRange(purchaseGoods.Where(rec => !model.PurchaseGoods.ContainsKey(rec.GoodId)));
context.SaveChanges(); context.SaveChanges();
purchaseGoods = context.PurchasesGoods.Where(rec => rec.PurchaseId == model.Id).ToList();
// обновили количество у существующих записей // обновили количество у существующих записей
foreach (var updateGood in purchaseGoods) foreach (var updateGood in purchaseGoods)
{ {