Доделал многие-ко-многим Машина Комплектация

This commit is contained in:
Леонид Малафеев 2024-04-28 16:46:17 +04:00
parent fb65ccd9a2
commit 8a4a34b232
2 changed files with 18 additions and 0 deletions

View File

@ -29,5 +29,6 @@ namespace CarCenterDatabaseImplement
public virtual DbSet<Request> Requests { set; get; }
public virtual DbSet<Feature> Features { set; get; }
public virtual DbSet<Bundling> Bundlings { set; get; }
public virtual DbSet<CarBundling> CarBundlings { set; get; }
}
}

View File

@ -74,6 +74,22 @@ namespace CarCenterDatabaseImplement.Models
}).ToList()
};
}
public void UpdateBundlings(CarCenterDatabase context, CarBindingModel model)
{
var car = context.Cars.First(x => x.Id == Id);
foreach (var pc in model.CarBundlings)
{
context.CarBundlings.Add(new CarBundling
{
Car = car,
Bundling = context.Bundlings.First(x => x.Id == pc.Key),
});
context.SaveChanges();
}
_carBundlings = null;
}
public void Update(CarBindingModel model)
{
if (model == null)
@ -104,6 +120,7 @@ namespace CarCenterDatabaseImplement.Models
Price = Price,
VINnumber = VINnumber,
FeatureID = FeatureID,
CarBundlings = CarBundlings,
};
}
}