コード例 #1
0
 /// <summary>
 /// Create a cohort
 /// https://api.sandbox.slcedu.org/api/rest/v1/cohorts
 /// Validation failed: ValidationError [type=REQUIRED_FIELD_MISSING, fieldName=cohortIdentifier, fieldValue=, expectedTypes=[STRING]] 
 /// ValidationError [type=REQUIRED_FIELD_MISSING, fieldName=cohortType, fieldValue=, expectedTypes=[TOKEN]] 
 /// ValidationError [type=REQUIRED_FIELD_MISSING, fieldName=educationOrgId, fieldValue=, expectedTypes=[REFERENCE]]",
 /// cohortType: Academic Intervention, Attendance Intervention, Discipline Intervention, Classroom Pullout, Extracurricular Activity, Field Trip, Principal Watch List, 
 /// Counselor List, In-school Suspension, Study Hall, Other
 /// </summary>
 /// <param name="token"></param>
 /// <param name="cohort">Required properties: cohortIdentifier, cohortType, and educationOrgId</param>
 /// <returns></returns>
 public HttpResponseMessage Post(Cohort obj)
 {
     try
     {
         var result = _cohortService.Create(obj).Result;
         return result;
     }
     catch(Exception e)
     {
         var notFoundMessage = new HttpResponseMessage(HttpStatusCode.InternalServerError);
         return notFoundMessage;
     }
 }
コード例 #2
0
        public static async Task<CohortDisplayObject> GetCohortDisplayObject(CohortService cs, Cohort cohort)
        {
            var students = GetStudentsByCohortId(cs, cohort.id);
            var custom = GetCohortCustomByCohortId(cs, cohort.id);

            await Task.WhenAll(students, custom);

            var displayObject = new CohortDisplayObject();
            displayObject.cohort = cohort;
            displayObject.students = from s in students.Result select s.id;
            displayObject.custom = JsonConvert.DeserializeObject<CohortCustom>(custom.Result); ;

            return displayObject;
        }
コード例 #3
0
        /// <summary>
        /// Create multiple new cohorts
        /// </summary>
        /// <param name="cohorts">new cohorts to create</param>
        /// <returns></returns>
        //public async Task<string[]> CreateCohorts(IEnumerable<Cohort> cohorts)
        //{
        //    try
        //    {
        //        var result = await Task.WhenAll(from c in cohorts select CreateCohort()); //TODO: add cohort as parameter
        //        return result;
        //    }
        //    catch (Exception ex)
        //    {
        //        throw;
        //    }
        //}

        /// <summary>
        /// Update a single cohort
        /// </summary>
        /// <returns></returns>
        public async Task<string> UpdateCohort(CohortService cs, Cohort cohort)
        {
            //var c = new CohortService(Session["access_token"].ToString());
            //var cohort = new Cohort();
            //var random = new Random();
            //cohort.id = "2012gd-cae52ab2-26f7-11e2-8acf-02786562673b";
            //cohort.educationOrgId = "2012dh-836f96e7-0b25-11e2-985e-024775596ac8";
            //cohort.cohortIdentifier = "ACC-" + DateTime.Now.Ticks.ToString().Substring(0,8);
            //cohort.cohortType = SlcClient.Enum.CohortType.ExtracurricularActivity;
            var result = await cs.Update(cohort);
            return result.ToString();
        }
コード例 #4
0
 /// <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;
     }           
 }