Исправление моделей

This commit is contained in:
dasha 2023-04-04 18:48:23 +04:00
parent 6dd59c47ad
commit 576d8eef75
6 changed files with 51 additions and 2 deletions

View File

@ -25,6 +25,24 @@ namespace HardwareShopBusinessLogic.BusinessLogics.Storekeeper
}
public List<ReportBuildGoodViewModel> GetBuildGood(List<GoodViewModel> goods)
{
/*var result = new List<ReportBuildGoodViewModel>();
foreach (var good in goods)
{
var builds = good.GoodComponents?
.SelectMany(x => x.Value.Item1.ComponentBuilds
.Select(y => y.Value.Item1.BuildName))
.ToList();
ReportBuildGoodViewModel record = new()
{
GoodName = good.GoodName,
Builds = builds
};
result.Add(record);
}
return result;*/
var list = new List<ReportBuildGoodViewModel>();
var builds = _buildStorage.GetFullList();

View File

@ -12,6 +12,7 @@
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\HardwareShopBusinessLogic\HardwareShopBusinessLogic.csproj" />
<ProjectReference Include="..\HardwareShopContracts\HardwareShopContracts.csproj" />
</ItemGroup>

View File

@ -1,4 +1,4 @@
using HardwareShopClientApp;
/*using HardwareShopClientApp;
var builder = WebApplication.CreateBuilder(args);
@ -27,3 +27,30 @@ app.MapControllerRoute(
pattern: "{controller=Home}/{action=Index}/{id?}");
app.Run();
*/
using HardwareShopBusinessLogic.BusinessLogics.Storekeeper;
using HardwareShopDatabaseImplement.Implements.Storekeeper;
using HardwareShopDatabaseImplement.Implements.Worker;
ComponentStorage _componentStorage = new();
GoodStorage _goodStorage = new();
PurchaseStorage _purchaseStorage = new();
BuildStorage _buildStorage = new();
ReportStorekeeperLogic reportLogic = new(_componentStorage, _goodStorage, _purchaseStorage, _buildStorage);
var goods = _goodStorage.GetFilteredList(new() { UserId = 1 });
var reportRecords = reportLogic.GetBuildGood(goods);
Console.WriteLine("start");
foreach (var reportRecord in reportRecords)
{
Console.WriteLine("good: " + reportRecord.GoodName);
Console.WriteLine("> builds:");
for (int i = 0; i < reportRecord.Builds.Count; i++)
{
Console.WriteLine(i + 1 + ". " + reportRecord.Builds[i]);
}
Console.WriteLine();
}

View File

@ -10,7 +10,7 @@ namespace HardwareShopDatabaseImplement
{
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
optionsBuilder.UseNpgsql("Host=localhost;Port=5432;Database=Computer_Hardware_Store;Username=user;Password=12345");
optionsBuilder.UseNpgsql("Host=localhost;Port=5433;Database=Computer_Hardware_Store;Username=user;Password=12345");
}
protected override void OnModelCreating(ModelBuilder modelBuilder)

View File

@ -84,6 +84,7 @@ namespace HardwareShopDatabaseImplement.Models.Storekeeper
{ // удалили те, которых нет в модели
context.ComponentsBuilds.RemoveRange(componentBuilds.Where(rec => !model.ComponentBuilds.ContainsKey(rec.BuildId)));
context.SaveChanges();
componentBuilds = context.ComponentsBuilds.Where(rec => rec.ComponentId == model.Id).ToList();
// обновили количество у существующих записей
foreach (var updateBuild in componentBuilds)
{

View File

@ -90,6 +90,8 @@ namespace HardwareShopDatabaseImplement.Models.Storekeeper
.RemoveRange(goodComponents
.Where(rec => !model.GoodComponents.ContainsKey(rec.ComponentId)));
context.SaveChanges();
goodComponents = context.GoodsComponents
.Where(rec => rec.GoodId == model.Id).ToList();
// обновили количество у существующих записей
foreach (var updateComponent in goodComponents)
{