public async Task <IActionResult> AddImage(PropertySupervisorImageViewModel viewModel) { if (ModelState.IsValid) { var path = string.Empty; if (viewModel.ImageFile != null) { path = await _imageHelper.UploadImageAsync(viewModel.ImageFile); } var propertySupervisorImage = new PropertySupervisorImage { ImageUrl = path, PropertySupervisor = await _dataContext.PropertySupervisors.FindAsync(viewModel.Id) }; _dataContext.PropertySupervisorImages.Add(propertySupervisorImage); await _dataContext.SaveChangesAsync(); return(RedirectToAction("DetailsProperty", "Supervisors", new { id = viewModel.Id })); } return(View(viewModel)); }
public async Task <IActionResult> AddImage(int?id) { if (id == null) { return(NotFound()); } var propertySupervisor = await _dataContext.PropertySupervisors.FindAsync(id.Value); if (propertySupervisor == null) { return(NotFound()); } var model = new PropertySupervisorImageViewModel { Id = propertySupervisor.Id }; return(View(model)); }