/// <summary> /// AJAX to this method to update existing groups with students /// </summary> /// <param name="obj"></param> /// <returns></returns> public async Task<string> UpdateGroup(CohortActionObject obj) { try { var cs = new CohortService(Session["access_token"].ToString()); var cohort = UpdateCohort(cs, obj.cohort); //1) update cohort var newStudentsAssociations = CreateMultipleAssociation(cs, obj.cohort.id, obj.studentsToCreate); //2) create student cohort association var cohortCustom = cs.UpdateCohortCustom(obj.cohort.id, JsonConvert.SerializeObject(obj.custom)); //3) update cohort custom entity //Get a list of the current studentCohortAssociations so that we have the ids to delete them from group var currentStudentCohortAssociation = await cs.GetStudentCohortAssociationsByCohortId(obj.cohort.id); //get the studentCohortAssociationId for students to delete var associationToDelete = (from s in obj.studentsToDelete select (from csca in currentStudentCohortAssociation where csca.studentId == s.id select csca.id).Single()); //delete the studentCohortAssociation var removeStudents = DeleteMultipleAssociation(cs, associationToDelete); await Task.WhenAll(newStudentsAssociations, cohortCustom, removeStudents); return "Success"; } catch (Exception e) { //handle throw; } }
/// <summary> /// Update cohort custom entity /// </summary> /// <param name="obj">Cohort data to update</param> /// <param name="cs">Cohort Service object to update</param> /// <returns></returns> public static Task<HttpResponseMessage> UpdateCustom(CohortActionObject obj, CohortService cs) { var custom = obj.custom; if (custom == null) custom = new CohortCustom { lastModifiedDate = DateTime.UtcNow }; else custom.lastModifiedDate = DateTime.UtcNow; var cohortCustom = cs.UpdateCohortCustom(obj.cohort.id, JsonConvert.SerializeObject(custom)); return cohortCustom; }