/// <summary> /// create a student grade row in StudenGrade table /// </summary> /// <param name="grade"></param> /// <returns> /// boolean value indicates success/failure /// </returns> public bool Insert(InsertingGrade grade) { using (IDbConnection connection = new SqlConnection(dbConnection)) { // inserting student garade to StudentGrade table int result = connection.Execute(_AddStudentGrade, new { CourseId = grade.CourseId, StudentId = grade.StudentId, Grade = grade.Grade }); var isSuccess = (result == 1) ? true : false; return(isSuccess); } }
public ActionResult <ReturningGrade> InsertGrade([FromBody] InsertingGrade grade) { Person person = _personRepository.GetPersonById(grade.StudentId); Course course = _courseRepository.GetCourseByCourseId(grade.CourseId); if (person == null) { // no person record in the database return(BadRequest(String.Format("{0} is not a valid person id.", grade.StudentId.ToString()))); } else if (course == null) { // not course record in the database return(BadRequest(String.Format("{0} is not a valid course id.", grade.CourseId.ToString()))); } else { if (person.Discriminator.ToLower().Equals("student")) { var combinationExists = _studentService.IsStudentCourseCombinationExists(grade); if (!combinationExists) { // makes a call to create a row in database var result = _studentService.InsertStudentGrade(grade); // returns a failure message when insertion fails if (result == null) { return(BadRequest("The application fails to create a record in database.")); } return(result); } return(BadRequest("The student and course combination is already in the database.")); } else { // reutrns a message when the person record is not a student return(BadRequest(String.Format("{0} is not a valid student id.", grade.StudentId.ToString()))); } } }
/// <summary> /// insert grade into database /// </summary> /// <param name="grade"></param> /// <returns> /// returning grade object of the record /// </returns> public ReturningGrade InsertStudentGrade(InsertingGrade grade) { var result = _studentGradeRepository.Insert(grade); ReturningGrade returningGrade = null; if (result) { StudentGrade studentGrade = _studentGradeRepository.GetStudentGradeByIds(grade.StudentId, grade.CourseId); returningGrade = new ReturningGrade() { GradeId = studentGrade.EnrollmentId, CourseId = studentGrade.CourseId, StudentId = studentGrade.StudentId, Grade = studentGrade.Grade }; } return(returningGrade); }
/// <summary> /// check if the combination of the student & course already exists /// </summary> /// <param name="grade"></param> /// <returns> /// boolean valu indicates it exists or not /// </returns> public bool IsStudentCourseCombinationExists(InsertingGrade grade) { var combinationExists = _studentGradeRepository.IsStudentCourseCombinationExists(grade.StudentId, grade.CourseId); return(combinationExists); }