public void EditApartment(Apartment apartment) { var apa = Apartments.SingleOrDefault(s => s.Id == apartment.Id); Entry(apa).CurrentValues.SetValues(apartment); apa.Amenities = new List <Amenities>(); foreach (var item in apartment.Amenities) { apa.Amenities.Add(Amenities.SingleOrDefault(s => s.Id == item.Id)); } SaveChanges(); }
public void RemoveApartment(int apartmentId) { var apa = Apartments.SingleOrDefault(s => s.Id == apartmentId); var comments = Comments.Where(s => s.Apartment.Id == apa.Id && s.IsDeleted == false); foreach (var item in comments) { item.IsDeleted = true; } var reservations = Reservations.Where(r => r.IsDeleted == false && r.ReservedApartment.Id == apartmentId); foreach (var item in reservations) { item.IsDeleted = true; } apa.IsDeleted = true; SaveChanges(); }