public async Task <IActionResult> StudentSelect(StuSelect student) { if (!ModelState.IsValid) { return(RedirectToAction("FinalSelection")); } else { var targetUser = _dbContext.StuSelection.SingleOrDefault(i => i.StuId.Equals(User.Identity.Name, StringComparison.CurrentCulture)); targetUser = new StuSelection { StuId = User.Identity.Name, FirstSelection = student.Selection.Department1, SecondSelection = student.Selection.Department2, ShirdSelection = student.Selection.Department3, FourthSelection = student.Selection.Department4 }; await _dbContext.StuSelection.AddAsync(targetUser); await _dbContext.SaveChangesAsync(); return(RedirectToAction("StudentSelect", "StudentSelection")); } }
public IActionResult StudentSelectChange(StuSelect student) { if (!ModelState.IsValid) { return(RedirectToAction("StudentSelect", "StudentSelection")); } else { //var targetUser = _dbContext.StuSelection.SingleOrDefault(i => i.StuId.Equals(User.Identity.Name, StringComparison.CurrentCulture)); var targetUser = new StuSelection { StuId = User.Identity.Name, FirstSelection = student.Selection.Department1, SecondSelection = student.Selection.Department2, ShirdSelection = student.Selection.Department3, FourthSelection = student.Selection.Department4 }; _dbContext.StuSelection.Update(targetUser); _dbContext.SaveChanges(); return(RedirectToAction("Index", "Home")); } }