public async Task <IActionResult> LoadCottageEditForm(int cottid) { //TODO: Refactor. var cottage = await _cottageRepository.GetCottageWithImagesAsync(cottid); var vm = new CottageFormViewModel { Cottage = new Cottage() }; vm.Cottage = cottage; return(View("Forms/CottageEditForm", vm)); }
public async Task <IActionResult> SubmitCottageEditForm(CottageFormViewModel vm) { var cottage = await _cottageRepository.GetAsync(vm.Cottage.Id); cottage.Description = vm.Cottage.Description; cottage.Name = vm.Cottage.Name; cottage.PricePerNight = vm.Cottage.PricePerNight; cottage.IsVisibleToClient = vm.Cottage.IsVisibleToClient; await _cottageRepository.SaveAsync(); return(RedirectToAction("LoadAllCottages", "Admin")); }
public async Task <IActionResult> SubmitCottageForm(List <IFormFile> images, CottageFormViewModel vm) { var cottage = new Cottage() { Description = vm.Cottage.Description, ImageGroup = new ImageGroup(), IsVisibleToClient = true, Name = vm.Cottage.Name, PricePerNight = vm.Cottage.PricePerNight }; cottage.ImageGroup.Images = new List <Image>(); WriteImages(images); AddImages(ref cottage, images); await _cottageRepository.AddAysnc(cottage); await _cottageRepository.SaveAsync(); return(RedirectToAction("Index", "Admin")); }