public async Task <IActionResult> AddImage(LibroImageViewModel model) { if (ModelState.IsValid) { var path = string.Empty; if (model.ImageFile != null) { path = await _imageHelper.UploadImageAsync(model.ImageFile); } var imagenLibro = new ImagenLibro { ImageUrl = path, Libro = await _dataContext.Libros.FindAsync(model.Id) }; _dataContext.ImagenLibros.Add(imagenLibro); await _dataContext.SaveChangesAsync(); return(RedirectToAction($"{nameof(DetailsLibro)}/{model.Id}")); } return(View(model)); }
public async Task <IActionResult> AddImage(int?id) { if (id == null) { return(NotFound()); } var libro = await _dataContext.Libros.FindAsync(id.Value); if (libro == null) { return(NotFound()); } var model = new LibroImageViewModel { Id = libro.Id }; return(View(model)); }