public async Task <IActionResult> PostUploadProfilePicture(List <IFormFile> UploadDefault) { try { var folderUpload = "upload"; var fileName = await _functionalService.UploadFile(UploadDefault, _env, folderUpload); ApplicationUser appUser = await _userManager.GetUserAsync(User); if (appUser != null) { UserProfile profile = _context.UserProfile.SingleOrDefault(x => x.ApplicationUserId.Equals(appUser.Id)); if (profile != null) { profile.ProfilePicture = "/" + folderUpload + "/" + fileName; _context.UserProfile.Update(profile); await _context.SaveChangesAsync(); } } return(Ok(fileName)); } catch (Exception ex) { return(StatusCode(500, new { message = ex.Message })); } }
public async Task <IActionResult> PostUploadProfilePicture(IFormFile file) { try { var IdCurent = User.FindFirst("UserId").Value.ToString(); var appUser = await _context.AppUsers.Where(x => x.Id.ToString() == IdCurent).SingleOrDefaultAsync(); var folderUpload = "uploaded"; var fileName = await _functionalService.UploadFile(file, _hostingEnvironment, folderUpload, IdCurent); var webRoot = _hostingEnvironment.ContentRootPath; if (appUser != null) { appUser.Avatar = "/" + folderUpload + "/" + fileName; _context.AppUsers.Update(appUser); await _context.SaveChangesAsync(); } return(Ok(fileName)); } catch (Exception ex) { return(StatusCode(500, new { message = ex.Message })); } }