public async Task <IActionResult> AddImage(PropertyImageViewMode model) { if (ModelState.IsValid) { var path = string.Empty; if (model.ImageFile != null) { path = await _imageHelper.UploadImageAsync(model.ImageFile); } var propertyImage = new PropertyImage { ImageUrl = path, Property = await _dataContext.Properties.FindAsync(model.Id) }; _dataContext.PropertyImages.Add(propertyImage); await _dataContext.SaveChangesAsync(); return(RedirectToAction($"{nameof(DetailsProperty)}/{model.Id}")); } return(View(model)); }
public async Task <IActionResult> AddImage(int?id) { if (id == null) { return(NotFound()); } var property = await _dataContext.Properties.FindAsync(id.Value); if (property == null) { return(NotFound()); } var model = new PropertyImageViewMode { Id = property.Id }; return(View(model)); }