public JsonResult DeleteGrade(int gradeId) { Grade grade = new Grade(); UnitOfWork unitOfWork = new UnitOfWork(); GradeRepository gradeRepository = new GradeRepository(); grade = gradeRepository.GetById(gradeId); gradeRepository.Delete(grade); unitOfWork.Commit(); return Json("successfully deleted", 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); }
public JsonResult GetGrade(int gradeId) { Grade grade = new Grade(); GradeRepository gradeRepository = new GradeRepository(); grade = gradeRepository.GetById(gradeId); SelectListItem gradeItem = new SelectListItem() { Text = grade.GradeValue.ToString(), Value = grade.Id.ToString(), }; return Json(gradeItem, JsonRequestBehavior.AllowGet); }