// GET: HelpQueue/HelpQueue/{id?}
        public async Task <ActionResult> Queue(int?id)
        {
            var service = new CohortService(User.Identity.GetUserId());

            CohortDetail model = null;

            if (User.IsInRole("Student"))
            {
                model = await service.GetUserCohortDetailAsync(User.Identity.GetUserId());

                if (model is null)
                {
                    return(RedirectToAction(nameof(InactiveAccount)));
                }
            }
            else if (id.HasValue)
            {
                model = await service.GetCohortById(id.Value);
            }

            if (model is null)
            {
                return(RedirectToAction(nameof(Index)));
            }

            return(View(model));
        }
        /// <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>
 /// Create a StudentCohortAssociation object
 /// </summary>
 /// <param name="cs">the service to use for this action</param>
 /// <param name="associations">the StudentCohortAssociation to create</param>
 /// <returns>result of this action</returns>
 public static async Task<ActionResponseResult> CreateOneStudentCohortAssociation(CohortService cs, string cId, string sId)
 {
     var a = new StudentCohortAssociation { cohortId = cId, studentId = sId, beginDate = DateTime.Now };
     var result = await cs.CreateStudentCohortAssociation(a);
     var student = (StudentDisplayObject)HttpContext.Current.Cache[sId];
     return GlobalHelper.GetActionResponseResult(sId, student != null ? student.name : "", result, HttpStatusCode.Created);
 }
Ejemplo n.º 4
0
        public IHttpActionResult GetAllCohort()
        {
            CohortService cohortService = CreateCohortService();
            var           cohorts       = cohortService.GetCohorts();

            return(Ok(cohorts));
        }
Ejemplo n.º 5
0
        public IHttpActionResult GetCohort(int id)
        {
            CohortService cohortService = CreateCohortService();
            var           cohorts       = cohortService.GetCohortById(id);

            return(Ok(cohorts));
        }
Ejemplo n.º 6
0
        private CohortService CreateCohortService()
        {
            var userId        = Guid.Parse(User.Identity.GetUserId());
            var cohortService = new CohortService(userId);

            return(cohortService);
        }
        public async Task <ActionResult> Register()
        {
            var service = new CohortService();

            ViewBag.CohortId = new SelectList(await service.GetCohortListAsync(), "Id", "Name");
            return(View());
        }
        internal string CURRENT_ED_ORG_ID = ConfigurationManager.AppSettings["CurrentEdgOrgId"]; //there's no data from inBloom about the current user Ed Org, temporarily using a constant value for each environment

        /// <summary>
        /// Create new student cohort associations
        /// </summary>
        /// <param name="obj">cohort to create</param>
        /// <param name="cs">cohort service</param>
        /// <returns>result of this action</returns>
        public static Task<IEnumerable<ActionResponseResult>> GetNewStudentCohortAssociations(CohortActionObject obj, CohortService cs)
        {
            Task<IEnumerable<ActionResponseResult>> newStudentsAssociations;
            if (obj.studentsToCreate != null && obj.studentsToCreate.Count() > 0)
                newStudentsAssociations = CohortActionHelper.CreateMultipleStudentCohortAssociations(cs, obj.cohort.id, obj.studentsToCreate);
            else
                newStudentsAssociations = null;
            return newStudentsAssociations;
        }
 private static async Task<string> GetCohortCustomByCohortId(CohortService cs, string cohortId)
 {
     try
     {
         var result = await cs.GetCustomById(cohortId);
         return result;
     }
     catch (Exception ex)
     {
         //when there isn't a custom yet, SLC throw a 404
         return "";
     }
     
 }
        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;
        }
