This commit is contained in:
Анна Забродина 2024-03-10 21:48:34 +04:00
commit e00013520c

View File

@ -87,7 +87,7 @@ namespace HotelDataBaseImplement.Models
{ {
var roomLunches = context.RoomLunches.Where(rec => rec.RoomId == model.Id).ToList(); var roomLunches = context.RoomLunches.Where(rec => rec.RoomId == model.Id).ToList();
if (roomLunches != null) if (roomLunches != null && roomLunches.Count > 0)
{ {
context.RoomLunches.RemoveRange(roomLunches.Where(rec => !model.RoomLunches.ContainsKey(rec.LunchId))); context.RoomLunches.RemoveRange(roomLunches.Where(rec => !model.RoomLunches.ContainsKey(rec.LunchId)));
context.SaveChanges(); context.SaveChanges();
@ -101,12 +101,12 @@ namespace HotelDataBaseImplement.Models
var room = context.Rooms.First(x => x.Id == Id); var room = context.Rooms.First(x => x.Id == Id);
foreach (var cm in model.RoomLunches) foreach (var lunch in model.RoomLunches)
{ {
context.RoomLunches.Add(new RoomLunch context.RoomLunches.Add(new RoomLunch
{ {
Room = room, Room = room,
Lunch = context.Lunches.First(x => x.Id == cm.Key) Lunch = context.Lunches.First(x => x.Id == lunch.Key)
}); });
context.SaveChanges(); context.SaveChanges();
} }