public async Task <IActionResult> AddImage(ElementoImageViewModel model) { if (ModelState.IsValid) { var path = string.Empty; //TODO: Validar que sea png o jpg if (model.ImageFile != null) { path = await _imageHelper.UploadImageAsync(model.ImageFile); } var elementoImage = new ElementoImage { ImageUrl = path, Elemento = await _dataContext.Elementos.FindAsync(model.ElementoImageId) }; _dataContext.ElementoImages.Add(elementoImage); await _dataContext.SaveChangesAsync(); //return RedirectToAction($"{nameof(Details)}/{model.ElementoImageId}"); return(RedirectToAction("Details", "Elementos", new { @id = elementoImage.Elemento.ElementoID })); } return(View(model)); }
public async Task <IActionResult> AddImage(int?id) { if (id == null) { return(NotFound()); } var elemento = await _dataContext.Elementos.FindAsync(id.Value); if (elemento == null) { return(NotFound()); } var model = new ElementoImageViewModel { ElementoImageId = elemento.ElementoID }; return(View(model)); }