/// <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; } }
public static async Task<Task<IEnumerable<ActionResponseResult>>> DeleteStudentCohortAssocations(CohortActionObject obj, CohortService cs) { Task<IEnumerable<ActionResponseResult>> removeStudents; //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 (currentStudentCohortAssociation.FirstOrDefault(csca => csca.studentId == s))); //delete the studentCohortAssociation removeStudents = CohortActionHelper.DeleteMultipleStudentCohortAssociations(cs, associationToDelete); return removeStudents; }