доделал
This commit is contained in:
parent
8029254363
commit
509b29b85d
@ -102,7 +102,6 @@ namespace TravelCompany.Forms
|
||||
Adress = textBoxAdress.Text,
|
||||
OpeningDate = dateTimeOpen.Value,
|
||||
TravelMaxCount = (int)numericUpTravelMaxCount.Value,
|
||||
ShopTravels = null
|
||||
};
|
||||
var operationResult = _id.HasValue ? _logic.Update(model) : _logic.Create(model);
|
||||
if (!operationResult)
|
||||
|
@ -12,7 +12,7 @@ using TravelCompanyDatabaseImplement;
|
||||
namespace TravelCompanyDatabaseImplement.Migrations
|
||||
{
|
||||
[DbContext(typeof(TravelCompanyDataBase))]
|
||||
[Migration("20240503064033_Initial-Create")]
|
||||
[Migration("20240506091037_Initial-Create")]
|
||||
partial class InitialCreate
|
||||
{
|
||||
/// <inheritdoc />
|
@ -72,35 +72,29 @@ namespace TravelCompanyDatabaseImplement.Models
|
||||
ShopTravels = ShopTravels,
|
||||
TravelMaxCount = TravelMaxCount
|
||||
};
|
||||
|
||||
public void UpdateTravels(TravelCompanyDataBase context, ShopBindingModel model)
|
||||
{
|
||||
if (model.ShopTravels == null)
|
||||
return;
|
||||
var shopTravels = context.ShopTravels.Where(rec =>
|
||||
rec.ShopId == model.Id).ToList();
|
||||
if (shopTravels != null && shopTravels.Count > 0)
|
||||
var ShopTravels = context.ShopTravels.Where(rec => rec.ShopId == model.Id).ToList();
|
||||
if (ShopTravels != null && ShopTravels.Count > 0)
|
||||
{
|
||||
context.ShopTravels.RemoveRange(shopTravels.Where(rec
|
||||
=> !model.ShopTravels.ContainsKey(rec.TravelId)));
|
||||
|
||||
context.ShopTravels.RemoveRange(ShopTravels.Where(rec => !model.ShopTravels.ContainsKey(rec.TravelId)));
|
||||
context.SaveChanges();
|
||||
foreach (var updateTravel in shopTravels)
|
||||
ShopTravels = context.ShopTravels.Where(rec => rec.ShopId == model.Id).ToList();
|
||||
foreach (var updateTravel in ShopTravels)
|
||||
{
|
||||
updateTravel.Count =
|
||||
model.ShopTravels[updateTravel.TravelId].Item2;
|
||||
updateTravel.Count = model.ShopTravels[updateTravel.TravelId].Item2;
|
||||
model.ShopTravels.Remove(updateTravel.TravelId);
|
||||
}
|
||||
context.SaveChanges();
|
||||
}
|
||||
var shop = context.Shops.First(x => x.Id == Id);
|
||||
foreach (var pc in model.ShopTravels)
|
||||
foreach (var ar in model.ShopTravels)
|
||||
{
|
||||
context.ShopTravels.Add(new ShopTravels
|
||||
{
|
||||
Shop = shop,
|
||||
Travel = context.Travels.First(x => x.Id == pc.Key),
|
||||
Count = pc.Value.Item2
|
||||
Travel = context.Travels.First(x => x.Id == ar.Key),
|
||||
Count = ar.Value.Item2
|
||||
});
|
||||
context.SaveChanges();
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user