public void GradeAssignment(GradeAssignmentRequest request) { using (var cn = new SqlConnection(Settings.GetConnectionString())) { var p = new DynamicParameters(); p.Add("RosterAssignmentId", request.RosterAssignmentId); if (request.PointsEarned.HasValue) { p.Add("PointsEarned", request.PointsEarned); p.Add("Percentage", request.Percentage); p.Add("Grade", request.AssignmentGrade); } cn.Execute("spUpdateRosterAssignment", p, commandType: CommandType.StoredProcedure); } }
public CourseGradedAssignmentResponse GradeAssignment(int rosterId, int rosterAssignmentId, decimal? pointsEarned, int pointsPossible) { var response = new CourseGradedAssignmentResponse(); //Validation if (pointsEarned < 0) { response.Message = "Points earned cannot be negative."; return response; } //Update grade for the assignment var request = new GradeAssignmentRequest() { PointsEarned = pointsEarned, RosterAssignmentId = rosterAssignmentId, RosterId = rosterId }; if (pointsEarned.HasValue) { request.Percentage = pointsEarned/pointsPossible*100M; response.Percentage = request.Percentage; request.AssignmentGrade = ConvertPercentToGrade(request.Percentage.Value); } if (request.Percentage > 999M) { response.Message = "Points earned cannot exceed 999% of the possible points"; return response; } try { _assignmentRepository.GradeAssignment(request); response.Success = true; } catch (Exception ex) { response.Success = false; response.Message = ex.Message; return response; } //Update overall course grade var updateCourseGradeResponse = UpdateOverallGrade(rosterId); if (updateCourseGradeResponse.Success) { response.OverallGrade = updateCourseGradeResponse.Data; } else { response.Message = updateCourseGradeResponse.Message; } return response; }
public void CanGradeAssignment() { var gradebook = _repo.GetGradebookForCourseId(1); var target = gradebook.First(); var pointsBefore = target.PointsEarned; var request = new GradeAssignmentRequest() { AssignmentGrade = "A", Percentage = 100.00M, PointsEarned = 10, RosterAssignmentId = target.RosterAssignmentId, RosterId = target.RosterId }; _repo.GradeAssignment(request); gradebook = _repo.GetGradebookForCourseId(1); target = gradebook.First(a => a.RosterAssignmentId == target.RosterAssignmentId); Assert.AreNotEqual(pointsBefore, target.PointsEarned); Assert.IsTrue(target.PointsEarned == 10); }