public ActionResult AddGrade(GradeAddGradeVM model) { if (model.GradeValue < 2 || model.GradeValue > 6) { ModelState.AddModelError("Error", "Grade must be 2 - 6"); return View(model); } GradeRepository gRepo = new GradeRepository(); Grade grade = new Grade(); var test = gRepo.GetAll(filter: g => g.StudentID == model.StudentID && g.SubjectID == model.SubjectID).FirstOrDefault(); if (test != null) { ModelState.AddModelError("Error", "Student already have grade"); return View(model); } grade.StudentID = model.StudentID; grade.SubjectID = model.SubjectID; grade.GradeValue = model.GradeValue; gRepo.Save(grade); return RedirectToAction("StudentsGrades" + "/" + model.SubjectID, "Grade"); }
public JsonResult AddGradeToStudent(int gradevalue, int studentid, int subjectid) { GradeRepository gradeRepo = new GradeRepository(); Grade grade = gradeRepo.GetAll(filter: g => g.StudentID == studentid && g.SubjectID == subjectid).FirstOrDefault(); if (grade == null) { grade = new Grade(); grade.StudentID = studentid; grade.GradeValue = gradevalue; grade.SubjectID = subjectid; gradeRepo.Save(grade); return Json(true); } return Json(false); }