public async Task <IActionResult> AddImage(ImageHospitalViewModel model) { if (ModelState.IsValid) { var path = string.Empty; if (model.ImageFile != null) { path = await _imageHelper.UploadImageAsync(model.ImageFile); } var hospitalImage = new ImageHospital { ImageUrl = path, Hospital = await _dataContext.Hospitals.FindAsync(model.Id) }; _dataContext.ImageHospitals.Add(hospitalImage); await _dataContext.SaveChangesAsync(); return(RedirectToAction($"{nameof(Details)}/{model.Id}")); } return(View(model)); }
public async Task <IActionResult> AddImage(int?id) { if (id == null) { return(NotFound()); } var hospital = await _dataContext.Hospitals.FindAsync(id.Value); if (hospital == null) { return(NotFound()); } var model = new ImageHospitalViewModel { Id = hospital.Id }; return(View(model)); }