public IActionResult updateCourseProgress([FromBody] StudentCourseProgressDTO courseProgressDTO)
 {
     try
     {
         // TODO: also add the rating to mentor table
         var result = repository.UpdateCourseProgress(courseProgressDTO);
         if (result == 1)
         {
             return(Ok(new { Message = "Progress updated successfully!" }));
         }
         else if (result == 3)
         {
             return(NotFound(new { Message = "Error: Course not found!" }));
         }
         else if (result == 4)
         {
             return(Conflict(new { Message = "Action cannot be completed. Course is already complete or is not ongoing." }));
         }
         return(BadRequest(new { Message = "Internal server error. Try again later." }));
     }
     catch (Exception e)
     {
         return(BadRequest(e.InnerException));
     }
 }
Beispiel #2
0
 public int UpdateCourseProgress(StudentCourseProgressDTO courseProgressDTO)
 {
     try
     {
         var course = (from studentCourse in context.StudentCourses
                       join student in context.MODUsers on studentCourse.User equals student
                       where student.Email == courseProgressDTO.Email && studentCourse.CourseId == courseProgressDTO.CourseId
                       select studentCourse).FirstOrDefault();
         if (course != null)
         {
             if (course.Status != 4 || course.Status == 5)
             {
                 return(4); // already progress is 100 or not ongoing or not completed
             }
             course.Progress = courseProgressDTO.Progress;
             if (course.Progress == 100)
             {
                 course.Status = 5; // completed
             }
             context.StudentCourses.Update(course);
             var result = context.SaveChanges();
             if (result > 0)
             {
                 return(1); // success
             }
             return(2);     // error updating status failed
         }
         return(3);         // course not found
     }
     catch (Exception e)
     {
         throw e;
     }
 }