public async Task <IActionResult> CreateSpellingGroup(SpellingGroupViewModel SpellingGroupVM) { if (ModelState.IsValid) { SpellingGroup newList = new SpellingGroup() { Name = SpellingGroupVM.Name, Description = SpellingGroupVM.Description, TeacherUsername = User.Identity.Name }; try { await _context.SpellingGroups.AddAsync(newList); await _context.SaveChangesAsync(); ViewData["message"] = $"You have successfully created the Spelling Group named {newList.Name}"; } catch (Exception ex) // Make a log to enter this Exception ex { ViewData["message"] = "There was a problem updating the database. Please try again."; } } return(View()); }
public async Task <IActionResult> EditGroup(SpellingGroupViewModel spellingGroupVM) { if (ModelState.IsValid) { var spellingGroup = await _context.SpellingGroups.SingleOrDefaultAsync(g => g.SpellingGroupId == spellingGroupVM.SpellingGroupId); spellingGroup.Name = spellingGroupVM.Name; spellingGroup.Description = spellingGroupVM.Description; _context.SpellingGroups.Update(spellingGroup); await _context.SaveChangesAsync(); } return(RedirectToAction("CreateSpellingGroup")); }
// GET: Teacher/EditGroup // Go the the edit page for the selected group. public async Task <IActionResult> EditGroup(int?id) { if (id == null) { return(NotFound()); } else { var spellingGroup = await _context.SpellingGroups.SingleOrDefaultAsync(g => g.SpellingGroupId == id); SpellingGroupViewModel spellingGroupVM = new SpellingGroupViewModel() { Name = spellingGroup.Name, Description = spellingGroup.Description, SpellingGroupId = spellingGroup.SpellingGroupId }; return(View(spellingGroupVM)); } }