public async Task <IActionResult> EditProfile(AccountProfileViewModel viewModel) { int userId = Convert.ToInt32(Convert.ToString(User.Claims.Where(claim => claim.Type == "Id").Select(claim => claim.Value).SingleOrDefault())); int accountId = accountLogic.GetAccountIdByUserId(userId); var user = viewModel.User; var account = viewModel.Account; if (viewModel.AccountImage != null) { var accountImage = viewModel.AccountImage; string accountImageFileName = accountImage.FileName; account.Image = accountImageFileName; //Add image to root of app string mapRoot = "images/UserImages/"; var accountImagePath = Path.Combine(_hostingEnvironment.WebRootPath, mapRoot); await AddFileToDirectory(accountImage, accountImagePath); } else { account.Image = viewModel.Account.Image; } user.Id = userId; user.AccountId = accountId; account.Id = accountId; //Toevoegen in database userLogic.EditUser(user); if (accountLogic.EditAccount(account)) { return(RedirectToAction("Profile")); } TempData["InvalidFields"] = "Er is iets fout gegaan bij het aanpassen van de accountgegevens, probeer het opnieuw!"; return(RedirectToAction("Profile")); }