public HotelEditViewModel Update(HotelEditViewModel Hotel) { Hotel _Hotel = HotelRepo.Update(Hotel.toModel()); if (Hotel.HotelImages != null && Hotel.HotelImages.Count() > 0) { var toAdd = Hotel.HotelImages.Where(i => i.ID == 0); foreach (var image in toAdd) { ImagRepo.Add(image.toModel()); } var toUpdate = Hotel.HotelImages.Where(i => i.ID > 0); foreach (var image in toUpdate) { ImagRepo.Update(image.toModel()); } int[] ids = Hotel.HotelImages.Select(x => x.ID).ToArray(); var toDelete = ImagRepo.GetFilter(i => !ids.Contains(i.ID) && i.HotelID == Hotel.ID); foreach (var image in toDelete) { ImagRepo.Remove(image); } //unitOfWork.commit(); } unitOfWork.commit(); return(_Hotel.toEditViewModel()); }
public HotelEditViewModel Update(HotelEditViewModel Hotel) { Hotel _Hotel = HotelRepo.Update(Hotel.toModel()); unitOfWork.commit(); return(_Hotel.toEditViewModel()); }
public HotelEditViewModel Add(HotelEditViewModel Hotel) { Hotel _Hotel = HotelRepo.Add(Hotel.toModel()); unitOfWork.commit(); if (Hotel.HotelImages != null && Hotel.HotelImages.Count() > 0) { foreach (var image in Hotel.HotelImages) { image.HotelID = _Hotel.ID; ImagRepo.Add(image.toModel()); } } unitOfWork.commit(); return(_Hotel.toEditViewModel()); }
public void Remove(HotelEditViewModel Hotel) { HotelRepo.Remove(Hotel.toModel()); unitOfWork.commit(); }