public static async Task <Rubric> GenerateRubric(string courseID, string rubricId) { Rubric resultRubric = new Rubric(); resultRubric.id = rubricId; var sectionURI = canvasAPIurl + $"/courses/{courseID}/rubrics/{rubricId}"; var response = webber.GetAsync(sectionURI).Result; var content = await response.Content.ReadAsStringAsync(); JObject jsonData = JsonConvert.DeserializeObject <JObject>(content); JArray criteriaData = (JArray)jsonData["data"]; foreach (JToken criterion in criteriaData) { Rubric.Criterion tempCriterion = new Rubric.Criterion(); tempCriterion.id = (string)criterion["id"]; JArray ratingData = (JArray)criterion["ratings"]; foreach (JToken rating in ratingData) { Rubric.Criterion.Rating tempRating = new Rubric.Criterion.Rating(); tempRating.id = (string)rating["id"]; tempRating.points = (Decimal)rating["points"]; tempCriterion.ratings.Add(tempRating); } resultRubric.criteria.Add(tempCriterion); } return(resultRubric); }
public static async Task FerbyTask(string courseID, Dictionary <string, string> canvasStudents, string assessmentID, List <Student> studentsFromFile, Rubric rubric) { int counter = 0; foreach (var student in studentsFromFile) { string studentName = (student.firstName + " " + student.lastName).ToLower(); if (canvasStudents.ContainsKey(studentName)) { var gradeURI = canvasAPIurl + $"courses/{courseID}/assignments/{assessmentID}/submissions/{canvasStudents[studentName]}"; var response = await webber.GetAsync(gradeURI); var content = await response.Content.ReadAsStringAsync(); JObject jsonData = JsonConvert.DeserializeObject <JObject>(content); var stringCheck = jsonData["grade"].ToString(); if (stringCheck != "") { Console.WriteLine("Grade not null"); if (!overwriteGrades) { continue; } } Dictionary <string, string> temp = new Dictionary <string, string>(); List <string> listOfQueries = new List <string>(); if (student.rubricGrades.Count != rubric.criteria.Count) { throw new Exception("mismatch of criteria count"); } for (int i = 0; i < rubric.criteria.Count; i++) { var criterion = rubric.criteria[i]; temp.Add($"rubric_assessment[{criterion.id}][points]", Convert.ToString(student.rubricGrades[i])); listOfQueries.Add($"rubric_assessment[{criterion.id}][points]={student.rubricGrades[i]}"); string ratingIDChosen = ""; for (int j = 0; j < criterion.ratings.Count; j++) { if (criterion.ratings[j].points <= student.rubricGrades[i]) { ratingIDChosen = criterion.ratings[j].id; break; } } temp.Add($"rubric_assessment[{criterion.id}][rating_id]", ratingIDChosen); //listOfQueries } if (!string.IsNullOrEmpty(student.comment)) { temp.Add("comment[text_comment]", student.comment); } var payload = new FormUrlEncodedContent(temp); response = await webber.PutAsync(gradeURI, payload); Console.WriteLine($"{++counter} students graded"); } } }