/// <summary> /// Create a single cohort /// </summary> /// <returns></returns> public async Task<string> CreateCohort(CohortService cs, Cohort cohort) //TODO: modify to accept a cohort argument { try { //var cs = new CohortService(Session["access_token"].ToString()); //var cohort = new Cohort(); //var random = new Random(); //cohort.educationOrgId = "2012dh-836f96e7-0b25-11e2-985e-024775596ac8"; //cohort.cohortIdentifier = "ACC-TEST-COH-" + random.Next(10); //cohort.cohortType = SlcClient.Enum.CohortType.ExtracurricularActivity; var result = await cs.Create(cohort); //result.Headers.Location.AbsolutePath.Substring(result.Headers.Location.AbsolutePath.LastIndexOf("/") + 1) return result.Headers.Location.Segments[5]; //getting the id from header location } catch { throw; } }
/// <summary> /// Create a single cohort /// </summary> /// <returns>result of the cohort creation</returns> public async Task<Result> CreateCohort(CohortService cs, Cohort cohort) //TODO: modify to accept a cohort argument { try { var userSession = (UserSession)Session[INBLOOM_USER_SESSION]; //set temporary edorgid because it's null from the INBLOOM API if (userSession != null && userSession.edOrgId != null && userSession.edOrgId != "") cohort.educationOrgId = userSession.edOrgId; else cohort.educationOrgId = CURRENT_ED_ORG_ID; cohort.cohortType = InBloomClient.Enum.CohortType.Other; var response = await cs.Create(cohort); var result = new Result { completedSuccessfully = response.StatusCode == HttpStatusCode.Created, objectActionResult = GlobalHelper.GetActionResponseResult("", cohort.cohortIdentifier, response, HttpStatusCode.Created) }; if (response.StatusCode == HttpStatusCode.Created) { //another way of getting the Id: result.Headers.Location.AbsolutePath.Substring(result.Headers.Location.AbsolutePath.LastIndexOf("/") + 1) result.objectActionResult.objectId = response.Headers.Location.Segments[5]; //getting the id from header location result.objectActionResult.objectName = cohort.cohortIdentifier; } return result; } catch { throw; } }