WIP: ПИбд-23 Тихоненков Алексей Евгеньевич Лабораторная работа №4 (Усложненная) #13

Closed
YourDax wants to merge 11 commits from Lab4HARD into Lab4
2 changed files with 11 additions and 11 deletions
Showing only changes of commit 195b51b686 - Show all commits

View File

@ -17,6 +17,8 @@ namespace CarpentryWorkshopDatabaseImplement
optionsBuilder.UseNpgsql(@"Host=localhost;Port=5432;Database=CarpentryWorkshopDatabaseFull;Username=postgres;Password=postgres");
}
base.OnConfiguring(optionsBuilder);
AppContext.SetSwitch("Npgsql.EnableLegacyTimestampBehavior", true);
AppContext.SetSwitch("Npgsql.DisableDateTimeInfinityConversions", true);
}
public virtual DbSet<Component> Components { set; get; }
public virtual DbSet<Wood> Woods { set; get; }

View File

@ -91,29 +91,27 @@ namespace CarpentryWorkshopDatabaseImplement.Models
public void UpdateWoods(CarpentryWorkshopDatabase context,
ShopBindingModel model)
{
var shopWoods = context.ShopWoods.Where(rec =>
rec.ShopId == model.Id).ToList();
if (shopWoods != null && shopWoods.Count > 0)
var ShopWoods = context.ShopWoods.Where(rec => rec.ShopId == model.Id).ToList();
if (ShopWoods != null && ShopWoods.Count > 0)
{
context.ShopWoods.RemoveRange(shopWoods.Where(rec => !model.ShopWoods.ContainsKey(rec.WoodId)));
context.ShopWoods.RemoveRange(ShopWoods.Where(rec => !model.ShopWoods.ContainsKey(rec.WoodId)));
context.SaveChanges();
foreach (var updateWood in shopWoods)
ShopWoods = context.ShopWoods.Where(rec => rec.ShopId == model.Id).ToList();
foreach (var updateWood in ShopWoods)
{
updateWood.Count =
model.ShopWoods[updateWood.WoodId].Item2;
updateWood.Count = model.ShopWoods[updateWood.WoodId].Item2;
model.ShopWoods.Remove(updateWood.WoodId);
}
context.SaveChanges();
}
var shop = context.Shops.First(x => x.Id == Id);
foreach (var pc in model.ShopWoods)
foreach (var ar in model.ShopWoods)
{
context.ShopWoods.Add(new ShopWood
{
Shop = shop,
Wood = context.Woods.First(x => x.Id == pc.Key),
Count = pc.Value.Item2
Wood = context.Woods.First(x => x.Id == ar.Key),
Count = ar.Value.Item2
});
context.SaveChanges();
}