public async Task <IActionResult> ChangeSchool(ChangeSchoolViewModel model) { if (!ModelState.IsValid) { return(View(model)); } var user = await GetCurrentUserAsync(); if (user != null) { user.School = _context.Schools.Where(a => a.ID == model.School).FirstOrDefault(); user.SchoolID = model.School; var result = await _userManager.UpdateAsync(user); if (result.Succeeded) { await _context.SaveChangesAsync(); await _signInManager.SignInAsync(user, isPersistent : false); return(RedirectToAction(nameof(Index), new { Message = ManageMessageId.ChangeSchoolSuccess })); } } return(RedirectToAction(nameof(Index), new { Message = ManageMessageId.Error })); }
public async Task <IActionResult> ChangeSchool() { var user = await GetCurrentUserAsync(); if (user == null) { return(View("Error")); } var model = new ChangeSchoolViewModel { OldSchool = user.SchoolID, Schools = _context.Schools.Where(a => a.Status == 1).ToList() }; return(View(model)); }