public async Task <IActionResult> PopulateGradeSheet(int id) { int findId = 0; if (int.TryParse(HttpContext.Request.Form["RosterNum"], out findId)) { } else { findId = 0; } Section section = await _context.Section.FindAsync(findId); Student stud = await _studContext.Student.FindAsync(id); //Grade grade = new Grade(); var events = _eventContext.Event.Where(c => c.EventCode == section.EventCode); foreach (Event ev in events) { _gradeContext.Add(new Grade { SectionId = findId, StudentId = stud.Id, EventId = ev.Id }); } await _gradeContext.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); }
public async Task <IActionResult> Create([Bind("Id,StudentId,EventId,State,SectionId,GradeEarned")] Grade grade) { if (ModelState.IsValid) { _context.Add(grade); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(grade)); }