public async Task <IActionResult> Edit(int id, [Bind("Id,StudentId,EventId,State,SectionId,GradeEarned")] Grade grade) { if (id != grade.Id) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(grade); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!GradeExists(grade.Id)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } return(View(grade)); }
public IActionResult ChangeGrade([Bind("x,y,z,ChangeState,sectionId")] int?id) { //getViewModel(id); int x = -1; int y = -1; int studId = -1; int newState = -1; int sectionId = -1; if (int.TryParse(HttpContext.Request.Form["x"], out x)) { } else { } if (int.TryParse(HttpContext.Request.Form["y"], out y)) { } else { } if (int.TryParse(HttpContext.Request.Form["z"], out studId)) { } else { } if (int.TryParse(HttpContext.Request.Form["ChangeState"], out newState)) { } else { } //if (int.TryParse(HttpContext.Request.Form["sectionId"], out sectionId)) //{ //} //else //{ //} //Load proper grade var newGrade = _gradeContext.Grade.First(t => (t.SectionId == id) && (t.EventId == y) && (t.StudentId == studId) ); if (newGrade != null) { newGrade.State = newState - 1; _gradeContext.Update(newGrade); _gradeContext.SaveChanges(); } return(RedirectToAction(nameof(Index))); }