This commit is contained in:
Николай 2023-04-02 16:10:21 +04:00
parent 934080cd54
commit 8203d22849
6 changed files with 15 additions and 18 deletions

View File

@ -15,7 +15,6 @@ namespace HardwareShopContracts.BindingModels
public int UserId { get; set; }
public Dictionary<int, (IGoodModel, int)> PurchaseGoods { get; set; } = new();
}
}

View File

@ -8,5 +8,7 @@ namespace HardwareShopContracts.SearchModels
public string? BuildName { get; set; } = string.Empty;
public int? UserId { get; set; }
public int? PurchaseId { get; set; }
}
}

View File

@ -61,7 +61,7 @@ namespace HardwareShopDatabaseImplement.Implements.Worker
public BuildViewModel? Insert(BuildBindingModel model)
{
using var context = new HardwareShopDatabase();
var newBuild = Build.Create(context, model);
var newBuild = Build.Create(model);
if (newBuild == null)
{
return null;

View File

@ -21,7 +21,7 @@ namespace HardwareShopDatabaseImplement.Implements.Worker
public List<CommentViewModel> GetFilteredList(CommentSearchModel model)
{
if (!model.Id.HasValue)
if (!model.BuildId.HasValue && !model.UserId.HasValue)
{
return new();
}
@ -35,13 +35,12 @@ namespace HardwareShopDatabaseImplement.Implements.Worker
.Select(x => x.GetViewModel)
.ToList();
}
return context.Comments
.Include(x => x.Build)
.Include(x => x.User)
.Where(x => x.BuildId == model.BuildId)
.Select(x => x.GetViewModel)
.ToList();
.Include(x => x.Build)
.Include(x => x.User)
.Where(x => x.BuildId == model.BuildId)
.Select(x => x.GetViewModel)
.ToList();
}
public CommentViewModel? GetElement(CommentSearchModel model)

View File

@ -47,18 +47,13 @@ namespace HardwareShopDatabaseImplement.Models.Worker
}
}
public static Build Create(HardwareShopDatabase context, BuildBindingModel model)
public static Build Create(BuildBindingModel model)
{
return new Build()
{
Id = model.Id,
BuildName = model.BuildName,
UserId = model.UserId,
Purchases = model.BuildPurchases.Select(x => new PurchaseBuild
{
Purchase = context.Purchases.First(y => y.Id == x.Key),
Count = x.Value.Item2
}).ToList()
};
}
@ -75,6 +70,7 @@ namespace HardwareShopDatabaseImplement.Models.Worker
Price = Price,
UserLogin = User.Login,
UserId = UserId,
BuildPurchases = BuildPurchases,
};
public void UpdatePurchases(HardwareShopDatabase context, BuildBindingModel model)
@ -94,13 +90,13 @@ namespace HardwareShopDatabaseImplement.Models.Worker
}
var build = context.Builds.First(x => x.Id == Id);
//добавляем в бд блюда которые есть в моделе, но ещё нет в бд
foreach (var dc in model.BuildPurchases)
foreach (var bp in model.BuildPurchases)
{
context.PurchasesBuilds.Add(new PurchaseBuild
{
Build = build,
Purchase = context.Purchases.First(x => x.Id == dc.Key),
Count = dc.Value.Item2
Purchase = context.Purchases.First(x => x.Id == bp.Key),
Count = bp.Value.Item2
});
context.SaveChanges();
}

View File

@ -68,6 +68,7 @@ namespace HardwareShopDatabaseImplement.Models.Worker
{
PurchaseStatus = model.PurchaseStatus;
DatePurchase = model.DatePurchase;
Sum = model.Sum;
}
public PurchaseViewModel GetViewModel => new()