Промежуточные изменения
This commit is contained in:
parent
923d110e40
commit
879d0d858b
@ -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<ReportComponentsViewModel> GetComponents(UserBindingModel user, ReportBindingModel model)
|
||||
{
|
||||
{
|
||||
var result = new List<ReportComponentsViewModel>();
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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);
|
||||
}
|
||||
|
@ -1,5 +1,5 @@
|
||||
using HardwareShopDataModels.Models;
|
||||
using System.ComponentModel;
|
||||
|
||||
namespace HardwareShopContracts.BindingModels
|
||||
{
|
||||
public class BuildBindingModel : IBuildModel
|
||||
|
@ -1,5 +1,4 @@
|
||||
using HardwareShopDataModels.Models;
|
||||
using System.ComponentModel;
|
||||
|
||||
namespace HardwareShopContracts.BindingModels
|
||||
{
|
||||
|
@ -12,10 +12,10 @@ namespace HardwareShopContracts.BindingModels
|
||||
|
||||
public int UserId { get; set; }
|
||||
|
||||
public Dictionary<int, (IComponentModel, int)> GoodComponents
|
||||
{
|
||||
get;
|
||||
set;
|
||||
public Dictionary<int, (IComponentModel, int)> GoodComponents
|
||||
{
|
||||
get;
|
||||
set;
|
||||
} = new();
|
||||
}
|
||||
}
|
||||
|
@ -1,6 +1,6 @@
|
||||
using HardwareShopDataModels.Enums;
|
||||
using HardwareShopDataModels.Models;
|
||||
using System.ComponentModel;
|
||||
|
||||
namespace HardwareShopContracts.BindingModels
|
||||
{
|
||||
public class PurchaseBindingModel : IPurchaseModel
|
||||
|
@ -1,5 +1,5 @@
|
||||
using HardwareShopDataModels.Models;
|
||||
using HardwareShopDataModels.Enums;
|
||||
using HardwareShopDataModels.Enums;
|
||||
using HardwareShopDataModels.Models;
|
||||
|
||||
namespace HardwareShopContracts.BindingModels
|
||||
{
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
@ -1,5 +1,4 @@
|
||||
using System.ComponentModel;
|
||||
namespace HardwareShopContracts.SearchModels
|
||||
namespace HardwareShopContracts.SearchModels
|
||||
{
|
||||
public class BuildSearchModel
|
||||
{
|
||||
|
@ -1,7 +1,4 @@
|
||||
|
||||
using System.ComponentModel;
|
||||
|
||||
namespace HardwareShopContracts.SearchModels
|
||||
namespace HardwareShopContracts.SearchModels
|
||||
{
|
||||
public class CommentSearchModel
|
||||
{
|
||||
|
@ -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; }
|
||||
}
|
||||
}
|
||||
|
@ -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; }
|
||||
}
|
||||
}
|
||||
|
@ -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.Неизвестен;
|
||||
}
|
||||
}
|
@ -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);
|
||||
}
|
||||
}
|
@ -1,7 +1,6 @@
|
||||
using HardwareShopContracts.BindingModels;
|
||||
using HardwareShopContracts.SearchModels;
|
||||
using HardwareShopContracts.ViewModels;
|
||||
using HardwareShopDataModels.Models;
|
||||
|
||||
namespace HardwareShopContracts.StoragesContracts
|
||||
{
|
||||
|
@ -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; }
|
||||
}
|
||||
}
|
||||
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
@ -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; }
|
||||
|
@ -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
|
||||
{
|
||||
|
@ -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
|
||||
{
|
||||
|
@ -1,5 +1,5 @@
|
||||
using HardwareShopDataModels.Models;
|
||||
using HardwareShopDataModels.Enums;
|
||||
using HardwareShopDataModels.Enums;
|
||||
using HardwareShopDataModels.Models;
|
||||
using System.ComponentModel;
|
||||
|
||||
namespace HardwareShopContracts.ViewModels
|
||||
|
@ -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
|
||||
{
|
||||
|
@ -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
|
||||
{
|
||||
|
@ -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();
|
||||
});
|
||||
|
@ -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()
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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)
|
||||
|
@ -1,5 +1,4 @@
|
||||
using System;
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
|
||||
|
||||
#nullable disable
|
||||
|
@ -32,7 +32,7 @@ namespace HardwareShopDatabaseImplement.Models.Storekeeper
|
||||
public virtual List<PurchaseGood> Purchases { get; set; } = new();
|
||||
|
||||
[NotMapped]
|
||||
public Dictionary<int, (IComponentModel, int)> GoodComponents
|
||||
public Dictionary<int, (IComponentModel, int)> GoodComponents
|
||||
{
|
||||
get
|
||||
{
|
||||
|
@ -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
|
||||
{
|
||||
|
@ -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)
|
||||
{
|
||||
|
@ -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)
|
||||
|
@ -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)
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user