public async Task <IActionResult> Create([Bind("Id,ClassName,TeacherId,Created")] SchoolClass schoolClass) { if (ModelState.IsValid) { schoolClass.Id = Guid.NewGuid(); _context.Add(schoolClass); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(schoolClass)); }
public async Task <IActionResult> Create([Bind("StudentId,SchoolClassId")] SchoolClassStudent schoolClassStudent) { if (ModelState.IsValid) { _context.Add(schoolClassStudent); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } ViewData["SchoolClassId"] = new SelectList(_context.SchoolClasses, "Id", "ClassName", schoolClassStudent.SchoolClassId); return(View(schoolClassStudent)); }
public async Task <IActionResult> Create([Bind("Id,ClassName,ProgramManagerId,Created")] SchoolClass schoolClass) { if (ModelState.IsValid) { schoolClass.Id = Guid.NewGuid(); _context.Add(schoolClass); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } ViewData["ProgramManagerId"] = new SelectList(_context.Set <AppUser>(), "Id", "Id", schoolClass.ProgramManagerId); return(View(schoolClass)); }
public async Task <IActionResult> Create([Bind("Id,ClassName,TeacherId,Created")] SchoolClass schoolClass) { var checkIfClassNameExists = _context.SchoolClasses.Where(sc => sc.ClassName == schoolClass.ClassName); if (checkIfClassNameExists.Count() == 1) { return(RedirectToAction("ClassAlreadyExists", "Admins")); } ; if (ModelState.IsValid) { schoolClass.Id = Guid.NewGuid(); schoolClass.Created = DateTime.Now; _context.Add(schoolClass); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(schoolClass)); }