бред
This commit is contained in:
parent
cf82bd4fe7
commit
2debfe4ba8
@ -137,5 +137,6 @@ namespace HardwareShopContracts.BusinessLogicsContracts
|
||||
_logger.LogInformation("ReadList. Count:{Count}", list.Count);
|
||||
return sum;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -123,5 +123,23 @@ namespace HardwareShopContracts.BusinessLogicsContracts
|
||||
}
|
||||
_logger.LogInformation("Purchase. UserId:{UserId}. PurchaseID:{Id}. Sum:{ Sum}", model.UserId, model.Id, model.Sum);
|
||||
}
|
||||
|
||||
public double Price(PurchaseSearchModel model)
|
||||
{
|
||||
_logger.LogInformation("ReadList. Id:{Id}", model?.Id);
|
||||
var list = _purchaseStorage.GetFilteredListBuild(model);
|
||||
if (list == null)
|
||||
{
|
||||
_logger.LogWarning("ReadList return null list");
|
||||
return 0;
|
||||
}
|
||||
double sum = 0;
|
||||
foreach (var build in list)
|
||||
{
|
||||
sum += build.Value.Item1* build.Value.Item2.Price;
|
||||
}
|
||||
_logger.LogInformation("ReadList. Count:{Count}", list.Count);
|
||||
return sum;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -8,6 +8,7 @@ namespace HardwareShopContracts.BusinessLogicsContracts
|
||||
{
|
||||
List<PurchaseViewModel>? ReadList(PurchaseSearchModel? model);
|
||||
CommentViewModel? ReadElement(CommentSearchModel model);
|
||||
double Price(PurchaseSearchModel model);
|
||||
bool Create(PurchaseBindingModel model);
|
||||
bool Update(PurchaseBindingModel model);
|
||||
bool Delete(PurchaseBindingModel model);
|
||||
|
@ -1,6 +1,7 @@
|
||||
using HardwareShopContracts.BindingModels;
|
||||
using HardwareShopContracts.SearchModels;
|
||||
using HardwareShopContracts.ViewModels;
|
||||
using HardwareShopDataModels.Models;
|
||||
|
||||
namespace HardwareShopContracts.StoragesContracts
|
||||
{
|
||||
@ -8,6 +9,7 @@ namespace HardwareShopContracts.StoragesContracts
|
||||
{
|
||||
List<PurchaseViewModel> GetFullList();
|
||||
List<PurchaseViewModel> GetFilteredList(PurchaseSearchModel model);
|
||||
Dictionary<int, (int, IBuildModel)> GetFilteredListBuild(PurchaseSearchModel model);
|
||||
PurchaseViewModel? GetElement(PurchaseSearchModel model);
|
||||
PurchaseViewModel? Insert(PurchaseBindingModel model);
|
||||
PurchaseViewModel? Update(PurchaseBindingModel model);
|
||||
|
@ -2,7 +2,9 @@
|
||||
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
|
||||
@ -15,6 +17,7 @@ namespace HardwareShopDatabaseImplement.Implements.Worker
|
||||
return context.Purchases
|
||||
.Include(x => x.Builds)
|
||||
.Include(x => x.Goods)
|
||||
.ThenInclude(x => x.Good)
|
||||
.Include(x => x.User)
|
||||
.Select(x => x.GetViewModel)
|
||||
.ToList();
|
||||
@ -23,25 +26,36 @@ namespace HardwareShopDatabaseImplement.Implements.Worker
|
||||
public List<PurchaseViewModel> GetFilteredList(PurchaseSearchModel model)
|
||||
{
|
||||
using var context = new HardwareShopDatabase();
|
||||
if (model.UserId.HasValue)
|
||||
if (!model.UserId.HasValue)
|
||||
{
|
||||
return context.Purchases
|
||||
.Include(x => x.Builds)
|
||||
.Include(x => x.Goods)
|
||||
.Include(x => x.User)
|
||||
.Where(x => x.UserId == model.UserId)
|
||||
.Select(x => x.GetViewModel)
|
||||
.ToList();
|
||||
return new();
|
||||
}
|
||||
return context.Purchases
|
||||
.Include(x => x.Builds)
|
||||
.Include(x => x.Goods)
|
||||
.Include(x => x.User)
|
||||
.Where(x => x.Id == model.Id)
|
||||
.Select(x => x.GetViewModel)
|
||||
.ToList();
|
||||
.Include(x => x.Builds)
|
||||
.Include(x => x.Goods)
|
||||
.ThenInclude(x => x.Good)
|
||||
.Include(x => x.User)
|
||||
.Where(x => x.UserId == model.UserId)
|
||||
.Select(x => x.GetViewModel)
|
||||
.ToList();
|
||||
}
|
||||
|
||||
public Dictionary<int, (int, IBuildModel)> GetFilteredListBuild(PurchaseSearchModel model)
|
||||
{
|
||||
using var context = new HardwareShopDatabase();
|
||||
var listBuilds = context.PurchasesBuilds
|
||||
.Include(x => x.Build)
|
||||
.Where(x => x.PurchaseId == model.Id)
|
||||
.ToList();
|
||||
Dictionary<int,(int, IBuildModel)>? _purchaseBuilds = null;
|
||||
foreach(var build in listBuilds)
|
||||
{
|
||||
_purchaseBuilds.Add(build.BuildId, (build.Count, build.Build));
|
||||
}
|
||||
return _purchaseBuilds;
|
||||
}
|
||||
|
||||
|
||||
public PurchaseViewModel? GetElement(PurchaseSearchModel model)
|
||||
{
|
||||
if (!model.Id.HasValue)
|
||||
@ -52,6 +66,7 @@ namespace HardwareShopDatabaseImplement.Implements.Worker
|
||||
return context.Purchases
|
||||
.Include(x => x.Builds)
|
||||
.Include(x => x.Goods)
|
||||
.ThenInclude(x => x.Good)
|
||||
.Include(x => x.User)
|
||||
.FirstOrDefault(x => model.Id.HasValue && x.Id == model.Id)
|
||||
?.GetViewModel;
|
||||
@ -70,6 +85,7 @@ namespace HardwareShopDatabaseImplement.Implements.Worker
|
||||
return context.Purchases
|
||||
.Include(x => x.Builds)
|
||||
.Include(x => x.Goods)
|
||||
.ThenInclude(x => x.Good)
|
||||
.Include(x => x.User)
|
||||
.FirstOrDefault(x => x.Id == newPurchase.Id)
|
||||
?.GetViewModel;
|
||||
@ -84,6 +100,7 @@ namespace HardwareShopDatabaseImplement.Implements.Worker
|
||||
var purchase = context.Purchases
|
||||
.Include(x => x.Builds)
|
||||
.Include(x => x.Goods)
|
||||
.ThenInclude(x => x.Good)
|
||||
.Include(x => x.User)
|
||||
.FirstOrDefault(x => x.Id == model.Id);
|
||||
if (purchase == null)
|
||||
@ -109,6 +126,7 @@ namespace HardwareShopDatabaseImplement.Implements.Worker
|
||||
var element = context.Purchases
|
||||
.Include(x => x.Builds)
|
||||
.Include(x => x.Goods)
|
||||
.ThenInclude(x => x.Good)
|
||||
.Include(x => x.User)
|
||||
.FirstOrDefault(rec => rec.Id == model.Id);
|
||||
if (element != null)
|
||||
|
Loading…
Reference in New Issue
Block a user