слияние типа
This commit is contained in:
commit
1c67a1004f
@ -0,0 +1,146 @@
|
|||||||
|
|
||||||
|
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
|
||||||
|
{
|
||||||
|
public class WorkerReportLogic : IWorkerReportLogic
|
||||||
|
{
|
||||||
|
private readonly IComponentStorage _componentStorage;
|
||||||
|
|
||||||
|
private readonly BuildStorage _buildStorage;
|
||||||
|
|
||||||
|
private readonly IPurchaseStorage _purchaseStorage;
|
||||||
|
|
||||||
|
private readonly IGoodStorage _goodStorage;
|
||||||
|
|
||||||
|
private readonly ICommentStorage _commentStorage;
|
||||||
|
|
||||||
|
public WorkerReportLogic(IComponentStorage componentStorage, BuildStorage buildStorage, IPurchaseStorage purchaseStorage, IGoodStorage goodStorage, ICommentStorage commentStorage)
|
||||||
|
{
|
||||||
|
_componentStorage = componentStorage;
|
||||||
|
_buildStorage = buildStorage;
|
||||||
|
_purchaseStorage = purchaseStorage;
|
||||||
|
_goodStorage = goodStorage;
|
||||||
|
_commentStorage = commentStorage;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Получение списка компонент с указанием, в каких покупках используются
|
||||||
|
/// </summary>
|
||||||
|
/// <returns></returns>
|
||||||
|
public List<ReportPurchaseComponentViewModel> GetPurchaseComponent(List<PurchaseViewModel> purchaseList)
|
||||||
|
{
|
||||||
|
var list = new List<ReportPurchaseComponentViewModel>();
|
||||||
|
|
||||||
|
foreach (var purchase in purchaseList)
|
||||||
|
{
|
||||||
|
var record = new ReportPurchaseComponentViewModel
|
||||||
|
{
|
||||||
|
Id = purchase.Id,
|
||||||
|
Builds = new List<(string Build, int count, List<(string Component, int count)>)>(),
|
||||||
|
Goods = new List<(string Good, int count, List<(string Component, int count)>)>(),
|
||||||
|
TotalCount = 0,
|
||||||
|
TotalCost = 0
|
||||||
|
};
|
||||||
|
foreach (var good in purchase.PurchaseGoods)
|
||||||
|
{
|
||||||
|
List<(string Component, int count)> componentList = new List<(string Component, int count)>();
|
||||||
|
int goodTotalCount = 0;
|
||||||
|
foreach (var component in good.Value.Item1.GoodsComponents)
|
||||||
|
{
|
||||||
|
componentList.Add(new(component.Value.Item1.ComponentName, component.Value.Item2));
|
||||||
|
goodTotalCount += component.Value.Item2;
|
||||||
|
}
|
||||||
|
record.Goods.Add(new(good.Value.Item1.GoodName, good.Value.Item2, componentList));
|
||||||
|
record.TotalCount += goodTotalCount * good.Value.Item2;
|
||||||
|
}
|
||||||
|
foreach (var build in purchase.PurchaseBuilds)
|
||||||
|
{
|
||||||
|
List<(string Component, int count)> componentList = new List<(string Component, int count)>();
|
||||||
|
int buildTotalCount = 0;
|
||||||
|
foreach (var component in build.Value.Item1.BuildComponents)
|
||||||
|
{
|
||||||
|
componentList.Add(new(component.Value.Item1.ComponentName, component.Value.Item2));
|
||||||
|
buildTotalCount += component.Value.Item2;
|
||||||
|
}
|
||||||
|
record.Builds.Add(new(build.Value.Item1.BuildName, build.Value.Item2, componentList));
|
||||||
|
record.TotalCount += buildTotalCount * build.Value.Item2;
|
||||||
|
}
|
||||||
|
list.Add(record);
|
||||||
|
}
|
||||||
|
return list;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Получение списка покупок за определенный период
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="model"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public List<ReportPurchaseViewModel> GetPurchase(ReportBindingModel model)
|
||||||
|
{
|
||||||
|
var list = new List<ReportPurchaseViewModel>();
|
||||||
|
var purchases = _purchaseStorage.GetFilteredList(new PurchaseSearchModel { DateFrom = model.DateFrom, DateTo = model.DateTo });
|
||||||
|
|
||||||
|
foreach (var purchase in purchases)
|
||||||
|
{
|
||||||
|
var record = new ReportPurchaseViewModel
|
||||||
|
{
|
||||||
|
Id = purchase.Id,
|
||||||
|
Builds = new List<(string Build, int count, List<string>, List<(string Component, int count)>)>(),
|
||||||
|
};
|
||||||
|
foreach (var build in purchase.PurchaseBuilds)
|
||||||
|
{
|
||||||
|
List<string> commentList = new List<string>();
|
||||||
|
foreach (var comment in build.Value.Item1.BuildComments)
|
||||||
|
{
|
||||||
|
commentList.Add(new(comment.Value.Text));
|
||||||
|
}
|
||||||
|
List<(string Component, int count)> componentList = new List<(string Component, int count)>();
|
||||||
|
foreach (var component in build.Value.Item1.BuildComponents)
|
||||||
|
{
|
||||||
|
componentList.Add(new(component.Value.Item1.ComponentName, component.Value.Item2));
|
||||||
|
}
|
||||||
|
record.Builds.Add(new (build.Value.Item1.BuildName, build.Value.Item2, commentList, componentList));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return list;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Сохранение компонент с указаеним покупок в файл-Word
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="model"></param>
|
||||||
|
public void SaveComponentsToWordFile(ReportBindingModel model)
|
||||||
|
{
|
||||||
|
throw new NotImplementedException();
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Сохранение компонент с указаеним покупок в файл-Excel
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="model"></param>
|
||||||
|
public void SaveDishComponentToExcelFile(ReportBindingModel model)
|
||||||
|
{
|
||||||
|
throw new NotImplementedException();
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Сохранение отчёта по покупкам в файл-Pdf
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="model"></param>
|
||||||
|
public void SaveOrdersToPdfFile(ReportBindingModel model)
|
||||||
|
{
|
||||||
|
throw new NotImplementedException();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -12,6 +12,7 @@
|
|||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ProjectReference Include="..\HardwareShopContracts\HardwareShopContracts.csproj" />
|
<ProjectReference Include="..\HardwareShopContracts\HardwareShopContracts.csproj" />
|
||||||
|
<ProjectReference Include="..\HardwareShopDatabaseImplement\HardwareShopDatabaseImplement.csproj" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
</Project>
|
</Project>
|
||||||
|
@ -21,9 +21,6 @@
|
|||||||
<th>
|
<th>
|
||||||
Название
|
Название
|
||||||
</th>
|
</th>
|
||||||
<th>
|
|
||||||
Логин пользователя
|
|
||||||
</th>
|
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
<tbody>
|
<tbody>
|
||||||
|
@ -23,9 +23,6 @@
|
|||||||
<th>
|
<th>
|
||||||
Название сборки к которой относиться комментарий
|
Название сборки к которой относиться комментарий
|
||||||
</th>
|
</th>
|
||||||
<th>
|
|
||||||
Логин пользователя
|
|
||||||
</th>
|
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
<tbody>
|
<tbody>
|
||||||
|
@ -36,9 +36,6 @@
|
|||||||
<th>
|
<th>
|
||||||
Статус
|
Статус
|
||||||
</th>
|
</th>
|
||||||
<th>
|
|
||||||
Логин пользователя
|
|
||||||
</th>
|
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
<tbody>
|
<tbody>
|
||||||
|
@ -21,9 +21,6 @@
|
|||||||
<th>
|
<th>
|
||||||
Цена
|
Цена
|
||||||
</th>
|
</th>
|
||||||
<th>
|
|
||||||
Логин пользователя
|
|
||||||
</th>
|
|
||||||
<th>
|
<th>
|
||||||
Количество
|
Количество
|
||||||
</th>
|
</th>
|
||||||
@ -39,7 +36,7 @@
|
|||||||
<button type="button" class="btn btn-primary btn-lg mb-5" data-bs-toggle="modal" data-bs-target="#exampleModal">Изменить</button>
|
<button type="button" class="btn btn-primary btn-lg mb-5" data-bs-toggle="modal" data-bs-target="#exampleModal">Изменить</button>
|
||||||
<button type="button" class="btn btn-primary btn-lg mb-5">Удалить</button>
|
<button type="button" class="btn btn-primary btn-lg mb-5">Удалить</button>
|
||||||
<button type="button" class="btn btn-primary btn-lg mb-5">Обновить</button>
|
<button type="button" class="btn btn-primary btn-lg mb-5">Обновить</button>
|
||||||
<button type="button" class="btn btn-primary btn-lg mb-5">Сохрванить</button>
|
<button type="button" class="btn btn-primary btn-lg mb-5">Сохранить</button>
|
||||||
</div>
|
</div>
|
||||||
<div class="modal fade" id="exampleModal" tabindex="-1" aria-labelledby="exampleModalLabel" aria-hidden="true">
|
<div class="modal fade" id="exampleModal" tabindex="-1" aria-labelledby="exampleModalLabel" aria-hidden="true">
|
||||||
<div class="modal-dialog">
|
<div class="modal-dialog">
|
||||||
|
@ -24,9 +24,6 @@
|
|||||||
<th>
|
<th>
|
||||||
Статус
|
Статус
|
||||||
</th>
|
</th>
|
||||||
<th>
|
|
||||||
Логин пользователя
|
|
||||||
</th>
|
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
<tbody>
|
<tbody>
|
||||||
|
@ -24,9 +24,6 @@
|
|||||||
<th>
|
<th>
|
||||||
Статус
|
Статус
|
||||||
</th>
|
</th>
|
||||||
<th>
|
|
||||||
Логин пользователя
|
|
||||||
</th>
|
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
<tbody>
|
<tbody>
|
||||||
|
@ -13,5 +13,7 @@ namespace HardwareShopContracts.BindingModels
|
|||||||
public int UserId { get; set; }
|
public int UserId { get; set; }
|
||||||
|
|
||||||
public Dictionary<int, (IPurchaseModel, int)> BuildPurchases { get; set; } = new();
|
public Dictionary<int, (IPurchaseModel, int)> BuildPurchases { get; set; } = new();
|
||||||
|
|
||||||
|
public Dictionary<int, (IComponentModel, int)> BuildComponents { get; set; } = new();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -16,5 +16,7 @@ namespace HardwareShopContracts.BindingModels
|
|||||||
public int UserId { get; set; }
|
public int UserId { get; set; }
|
||||||
|
|
||||||
public Dictionary<int, (IGoodModel, int)> PurchaseGoods { get; set; } = new();
|
public Dictionary<int, (IGoodModel, int)> PurchaseGoods { get; set; } = new();
|
||||||
|
|
||||||
|
public Dictionary<int, (IBuildModel, int)> PurchaseBuilds { get; set; } = new();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,40 @@
|
|||||||
|
|
||||||
|
using HardwareShopContracts.BindingModels;
|
||||||
|
using HardwareShopContracts.ViewModels;
|
||||||
|
|
||||||
|
namespace HardwareShopContracts.BusinessLogicsContracts
|
||||||
|
{
|
||||||
|
public interface IWorkerReportLogic
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Получение списка компонент с указанием, в каких покупках используются
|
||||||
|
/// </summary>
|
||||||
|
/// <returns></returns>
|
||||||
|
List<ReportPurchaseComponentViewModel> GetPurchaseComponent(List<PurchaseViewModel> purchaseList);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Получение списка покупок за определенный период
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="model"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
List<ReportPurchaseViewModel> GetPurchase(ReportBindingModel model);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Сохранение компонент с указаеним покупок в файл-Word
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="model"></param>
|
||||||
|
void SaveComponentsToWordFile(ReportBindingModel model);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Сохранение компонент с указаеним покупок в файл-Excel
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="model"></param>
|
||||||
|
void SaveDishComponentToExcelFile(ReportBindingModel model);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Сохранение отчёта по покупкам в файл-Pdf
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="model"></param>
|
||||||
|
void SaveOrdersToPdfFile(ReportBindingModel model);
|
||||||
|
}
|
||||||
|
}
|
@ -1,4 +1,5 @@
|
|||||||
|
|
||||||
|
using HardwareShopDataModels.Enums;
|
||||||
using System.ComponentModel;
|
using System.ComponentModel;
|
||||||
namespace HardwareShopContracts.SearchModels
|
namespace HardwareShopContracts.SearchModels
|
||||||
{
|
{
|
||||||
@ -8,7 +9,10 @@ namespace HardwareShopContracts.SearchModels
|
|||||||
|
|
||||||
public int? UserId { get; set; }
|
public int? UserId { get; set; }
|
||||||
|
|
||||||
public DateTime? DatePurchase { get; set; }
|
public PurchaseStatus? PurchaseStatus { get; set; }
|
||||||
|
|
||||||
|
public DateTime? DateFrom { get; set; }
|
||||||
|
|
||||||
public DateTime? DateTo { get; set; }
|
public DateTime? DateTo { get; set; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -12,12 +12,10 @@ namespace HardwareShopContracts.ViewModels
|
|||||||
[DisplayName("Название Сборки")]
|
[DisplayName("Название Сборки")]
|
||||||
public string BuildName { get; set; } = string.Empty;
|
public string BuildName { get; set; } = string.Empty;
|
||||||
|
|
||||||
[DisplayName("Логин пользователя")]
|
|
||||||
public string UserLogin { get; set; } = string.Empty;
|
|
||||||
|
|
||||||
public int UserId { get; set; }
|
public int UserId { get; set; }
|
||||||
|
|
||||||
public Dictionary<int, (IPurchaseModel, int)> BuildPurchases { get; set; } = new();
|
public Dictionary<int, (IPurchaseModel, int)> BuildPurchases { get; set; } = new();
|
||||||
|
|
||||||
|
public Dictionary<int, (IComponentModel, int)> BuildComponents { get; set; } = new();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -16,8 +16,5 @@ namespace HardwareShopContracts.ViewModels
|
|||||||
public int BuildId { get; set; }
|
public int BuildId { get; set; }
|
||||||
|
|
||||||
public int UserId { get; set; }
|
public int UserId { get; set; }
|
||||||
|
|
||||||
[DisplayName("Логин пользователя")]
|
|
||||||
public string UserLogin { get; set; } = string.Empty;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -18,9 +18,8 @@ namespace HardwareShopContracts.ViewModels
|
|||||||
|
|
||||||
public int UserId { get; set; }
|
public int UserId { get; set; }
|
||||||
|
|
||||||
[DisplayName("Логин пользователя")]
|
|
||||||
public string UserLogin { get; set; } = string.Empty;
|
|
||||||
|
|
||||||
public Dictionary<int, (IGoodModel, int)> PurchaseGoods { get; set; } = new();
|
public Dictionary<int, (IGoodModel, int)> PurchaseGoods { get; set; } = new();
|
||||||
|
|
||||||
|
public Dictionary<int, (IBuildModel, int)> PurchaseBuilds { get; set; } = new();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,23 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace HardwareShopContracts.ViewModels
|
||||||
|
{
|
||||||
|
public class ReportPurchaseComponentViewModel
|
||||||
|
{
|
||||||
|
public int Id { get; set; }
|
||||||
|
|
||||||
|
public List<(string Build, int count, List<(string Component, int count)>)> Builds { get; set; } = new();
|
||||||
|
|
||||||
|
public List<(string Good, int count, List<(string Component, int count)>)> Goods { get; set; } = new();
|
||||||
|
|
||||||
|
public int TotalCount { get; set; }
|
||||||
|
|
||||||
|
public int TotalCost { get; set; }
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,15 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace HardwareShopContracts.ViewModels
|
||||||
|
{
|
||||||
|
public class ReportPurchaseViewModel
|
||||||
|
{
|
||||||
|
public int Id { get; set; }
|
||||||
|
|
||||||
|
public List<(string Build, int count, List<string>, List<(string Component, int count)>)> Builds { get; set; } = new();
|
||||||
|
}
|
||||||
|
}
|
@ -16,5 +16,9 @@ namespace HardwareShopDataModels.Models
|
|||||||
int UserId { get; }
|
int UserId { get; }
|
||||||
|
|
||||||
Dictionary<int, (IPurchaseModel, int)> BuildPurchases { get; }
|
Dictionary<int, (IPurchaseModel, int)> BuildPurchases { get; }
|
||||||
|
|
||||||
|
Dictionary<int, (IComponentModel, int)> BuildComponents { get; }
|
||||||
|
|
||||||
|
Dictionary<int, ICommentModel> BuildComments { get; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -13,5 +13,7 @@ namespace HardwareShopDataModels.Models
|
|||||||
int UserId { get; }
|
int UserId { get; }
|
||||||
|
|
||||||
Dictionary<int, (IGoodModel, int)> PurchaseGoods { get; }
|
Dictionary<int, (IGoodModel, int)> PurchaseGoods { get; }
|
||||||
|
|
||||||
|
Dictionary<int, (IBuildModel, int)> PurchaseBuilds { get; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -15,7 +15,6 @@ namespace HardwareShopDatabaseImplement.Implements.Worker
|
|||||||
return context.Builds
|
return context.Builds
|
||||||
.Include(x => x.Purchases)
|
.Include(x => x.Purchases)
|
||||||
.ThenInclude(x => x.Purchase)
|
.ThenInclude(x => x.Purchase)
|
||||||
.Include(x => x.User)
|
|
||||||
.ToList()
|
.ToList()
|
||||||
.Select(x => x.GetViewModel)
|
.Select(x => x.GetViewModel)
|
||||||
.ToList();
|
.ToList();
|
||||||
@ -57,7 +56,6 @@ namespace HardwareShopDatabaseImplement.Implements.Worker
|
|||||||
return context.Builds
|
return context.Builds
|
||||||
.Include(x => x.Purchases)
|
.Include(x => x.Purchases)
|
||||||
.ThenInclude(x => x.Purchase)
|
.ThenInclude(x => x.Purchase)
|
||||||
.Include(x => x.User)
|
|
||||||
.Where(x => x.Id == model.Id)
|
.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))
|
(model.Id.HasValue && x.Id == model.Id))
|
||||||
@ -77,7 +75,6 @@ namespace HardwareShopDatabaseImplement.Implements.Worker
|
|||||||
return context.Builds
|
return context.Builds
|
||||||
.Include(x => x.Purchases)
|
.Include(x => x.Purchases)
|
||||||
.ThenInclude(x => x.Purchase)
|
.ThenInclude(x => x.Purchase)
|
||||||
.Include(x => x.User)
|
|
||||||
.Where(x => x.UserId == model.Id)
|
.Where(x => x.UserId == model.Id)
|
||||||
.FirstOrDefault(x => x.Id == newBuild.Id)
|
.FirstOrDefault(x => x.Id == newBuild.Id)
|
||||||
?.GetViewModel;
|
?.GetViewModel;
|
||||||
@ -92,7 +89,6 @@ namespace HardwareShopDatabaseImplement.Implements.Worker
|
|||||||
var build = context.Builds
|
var build = context.Builds
|
||||||
.Include(x => x.Purchases)
|
.Include(x => x.Purchases)
|
||||||
.ThenInclude(x => x.Purchase)
|
.ThenInclude(x => x.Purchase)
|
||||||
.Include(x => x.User)
|
|
||||||
.Where(x => x.UserId == model.UserId)
|
.Where(x => x.UserId == model.UserId)
|
||||||
.FirstOrDefault(x => x.Id == model.Id);
|
.FirstOrDefault(x => x.Id == model.Id);
|
||||||
if (build == null)
|
if (build == null)
|
||||||
@ -118,7 +114,6 @@ namespace HardwareShopDatabaseImplement.Implements.Worker
|
|||||||
var element = context.Builds
|
var element = context.Builds
|
||||||
.Include(x => x.Purchases)
|
.Include(x => x.Purchases)
|
||||||
.ThenInclude(x => x.Purchase)
|
.ThenInclude(x => x.Purchase)
|
||||||
.Include(x => x.User)
|
|
||||||
.Where(x => x.UserId == model.Id)
|
.Where(x => x.UserId == model.Id)
|
||||||
.FirstOrDefault(rec => rec.Id == model.Id);
|
.FirstOrDefault(rec => rec.Id == model.Id);
|
||||||
if (element != null)
|
if (element != null)
|
||||||
|
@ -14,7 +14,6 @@ namespace HardwareShopDatabaseImplement.Implements.Worker
|
|||||||
using var context = new HardwareShopDatabase();
|
using var context = new HardwareShopDatabase();
|
||||||
return context.Comments
|
return context.Comments
|
||||||
.Include(x => x.Build)
|
.Include(x => x.Build)
|
||||||
.Include(x => x.User)
|
|
||||||
.Select(x => x.GetViewModel)
|
.Select(x => x.GetViewModel)
|
||||||
.ToList();
|
.ToList();
|
||||||
}
|
}
|
||||||
@ -30,14 +29,12 @@ namespace HardwareShopDatabaseImplement.Implements.Worker
|
|||||||
{
|
{
|
||||||
return context.Comments
|
return context.Comments
|
||||||
.Include(x => x.Build)
|
.Include(x => x.Build)
|
||||||
.Include(x => x.User)
|
|
||||||
.Where(x => x.UserId == model.UserId)
|
.Where(x => x.UserId == model.UserId)
|
||||||
.Select(x => x.GetViewModel)
|
.Select(x => x.GetViewModel)
|
||||||
.ToList();
|
.ToList();
|
||||||
}
|
}
|
||||||
return context.Comments
|
return context.Comments
|
||||||
.Include(x => x.Build)
|
.Include(x => x.Build)
|
||||||
.Include(x => x.User)
|
|
||||||
.Where(x => x.BuildId == model.BuildId)
|
.Where(x => x.BuildId == model.BuildId)
|
||||||
.Select(x => x.GetViewModel)
|
.Select(x => x.GetViewModel)
|
||||||
.ToList();
|
.ToList();
|
||||||
@ -52,7 +49,6 @@ namespace HardwareShopDatabaseImplement.Implements.Worker
|
|||||||
using var context = new HardwareShopDatabase();
|
using var context = new HardwareShopDatabase();
|
||||||
return context.Comments
|
return context.Comments
|
||||||
.Include(x => x.Build)
|
.Include(x => x.Build)
|
||||||
.Include(x => x.User)
|
|
||||||
.FirstOrDefault(x => model.Id.HasValue && x.Id == model.Id)
|
.FirstOrDefault(x => model.Id.HasValue && x.Id == model.Id)
|
||||||
?.GetViewModel;
|
?.GetViewModel;
|
||||||
}
|
}
|
||||||
@ -75,7 +71,6 @@ namespace HardwareShopDatabaseImplement.Implements.Worker
|
|||||||
using var context = new HardwareShopDatabase();
|
using var context = new HardwareShopDatabase();
|
||||||
var comment = context.Comments
|
var comment = context.Comments
|
||||||
.Include(x => x.Build)
|
.Include(x => x.Build)
|
||||||
.Include(x => x.User)
|
|
||||||
.FirstOrDefault(x => x.Id == model.Id);
|
.FirstOrDefault(x => x.Id == model.Id);
|
||||||
if (comment == null)
|
if (comment == null)
|
||||||
{
|
{
|
||||||
@ -91,7 +86,6 @@ namespace HardwareShopDatabaseImplement.Implements.Worker
|
|||||||
using var context = new HardwareShopDatabase();
|
using var context = new HardwareShopDatabase();
|
||||||
var element = context.Comments
|
var element = context.Comments
|
||||||
.Include(x => x.Build)
|
.Include(x => x.Build)
|
||||||
.Include(x => x.User)
|
|
||||||
.FirstOrDefault(rec => rec.Id == model.Id);
|
.FirstOrDefault(rec => rec.Id == model.Id);
|
||||||
if (element != null)
|
if (element != null)
|
||||||
{
|
{
|
||||||
|
@ -17,7 +17,6 @@ namespace HardwareShopDatabaseImplement.Implements.Worker
|
|||||||
return context.Purchases
|
return context.Purchases
|
||||||
.Include(x => x.Goods)
|
.Include(x => x.Goods)
|
||||||
.ThenInclude(x => x.Good)
|
.ThenInclude(x => x.Good)
|
||||||
.Include(x => x.User)
|
|
||||||
.Select(x => x.GetViewModel)
|
.Select(x => x.GetViewModel)
|
||||||
.ToList();
|
.ToList();
|
||||||
}
|
}
|
||||||
@ -25,16 +24,20 @@ namespace HardwareShopDatabaseImplement.Implements.Worker
|
|||||||
public List<PurchaseViewModel> GetFilteredList(PurchaseSearchModel model)
|
public List<PurchaseViewModel> GetFilteredList(PurchaseSearchModel model)
|
||||||
{
|
{
|
||||||
using var context = new HardwareShopDatabase();
|
using var context = new HardwareShopDatabase();
|
||||||
if (!model.UserId.HasValue && !model.DatePurchase.HasValue)
|
if (!model.UserId.HasValue && !model.PurchaseStatus.HasValue && model.DateFrom.HasValue && model.DateTo.HasValue)
|
||||||
{
|
{
|
||||||
return new();
|
return context.Purchases
|
||||||
|
.Include(x => x.Goods)
|
||||||
|
.ThenInclude(x => x.Good)
|
||||||
|
.Where(x => x.DatePurchase >= model.DateFrom && x.DatePurchase <= model.DateTo)
|
||||||
|
.Select(x => x.GetViewModel)
|
||||||
|
.ToList();
|
||||||
}
|
}
|
||||||
if (model.UserId.HasValue)
|
if (model.UserId.HasValue)
|
||||||
{
|
{
|
||||||
return context.Purchases
|
return context.Purchases
|
||||||
.Include(x => x.Goods)
|
.Include(x => x.Goods)
|
||||||
.ThenInclude(x => x.Good)
|
.ThenInclude(x => x.Good)
|
||||||
.Include(x => x.User)
|
|
||||||
.Where(x => x.UserId == model.UserId)
|
.Where(x => x.UserId == model.UserId)
|
||||||
.Select(x => x.GetViewModel)
|
.Select(x => x.GetViewModel)
|
||||||
.ToList();
|
.ToList();
|
||||||
@ -42,8 +45,7 @@ namespace HardwareShopDatabaseImplement.Implements.Worker
|
|||||||
return context.Purchases
|
return context.Purchases
|
||||||
.Include(x => x.Goods)
|
.Include(x => x.Goods)
|
||||||
.ThenInclude(x => x.Good)
|
.ThenInclude(x => x.Good)
|
||||||
.Include(x => x.User)
|
.Where(x => x.PurchaseStatus == model.PurchaseStatus)
|
||||||
.Where(x => x.DatePurchase == model.DatePurchase)
|
|
||||||
.Select(x => x.GetViewModel)
|
.Select(x => x.GetViewModel)
|
||||||
.ToList();
|
.ToList();
|
||||||
}
|
}
|
||||||
@ -58,7 +60,6 @@ namespace HardwareShopDatabaseImplement.Implements.Worker
|
|||||||
return context.Purchases
|
return context.Purchases
|
||||||
.Include(x => x.Goods)
|
.Include(x => x.Goods)
|
||||||
.ThenInclude(x => x.Good)
|
.ThenInclude(x => x.Good)
|
||||||
.Include(x => x.User)
|
|
||||||
.FirstOrDefault(x => model.Id.HasValue && x.Id == model.Id)
|
.FirstOrDefault(x => model.Id.HasValue && x.Id == model.Id)
|
||||||
?.GetViewModel;
|
?.GetViewModel;
|
||||||
}
|
}
|
||||||
@ -76,7 +77,6 @@ namespace HardwareShopDatabaseImplement.Implements.Worker
|
|||||||
return context.Purchases
|
return context.Purchases
|
||||||
.Include(x => x.Goods)
|
.Include(x => x.Goods)
|
||||||
.ThenInclude(x => x.Good)
|
.ThenInclude(x => x.Good)
|
||||||
.Include(x => x.User)
|
|
||||||
.FirstOrDefault(x => x.Id == newPurchase.Id)
|
.FirstOrDefault(x => x.Id == newPurchase.Id)
|
||||||
?.GetViewModel;
|
?.GetViewModel;
|
||||||
}
|
}
|
||||||
@ -90,7 +90,6 @@ namespace HardwareShopDatabaseImplement.Implements.Worker
|
|||||||
var purchase = context.Purchases
|
var purchase = context.Purchases
|
||||||
.Include(x => x.Goods)
|
.Include(x => x.Goods)
|
||||||
.ThenInclude(x => x.Good)
|
.ThenInclude(x => x.Good)
|
||||||
.Include(x => x.User)
|
|
||||||
.FirstOrDefault(x => x.Id == model.Id);
|
.FirstOrDefault(x => x.Id == model.Id);
|
||||||
if (purchase == null)
|
if (purchase == null)
|
||||||
{
|
{
|
||||||
@ -115,7 +114,6 @@ namespace HardwareShopDatabaseImplement.Implements.Worker
|
|||||||
var element = context.Purchases
|
var element = context.Purchases
|
||||||
.Include(x => x.Goods)
|
.Include(x => x.Goods)
|
||||||
.ThenInclude(x => x.Good)
|
.ThenInclude(x => x.Good)
|
||||||
.Include(x => x.User)
|
|
||||||
.FirstOrDefault(rec => rec.Id == model.Id);
|
.FirstOrDefault(rec => rec.Id == model.Id);
|
||||||
if (element != null)
|
if (element != null)
|
||||||
{
|
{
|
||||||
|
@ -33,7 +33,37 @@ namespace HardwareShopDatabaseImplement.Models.Worker
|
|||||||
[ForeignKey("BuildId")]
|
[ForeignKey("BuildId")]
|
||||||
public virtual List<PurchaseBuild> Purchases { get; set; } = new();
|
public virtual List<PurchaseBuild> Purchases { get; set; } = new();
|
||||||
|
|
||||||
public Dictionary<int, (IPurchaseModel, int)>? _buildPurchases = null;
|
private Dictionary<int, ICommentModel> _buildComments = null;
|
||||||
|
|
||||||
|
[NotMapped]
|
||||||
|
public Dictionary<int, ICommentModel> BuildComments
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
if (_buildComments == null)
|
||||||
|
{
|
||||||
|
_buildComments = Comments.ToDictionary(recBC=> recBC.Id, recBC => recBC as ICommentModel);
|
||||||
|
}
|
||||||
|
return _buildComments;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private Dictionary<int, (IComponentModel, int)>? _buildComponents = null;
|
||||||
|
|
||||||
|
[NotMapped]
|
||||||
|
public Dictionary<int, (IComponentModel, int)> BuildComponents
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
if (_buildComponents == null)
|
||||||
|
{
|
||||||
|
_buildComponents = Components.ToDictionary(recBC => recBC.ComponentId, recBC => (recBC.Component as IComponentModel, recBC.Count));
|
||||||
|
}
|
||||||
|
return _buildComponents;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private Dictionary<int, (IPurchaseModel, int)>? _buildPurchases = null;
|
||||||
|
|
||||||
[NotMapped]
|
[NotMapped]
|
||||||
public Dictionary<int, (IPurchaseModel, int)> BuildPurchases
|
public Dictionary<int, (IPurchaseModel, int)> BuildPurchases
|
||||||
@ -70,7 +100,6 @@ namespace HardwareShopDatabaseImplement.Models.Worker
|
|||||||
Id = Id,
|
Id = Id,
|
||||||
BuildName = BuildName,
|
BuildName = BuildName,
|
||||||
Price = Price,
|
Price = Price,
|
||||||
UserLogin = User.Login,
|
|
||||||
UserId = UserId,
|
UserId = UserId,
|
||||||
BuildPurchases = BuildPurchases,
|
BuildPurchases = BuildPurchases,
|
||||||
};
|
};
|
||||||
@ -91,7 +120,7 @@ namespace HardwareShopDatabaseImplement.Models.Worker
|
|||||||
context.SaveChanges();
|
context.SaveChanges();
|
||||||
}
|
}
|
||||||
var build = context.Builds.First(x => x.Id == Id);
|
var build = context.Builds.First(x => x.Id == Id);
|
||||||
//добавляем в бд элементы которые есть в модели, но ещё нет в бд
|
//добавляем в бд сборки которые есть в модели, но ещё нет в бд
|
||||||
foreach (var bp in model.BuildPurchases)
|
foreach (var bp in model.BuildPurchases)
|
||||||
{
|
{
|
||||||
context.PurchasesBuilds.Add(new PurchaseBuild
|
context.PurchasesBuilds.Add(new PurchaseBuild
|
||||||
@ -117,7 +146,5 @@ namespace HardwareShopDatabaseImplement.Models.Worker
|
|||||||
var buildPurchases = context.PurchasesBuilds.Where(rec => rec.BuildId == model.Id).ToList();
|
var buildPurchases = context.PurchasesBuilds.Where(rec => rec.BuildId == model.Id).ToList();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -52,7 +52,6 @@ namespace HardwareShopDatabaseImplement.Models.Worker
|
|||||||
BuildId = BuildId,
|
BuildId = BuildId,
|
||||||
BuildName = Build.BuildName,
|
BuildName = Build.BuildName,
|
||||||
UserId = UserId,
|
UserId = UserId,
|
||||||
UserLogin = User.Login,
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -32,7 +32,7 @@ namespace HardwareShopDatabaseImplement.Models.Worker
|
|||||||
[ForeignKey("PurchaseId")]
|
[ForeignKey("PurchaseId")]
|
||||||
public virtual List<PurchaseGood> Goods { get; set; } = new();
|
public virtual List<PurchaseGood> Goods { get; set; } = new();
|
||||||
|
|
||||||
public 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,6 +47,21 @@ namespace HardwareShopDatabaseImplement.Models.Worker
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private Dictionary<int, (IBuildModel, int)>? _purchaseBuilds = null;
|
||||||
|
|
||||||
|
[NotMapped]
|
||||||
|
public Dictionary<int, (IBuildModel, int)> PurchaseBuilds
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
if (_purchaseBuilds == null)
|
||||||
|
{
|
||||||
|
_purchaseBuilds = Builds.ToDictionary(recPG => recPG.BuildId, recPG => (recPG.Build as IBuildModel, recPG.Count));
|
||||||
|
}
|
||||||
|
return _purchaseBuilds;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public static Purchase Create(HardwareShopDatabase context, PurchaseBindingModel model)
|
public static Purchase Create(HardwareShopDatabase context, PurchaseBindingModel model)
|
||||||
{
|
{
|
||||||
return new Purchase()
|
return new Purchase()
|
||||||
@ -78,7 +93,6 @@ namespace HardwareShopDatabaseImplement.Models.Worker
|
|||||||
PurchaseStatus = PurchaseStatus,
|
PurchaseStatus = PurchaseStatus,
|
||||||
DatePurchase = DatePurchase,
|
DatePurchase = DatePurchase,
|
||||||
UserId = UserId,
|
UserId = UserId,
|
||||||
UserLogin = User.Login,
|
|
||||||
PurchaseGoods = PurchaseGoods
|
PurchaseGoods = PurchaseGoods
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -98,7 +112,7 @@ namespace HardwareShopDatabaseImplement.Models.Worker
|
|||||||
context.SaveChanges();
|
context.SaveChanges();
|
||||||
}
|
}
|
||||||
var purchase = context.Purchases.First(x => x.Id == Id);
|
var purchase = context.Purchases.First(x => x.Id == Id);
|
||||||
//добавляем в бд блюда которые есть в моделе, но ещё нет в бд
|
//добавляем в бд товары которые есть в моделе, но ещё нет в бд
|
||||||
foreach (var dc in model.PurchaseGoods)
|
foreach (var dc in model.PurchaseGoods)
|
||||||
{
|
{
|
||||||
context.PurchasesGoods.Add(new PurchaseGood
|
context.PurchasesGoods.Add(new PurchaseGood
|
||||||
|
Loading…
Reference in New Issue
Block a user