Ejemplo n.º 11
0
        public async Task <ActionResult> Register(RegisterViewModel model)
        {
            if (ModelState.IsValid)
            {
                var user = new ApplicationUser
                {
                    UserName  = model.Email,
                    Email     = model.Email,
                    FirstName = model.FirstName,
                    LastName  = model.LastName
                };
                var result = await UserManager.CreateAsync(user, model.Password);

                if (result.Succeeded)
                {
                    UserManager.AddToRole(user.Id, "Student");

                    using (var ctx = new ApplicationDbContext())
                    {
                        ctx.Enrollments.Add(new EnrollmentEntity
                        {
                            StudentId = user.Id,
                            CohortId  = model.CohortId,
                            IsActive  = false
                        });
                        ctx.SaveChanges();
                    }

                    await SignInManager.SignInAsync(user, isPersistent : false, rememberBrowser : false);

                    // For more information on how to enable account confirmation and password reset please visit https://go.microsoft.com/fwlink/?LinkID=320771
                    // Send an email with this link
                    // string code = await UserManager.GenerateEmailConfirmationTokenAsync(user.Id);
                    // var callbackUrl = Url.Action("ConfirmEmail", "Account", new { userId = user.Id, code = code }, protocol: Request.Url.Scheme);
                    // await UserManager.SendEmailAsync(user.Id, "Confirm your account", "Please confirm your account by clicking <a href=\"" + callbackUrl + "\">here</a>");

                    return(RedirectToAction("Index", "Home"));
                }
                AddErrors(result);
            }

            var service = new CohortService();

            ViewBag.CohortId = new SelectList(await service.GetCohortListAsync(), "Id", "Name");

            // If we got this far, something failed, redisplay form
            return(View(model));
        }
        /// <summary>
        /// AJAX to this method to create brand new groups with students
        /// </summary>
        /// <param name="obj"></param>
        /// <returns></returns>
        public async Task<string> CreateGroup(CohortActionObject obj)
        {
            try
            {
                var cs = new CohortService(Session["access_token"].ToString());
                var cohortId = await CreateCohort(cs, obj.cohort); //1) create the cohort first and retrieve the Id of the new cohort
                var studentsAssociations = CreateMultipleAssociation(cs, cohortId, obj.studentsToCreate); //2) start creating student cohort association
                var cohortCustom = cs.CreateCohortCustom(cohortId, JsonConvert.SerializeObject(obj.custom)); //3) initial populate of the cohort custom entity

                await Task.WhenAll(studentsAssociations, cohortCustom);

                return cohortId;
            }
            catch (Exception e)
            {
                //handle
                throw;
            }            
        }
        /// <summary>
        /// Get all information about a cohort
        /// </summary>
        /// <param name="cs"></param>
        /// <param name="cohort"></param>
        /// <returns></returns>
        public static async Task<CohortDisplayObject> GetCohortDisplayObject(CohortService cs, Cohort cohort)
        {
            //check to see if the item is already in cache. if so, return the cache item
            var cache = (CohortDisplayObject)HttpContext.Current.Cache[cohort.id];
            if (cache != null)
                return cache;

            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); ;

            HttpContext.Current.Cache.Insert(cohort.id, displayObject);
            return displayObject;
        }
 public void DeleteCohort(string id)
 {
     try
     {
         var c = new CohortService(Session["access_token"].ToString());
         var result = c.DeleteById(id);
         //return result;
         Response.Redirect(MAIN);
     }
     catch
     {
         throw;
     }            
     //throw new Exception("break here");
 }
        public async Task<IEnumerable<Cohort>> GetCohorts(){
            var c = new CohortService(Session["access_token"].ToString());
            var cohorts = await c.GetAll();

            return cohorts;
        }
        public async Task<string> DeleteOneAssociation(CohortService cs, string associationId)
        {
            var result = await cs.DeleteStudentCohortAssociationById(associationId);

            return result.ToString();
        }
        /// <summary>
        /// Update the Result object after custom has been updated through inBloom
        /// </summary>
        /// <param name="cohortResult">Result object to update</param>
        /// <param name="cohortCustom">the inBloom response message</param>
        /// <param name="successStatus">HttpStatusCode that indicates a successful response</param>
        public static void ProcessCustomResult(Result cohortResult, Task<HttpResponseMessage> m, HttpStatusCode successStatus, 
                                                CohortCustom cohortCustom = null, CohortService cs = null)
        {
            //If not found meaning cohort doesn't have a custom entity created yet
            if (m.Result.StatusCode == HttpStatusCode.NotFound)
            {
                var result = CreateCustom(cohortCustom, cs);
                ProcessCustomResult(cohortResult, result, HttpStatusCode.Created);
            }
            else
            {
                //Found the custom entity, process response from the custom entity update
                var customResult = GlobalHelper.GetActionResponseResult(cohortResult.objectActionResult.objectId,
                                                cohortResult.objectActionResult.objectName, m.Result, successStatus);
                if (m.Result.StatusCode != successStatus)
                    cohortResult.completedSuccessfully = false;

                cohortResult.customActionResult = customResult;
            }           
        }
 private static async Task<IEnumerable<Student>> GetStudentsByCohortId(CohortService cs, string cohortId)
 {
     var result = await cs.GetStudentsByCohortId(cohortId);
     return result;
 }
 public static Task<HttpResponseMessage> CreateCustom(CohortCustom custom, CohortService cs)
 {
     if (custom == null) custom = new CohortCustom { lastModifiedDate = DateTime.UtcNow };
     else custom.lastModifiedDate = DateTime.UtcNow;
     var cohortCustom = cs.CreateCohortCustom(custom.cohortId, JsonConvert.SerializeObject(custom));
     return cohortCustom;
 }
        public async Task<ActionResult> Group()
        {
            var accessToken = Session["access_token"];
            if (accessToken != null)
            {
                var cs = new CohortService(accessToken.ToString());
                var ss = new StudentService(accessToken.ToString());
                var ses = new SectionService(accessToken.ToString());

                var co = GetCohorts();
                var st = GetStudents();
                var se = GetSections();

                //Get the available data elements and colors
                var dataElements = GlobalHelper.InitializeDataElements();
                var colors = GlobalHelper.InitializeColors();

                await Task.WhenAll(co, st, se);

                var cohorts = Task.WhenAll(from c in co.Result select CohortHelper.GetCohortDisplayObject(cs, c));
                var students = Task.WhenAll(from s in st.Result select StudentHelper.GetStudentDisplayObject(ss, s));
                var sections = Task.WhenAll(from s in se.Result select SectionHelper.GetSectionDisplayObject(ses, s));

                await Task.WhenAll(cohorts, students, se);

                var filters = FilterHelper.InitializeFilters(sections.Result); //contruct filter values to filter students in the app
                await Task.WhenAll(dataElements, colors);

                var data = GetGroupingDisplayObject(dataElements, colors, filters, cohorts, students, sections);

                return Json(data, JsonRequestBehavior.AllowGet);
            }

            //session has expired, refresh page
            return View("Index");
        }
        /// <summary>
        /// Create a StaffCohortAssociation object
        /// </summary>
        /// <param name="cs">the service to use for this action</param>
        /// <param name="associations">the StaffCohortAssociation to create</param>
        /// <returns>result of this action</returns>
        public static async Task<ActionResponseResult> CreateOneStaffCohortAssociation(CohortService cs, string cId, string sId)
        {
            var a = new StaffCohortAssociation { cohortId = cId, staffId = sId, beginDate = DateTime.Now };
            var result = await cs.CreateStaffCohortAssociation(a);

            return GlobalHelper.GetActionResponseResult(sId, "", result, HttpStatusCode.Created);            
        }
 /// <summary>
 /// Create multiple StudentCohortAssociation object
 /// </summary>
 /// <param name="cs">the service to use for this action</param>
 /// <param name="associations">the StudentCohortAssociations to create</param>
 /// <returns>list of results</returns>
 public static async Task<IEnumerable<ActionResponseResult>> CreateMultipleStudentCohortAssociations(CohortService cs, string cId, IEnumerable<string> sl)
 {
     var result = await Task.WhenAll(from s in sl select CreateOneStudentCohortAssociation(cs, cId, s));
     return result;
 }
 /// <summary>
 /// Delete multiple StudentCohortAssociation objects
 /// </summary>
 /// <param name="cs">the service to use for this action</param>
 /// <param name="associations">the StudentCohortAssociations to delete</param>
 /// <returns>result of this action</returns>
 public static async Task<IEnumerable<ActionResponseResult>> DeleteMultipleStudentCohortAssociations(CohortService cs, IEnumerable<StudentCohortAssociation> associations)
 {
     var result = await Task.WhenAll(from a in associations select DeleteOneStudentCohortAssociation(cs, a));
     return result;
 }
 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;
 }
 /// <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;
     }           
 }
        private static async Task ProcessASuccessfulCohortCreate(CohortActionObject obj, CohortService cs, Result cohortResult, string staffId)
        {
            obj.cohort.id = cohortResult.objectActionResult.objectId;
            obj.custom.cohortId = obj.cohort.id;
            //1) start creating staff/student cohort association
            var newStudentsAssociations = CohortActionHelper.GetNewStudentCohortAssociations(obj, cs);
            var newStaffAssociation = CohortActionHelper.CreateOneStaffCohortAssociation(cs, obj.cohort.id, staffId);
            //2) initial populate of the cohort custom entity        
            var cohortCustom = CohortActionHelper.CreateCustom(obj.custom, cs);

            //contruct a list of tasks we're waiting for
            var tasksToWaitFor = new List<Task>();
            if (newStudentsAssociations != null) tasksToWaitFor.Add(newStudentsAssociations);
            if (cohortCustom != null) tasksToWaitFor.Add(cohortCustom);
            if (newStaffAssociation != null) tasksToWaitFor.Add(newStaffAssociation);

            await Task.WhenAll(tasksToWaitFor);

            if (newStudentsAssociations != null)
                CohortActionHelper.DetermineFailedToCreateFor(cohortResult, newStudentsAssociations.Result);

            //determine whether custom was created successfully
            CohortActionHelper.ProcessCustomResult(cohortResult, cohortCustom, HttpStatusCode.Created);
        }
        /// <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();
        }
 /// <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;
 }
        /// <summary>
        /// Delete one cohort
        /// </summary>
        /// <param name="obj">data object to deletes cohort</param>
        /// <returns>result of the action</returns>
        public async Task<Result> ProcessOneCohortDelete(string id)
        {
            try
            {
                var accessToken = Session["access_token"];
                if (accessToken != null)
                {
                    var cs = new CohortService(Session["access_token"].ToString());                                 

                    var cohortResult = await DeleteCohort(cs, id);
                    //remove cohort from cache after an update
                    HttpContext.Cache.Remove(id);

                    // delete the group's directory from the FTP server
                    FTPHelper.removeDir(id);

                    return cohortResult;
                }
                else
                {
                    //session has expired
                    return GlobalHelper.GetSessionExpiredResult(id);
                }
            }
            catch (Exception e)
            {
                return GlobalHelper.GetExceptionResult(id, e);
            }
        }
        //public async Task<string[]> CreateCustom(CohortCustom obj)
        //{
        //    var cs = new CohortService(Session["access_token"].ToString());
        //    var result = await cs.CreateCohortCustom
        //}

        public async Task<ActionResult> Sample()
        {

                //var displayObj = new List<CohortDisplayObject>();
                var cs = new CohortService(Session["access_token"].ToString());
                //var c = new StudentsController();
                //var students = await c.Get(Session["access_token"].ToString());
                var co = await GetCohorts();
                //var st = GetStudents();

                var displayObj = await Task.WhenAll(from c in co select CohortHelper.GetCohortDisplayObject(cs, c));
                //await Task.WhenAll(co, st);
                //var data = new Data { students = st, cohorts = co };
                //var cs = new CohortService(Session["access_token"].ToString());

                //var result = await Task.WhenAll(from c in co.Result select createMultipleAssociation(cs, c, st.Result));
                var filters = Helper.FilterHelper.InitializeFilters();
                return View(displayObj);            
        }
        /// <summary>
        /// Create one cohort
        /// </summary>
        /// <param name="obj">data object to create cohort</param>
        /// <returns>result of the action</returns>
        public async Task<Result> ProcessOneCohortCreate(CohortActionObject obj)
        {
            try
            {
                var accessToken = Session["access_token"];
                if (accessToken != null)
                {
                    var cs = new CohortService(accessToken.ToString());
                    //create the cohort first
                    var cohortResult = await CreateCohort(cs, obj.cohort);

                    //if cohort was created successfully then continue to create associations
                    if (cohortResult.completedSuccessfully)
                    {
                        var staffId = Session[INBLOOM_USER_ID].ToString();
                        await ProcessASuccessfulCohortCreate(obj, cs, cohortResult, staffId);
                    }

                    return cohortResult;
                }
                else
                {
                    //section expired
                    return GlobalHelper.GetSessionExpiredResult(obj.cohort.cohortIdentifier);
                }

            }
            catch (Exception e)
            {
                return GlobalHelper.GetExceptionResult(obj.cohort.cohortIdentifier, e);
            }
        }
 public async Task<string[]> CreateMultipleAssociation(CohortService cs, string cId, IEnumerable<Student> sl)
 {
     var result = await Task.WhenAll(from s in sl select CreateOneAssociation(cs, cId, s));
     return result;
 }
        public async Task<string> CreateOneAssociation(CohortService cs, string cId, Student s)
        {
            var a = new StudentCohortAssociation { cohortId = cId, studentId = s.id, beginDate = DateTime.Now };
            var result = await cs.CreateStudentCohortAssociation(a);

            return result.ToString();
        }
 public async Task<string[]> DeleteMultipleAssociation(CohortService cs, IEnumerable<string> associations)
 {
     var result = await Task.WhenAll(from a in associations select DeleteOneAssociation(cs, a));
     return result;
 }
        public async Task<ActionResult> Group()
        {
            var cs = new CohortService(Session["access_token"].ToString());
            var ss = new StudentService(Session["access_token"].ToString());

            var co = GetCohorts();
            var st = GetStudents();

            await Task.WhenAll(co, st);

            var cohorts = Task.WhenAll(from c in co.Result select CohortHelper.GetCohortDisplayObject(cs, c));
            var students = Task.WhenAll(from s in st.Result select StudentHelper.GetStudentDisplayObject(ss, s));

            await Task.WhenAll(cohorts, students);

            var data = new GroupingDisplayObject();
            data.cohorts = cohorts.Result;
            data.students = students.Result;
            data.filters = FilterHelper.InitializeFilters();

            return View(data);
        }
 /// <summary>
 /// Delete a StudentCohortAssociation object
 /// </summary>
 /// <param name="cs">service to use for this action</param>
 /// <param name="association">the StudentCohortAssociation to delete</param>
 /// <returns>result of this action</returns>
 public static async Task<ActionResponseResult> DeleteOneStudentCohortAssociation(CohortService cs, StudentCohortAssociation association)
 {
     var response = await cs.DeleteStudentCohortAssociationById(association.id);
     var student = (StudentDisplayObject)HttpContext.Current.Cache[association.studentId];
     return GlobalHelper.GetActionResponseResult(association.studentId, student != null ? student.name : "", response, HttpStatusCode.NoContent);
 }