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

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

@ -5,7 +5,7 @@ using HardwareShopContracts.ViewModels;
namespace HardwareShopBusinessLogic.BusinessLogics.Storekeeper
{
public class ReportStorekeeperLogic : IReportStorekeeperLogic
public class ReportStorekeeperLogic : IReportStorekeeperLogic
{
private readonly IComponentStorage _componentStorage;
@ -39,7 +39,7 @@ namespace HardwareShopBusinessLogic.BusinessLogics.Storekeeper
/// Получение сведений по комплектующим за период,
/// с указанием в каких товарах и сборках они использовались
public List<ReportComponentsViewModel> GetComponents(UserBindingModel user, ReportBindingModel model)
{
{
var result = new List<ReportComponentsViewModel>();
var components = _componentStorage.GetFilteredList(new()
{
@ -69,5 +69,5 @@ namespace HardwareShopBusinessLogic.BusinessLogics.Storekeeper
}
return result;
}
}
}
}

View File

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

View File

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

View File

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

View File

@ -1,6 +1,6 @@
using HardwareShopDataModels.Enums;
using HardwareShopDataModels.Models;
using System.ComponentModel;
namespace HardwareShopContracts.BindingModels
{
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
{

View File

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

View File

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

View File

@ -1,7 +1,4 @@

using System.ComponentModel;
namespace HardwareShopContracts.SearchModels
namespace HardwareShopContracts.SearchModels
{
public class CommentSearchModel
{

View File

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

View File

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

View File

@ -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.Неизвестен;
}
}

View File

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

View File

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

View File

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

View File

@ -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<string> Builds
{
get;
set;
} = new();
{
get;
set;
} = new();
}
}

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -21,7 +21,8 @@ namespace HardwareShopDatabaseImplement
modelBuilder.Entity<PurchaseGood>().HasKey(x => new { x.PurchaseId, x.GoodId });
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.Email).IsUnique();
});

View File

@ -39,16 +39,16 @@ namespace HardwareShopDatabaseImplement.Implements.Storekeeper
public List<OrderViewModel> 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<OrderViewModel> GetFullList()

View File

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

View File

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

View File

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

View File

@ -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<Comment> Comments { get; set; } = new();
[ForeignKey("BuildId")]
public virtual List<ComponentBuild> Components { get; set; } = new();
[ForeignKey("BuildId")]
public virtual List<PurchaseBuild> Purchases { get; set; } = new();
private Dictionary<int, ICommentModel> _buildComments = null;
private Dictionary<int, ICommentModel> _buildComments = null!;
[NotMapped]
public Dictionary<int, ICommentModel> 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<int, (IComponentModel, int)>? _buildComponents = null;
private Dictionary<int, (IComponentModel, int)> _buildComponents = null!;
[NotMapped]
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]
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.SaveChanges();
buildPurchases = context.PurchasesBuilds.Where(rec => rec.BuildId == model.Id).ToList();
// обновили количество у существующих записей
foreach (var updateComponent in buildPurchases)
{

View File

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

View File

@ -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<PurchaseBuild> Builds { get; set; } = new();
[ForeignKey("PurchaseId")]
public virtual List<PurchaseGood> Goods { get; set; } = new();
private Dictionary<int, (IGoodModel, int)>? _purchaseGoods = null;
private Dictionary<int, (IGoodModel, int)> _purchaseGoods = null!;
[NotMapped]
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]
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.SaveChanges();
purchaseGoods = context.PurchasesGoods.Where(rec => rec.PurchaseId == model.Id).ToList();
// обновили количество у существующих записей
foreach (var updateGood in purchaseGoods)
{