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); }
public JsonResult EditGrade(int gradeId, double gradeValue, int subjectId, int studentId) { Grade grade = new Grade(); GradeRepository gradeRepo = new GradeRepository(); SelectListItem gradeItem = null; if (gradeId != 0) { grade = gradeRepo.GetById(gradeId); gradeValue = System.Math.Round(gradeValue, 2); grade.GradeValue = gradeValue; gradeRepo.Save(grade); } else { UnitOfWork unitOfWork = new UnitOfWork(); StudentRepository studentRepository = new StudentRepository(unitOfWork); GradeRepository gradeRepository = new GradeRepository(unitOfWork); SubjectRepository subjectRepository = new SubjectRepository(unitOfWork); Student student = new Student(); student = studentRepository.GetById(studentId); Subject subject = new Subject(); subject = subjectRepository.GetById(subjectId); grade.SubjectID = subjectId; grade.Subject = subject; grade.Student = student; gradeValue = System.Math.Round(gradeValue, 2); grade.GradeValue = gradeValue; gradeRepository.Save(grade); unitOfWork.Commit(); } gradeItem = new SelectListItem() { Text = grade.GradeValue.ToString(), Value = grade.Id.ToString() }; return(Json(gradeItem, JsonRequestBehavior.AllowGet)); }
public JsonResult EditGrade(int gradeId, double gradeValue, int subjectId, int studentId) { Grade grade = new Grade(); GradeRepository gradeRepo = new GradeRepository(); SelectListItem gradeItem = null; if (gradeId != 0) { grade = gradeRepo.GetById(gradeId); gradeValue = System.Math.Round(gradeValue, 2); grade.GradeValue = gradeValue; gradeRepo.Save(grade); } else { UnitOfWork unitOfWork = new UnitOfWork(); StudentRepository studentRepository = new StudentRepository(unitOfWork); GradeRepository gradeRepository = new GradeRepository(unitOfWork); SubjectRepository subjectRepository = new SubjectRepository(unitOfWork); Student student = new Student(); student = studentRepository.GetById(studentId); Subject subject = new Subject(); subject = subjectRepository.GetById(subjectId); grade.SubjectID = subjectId; grade.Subject = subject; grade.Student = student; gradeValue = System.Math.Round(gradeValue, 2); grade.GradeValue = gradeValue; gradeRepository.Save(grade); unitOfWork.Commit(); } gradeItem = new SelectListItem() { Text = grade.GradeValue.ToString(), Value = grade.Id.ToString() }; return Json(gradeItem, JsonRequestBehavior.AllowGet); }