public async Task <ResponseHelper> Update(ArtistUpdateDto model, IFormFile file = null) { var result = new ResponseHelper(); try { var originalEntry = await _context.Artists.SingleAsync(x => x.ArtistId == model.ArtistId); Mapper.Map(model, originalEntry); if (file != null && file.Length > 0) { var filePath = _hostingEnvironment.WebRootPath + @"\uploads\" + file.FileName; using (var stream = new FileStream(filePath, FileMode.Create)) { await file.CopyToAsync(stream); originalEntry.LogoUrl = file.FileName.ToLower().Trim(); } } _context.Update(originalEntry); await _context.SaveChangesAsync(); result.IsSuccess = true; } catch (Exception ex) { _logger.LogError(ex.Message); } return(result); }
public ActionResult UpdateArtist(int id, ArtistUpdateDto artistUpdateDto) { var artistFromRepo = _artistRepository.GetArtist(id); if (artistFromRepo == null) { return(NotFound()); } _mapper.Map(artistUpdateDto, artistFromRepo); _artistRepository.UpdateArtist(artistFromRepo); _artistRepository.SaveChanges(); return(NoContent()); }
public async Task <IActionResult> Update(ArtistUpdateDto model, IFormFile file = null) { if (ModelState.IsValid) { var result = await _artistService.Update(model, file); if (result.IsSuccess) { return(RedirectToAction("Index")); } throw new Exception("No se pudo actualizar el artista"); } return(View(model)); }