diff --git a/Hotel/HotelDataBaseImplement/Models/Room.cs b/Hotel/HotelDataBaseImplement/Models/Room.cs index 4aa5582..21877f1 100644 --- a/Hotel/HotelDataBaseImplement/Models/Room.cs +++ b/Hotel/HotelDataBaseImplement/Models/Room.cs @@ -87,7 +87,7 @@ namespace HotelDataBaseImplement.Models { 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.SaveChanges(); @@ -101,12 +101,12 @@ namespace HotelDataBaseImplement.Models 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 { Room = room, - Lunch = context.Lunches.First(x => x.Id == cm.Key) + Lunch = context.Lunches.First(x => x.Id == lunch.Key) }); context.SaveChanges(); }