public async Task <IActionResult> OnPostAsync() { var user = await _userManager.GetUserAsync(User); CurrentColorName = user.SecurityColorAnswer; CurrentColorSelection = CurrentColorName.ToLower(); CurrentSymbolName = user.SecuritySymbolAnswer; CurrentSymbolSelection = "fas fa-" + CurrentSymbolName.ToLower(); @TempData["SecurityColorSelection"] = Input.SecurityColorAnswer; @TempData["SecuritySymbolSelection"] = Input.SecuritySymbolAnswer; if (!ModelState.IsValid) { StatusMessage = ""; return(Page()); } if (user == null) { throw new ApplicationException($"Unable to load user with ID '{_userManager.GetUserId(User)}'."); } if (Input.SecurityColorAnswer != user.SecurityColorAnswer || Input.SecuritySymbolAnswer != user.SecuritySymbolAnswer) { ApplicationUser = await _context.ApplicationUser.SingleOrDefaultAsync(m => m.Id == user.Id); ApplicationUser.SecurityColorAnswer = Input.SecurityColorAnswer; ApplicationUser.SecuritySymbolAnswer = Input.SecuritySymbolAnswer; _context.Attach(ApplicationUser).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!ApplicationUserExists(ApplicationUser.Id)) { return(NotFound()); } else { throw; } } StatusMessage = "Security Selections Successfully Updated!"; _logger.LogInformation("User changed their security selections successfully."); } else { StatusMessage = "Security Selections Not Changed!"; } return(RedirectToPage("/Index")); }
public async Task <IActionResult> OnGetAsync() { var user = await _userManager.GetUserAsync(User); if (user == null) { throw new ApplicationException($"Unable to load user with ID '{_userManager.GetUserId(User)}'."); } CurrentColorName = user.SecurityColorAnswer; CurrentColorSelection = CurrentColorName.ToLower(); CurrentSymbolName = user.SecuritySymbolAnswer; CurrentSymbolSelection = "fas fa-" + CurrentSymbolName.ToLower(); @TempData["SecurityColorSelection"] = ""; @TempData["SecuritySymbolSelection"] = ""; Input = new InputModel { }; return(Page()); }