async public static Task <Homework[]> CreateFromJsonString(string json, Student student, bool groupHardRefresh = false) { /// <summary> /// Static method that creates an array of `TaskObj` from an API response /// </summary> dynamic jsonObj = JsonConvert.DeserializeObject(json); Homework[] homeworks = new Homework[jsonObj.data.Count]; CustomList previousGroups = new CustomList(3); // Make a list of size 3 (every student normally takes 3/4 subjects) for (int i = 0; i < jsonObj.data.Count; i++) { dynamic homeworkObj = jsonObj.data[i]; int id = homeworkObj.id; string temp = homeworkObj.group.reference.link; Group group; if (previousGroups.Contains(temp) || !groupHardRefresh) // If that group has already been called in this subroutine OR no hard refresh, retreive from cache. { group = await APIHandler.GetGroup(hateoasLink : temp); } else { group = await APIHandler.GetGroup(hateoasLink : temp, hardRefresh : groupHardRefresh); previousGroups.Add(temp); } int maxScore = homeworkObj.max_score; string title = homeworkObj.title; string description = homeworkObj.description; DateTime dateDue = homeworkObj.date_due; DateTime dateSet = homeworkObj.date_set; bool hasCompleted = false; if (homeworkObj.has_completed != null) { hasCompleted = homeworkObj.has_completed; } homeworks[i] = new Homework(id, group, title, description, maxScore, dateDue, dateSet, hasCompleted: hasCompleted, student: student); } return(homeworks); }
async public static Task <Assignment[]> CreateFromJsonString(string json, bool groupHardRefresh = false) { /// <summary> /// Static method that creates an array of `TaskObj` from an API response /// </summary> dynamic jsonObj = JsonConvert.DeserializeObject(json); Assignment[] assignments = new Assignment[jsonObj.data.Count]; CustomList previousGroups = new CustomList(3); // Make a list of size 3 for (int i = 0; i < jsonObj.data.Count; i++) { dynamic homeworkObj = jsonObj.data[i]; int id = homeworkObj.id; string temp = homeworkObj.group.reference.link; Group group; if (previousGroups.Contains(temp) || !groupHardRefresh) { group = await APIHandler.GetGroup(hateoasLink : temp); } else { group = await APIHandler.GetGroup(hateoasLink : temp, hardRefresh : groupHardRefresh); previousGroups.Add(temp); } int maxScore = homeworkObj.max_score; string title = homeworkObj.title; string description = homeworkObj.description; DateTime dateDue = homeworkObj.date_due; DateTime dateSet = homeworkObj.date_set; assignments[i] = new Assignment(id, group, title, description, maxScore, dateDue, dateSet); } return(assignments); }