Exemple #1
0
        public IActionResult PutLineItem([FromRoute] string id)
        {
            var insert   = false;
            var lineItem = db.LineItems.SingleOrDefault(li => li.Id == id);

            if (lineItem == null)
            {
                lineItem = new LineItem()
                {
                    Id = id
                };
                insert = true;
            }

            using (var reader = new StreamReader(Request.Body))
            {
                var requestJson = (JObject)JObject.Parse(reader.ReadToEnd())["lineItem"];

                if (!lineItem.UpdateWithJson(requestJson))
                {
                    return(new StatusCodeResult(422));
                }
            }

            if (TryValidateModel(lineItem))
            {
                if (insert)
                {
                    db.LineItems.Add(lineItem);
                }
                db.SaveChanges();

                db.LineItems
                .Include(li => li.AcademicSession)
                .Include(li => li.IMSClass)
                .Include(li => li.LineItemCategory)
                .Where(li => li.Id == id)
                .First();

                serializer = new OneRosterSerializer("lineItem");
                lineItem.AsJson(serializer.Writer, BaseUrl());
                if (insert)
                {
                    return(JsonWithStatus(serializer.Finish(), null, 201));
                }

                return(JsonOk(serializer.Finish()));
            }
            else
            {
                return(new StatusCodeResult(422));
            }
        }
Exemple #2
0
        public IActionResult PutResult([FromRoute] string id)
        {
            var insert = false;
            var result = db.Results.SingleOrDefault(r => r.Id == id);

            if (result == null)
            {
                result = new Result()
                {
                    Id = id
                };
                insert = true;
            }

            using (var reader = new StreamReader(Request.Body))
            {
                var requestJson = (JObject)JObject.Parse(reader.ReadToEnd())["result"];

                if (!result.UpdateWithJson(requestJson))
                {
                    return(new StatusCodeResult(422));
                }
            }

            if (TryValidateModel(result))
            {
                if (insert)
                {
                    db.Results.Add(result);
                }
                db.SaveChanges();

                db.Results
                .Include(r => r.LineItem)
                .Include(r => r.Student)
                .Where(r => r.Id == id)
                .First();

                serializer = new OneRosterSerializer("result");
                result.AsJson(serializer.Writer, BaseUrl());

                if (insert)
                {
                    return(JsonWithStatus(serializer.Finish(), null, 201));
                }
                return(JsonOk(serializer.Finish()));
            }
            else
            {
                return(new StatusCodeResult(422));
            }
        }
Exemple #3
0
        public IActionResult GetTeachersForClassInSchool([FromRoute] string schoolId, string classId)
        {
            var imsClass = db.IMSClasses
                           .Where(c => c.SchoolOrgId == schoolId)
                           .Include(c => c.Enrollments)
                           .ThenInclude(e => e.User)
                           .ThenInclude(u => u.UserOrgs)
                           .ThenInclude(uo => uo.Org)
                           .Include(c => c.Enrollments)
                           .ThenInclude(e => e.User)
                           .ThenInclude(u => u.UserAgents)
                           .ThenInclude(ua => ua.Agent)
                           .SingleOrDefault(c => c.Id == classId);

            if (imsClass == null)
            {
                return(NotFound());
            }

            serializer = new OneRosterSerializer("teachers");
            serializer.writer.WriteStartArray();
            foreach (var enrollment in imsClass.Enrollments)
            {
                var user = enrollment.User;
                if (user.Role == Vocabulary.RoleType.teacher)
                {
                    user.AsJson(serializer.writer, BaseUrl());
                }
            }
            serializer.writer.WriteEndArray();
            return(JsonOk(serializer.Finish()));
        }
Exemple #4
0
        public IActionResult GetEnrollmentsForClassInSchool([FromRoute] string schoolId, string classId)
        {
            var imsClass = db.IMSClasses
                           .Where(c => c.SchoolOrgId == schoolId)
                           .Include(c => c.Enrollments)
                           .ThenInclude(e => e.User)
                           .Include(c => c.Enrollments)
                           .ThenInclude(e => e.IMSClass)
                           .Include(c => c.Enrollments)
                           .ThenInclude(e => e.School)
                           .SingleOrDefault(c => c.Id == classId);

            if (imsClass == null)
            {
                return(NotFound());
            }

            serializer = new OneRosterSerializer("enrollments");
            serializer.writer.WriteStartArray();
            foreach (var enrollment in imsClass.Enrollments)
            {
                enrollment.AsJson(serializer.writer, BaseUrl());
            }
            serializer.writer.WriteEndArray();
            return(JsonOk(serializer.Finish()));
        }
Exemple #5
0
        public IActionResult GetTeachersForSchool([FromRoute] string id)
        {
            var teachers = db.Users
                           .Where(u => u.Role == Vocabulary.RoleType.teacher)
                           .Include(u => u.UserOrgs).ThenInclude(uo => uo.Org)
                           .Include(u => u.UserAgents).ThenInclude(ua => ua.Agent);

            if (!teachers.Any())
            {
                return(NotFound());
            }

            serializer = new OneRosterSerializer("teachers");
            serializer.writer.WriteStartArray();
            foreach (var teacher in teachers)
            {
                foreach (var org in teacher.UserOrgs)
                {
                    if (org.OrgId == id)
                    {
                        teacher.AsJson(serializer.writer, BaseUrl());
                    }
                }
            }
            serializer.writer.WriteEndArray();
            return(JsonOk(serializer.Finish()));
        }
        public IActionResult GetEnrollmentsForSchool([FromRoute] string id)
        {
            IQueryable <Enrollment> enrollments = db.Enrollments
                                                  .Include(e => e.User)
                                                  .Include(e => e.IMSClass)
                                                  .Include(e => e.School)
                                                  .Where(e => e.IMSClass.SchoolOrgId == id);

            enrollments = ApplyBinding(enrollments);

            if (!enrollments.Any())
            {
                return(NotFound());
            }

            serializer = new OneRosterSerializer("enrollments");
            serializer.Writer.WriteStartArray();
            foreach (var enrollment in enrollments)
            {
                enrollment.AsJson(serializer.Writer, BaseUrl());
            }
            serializer.Writer.WriteEndArray();

            return(JsonOk(serializer.Finish(), ResponseCount));
        }
        public IActionResult GetStudentsForSchool([FromRoute] string id)
        {
            IQueryable <User> students = db.Users
                                         .Where(u => u.Role == Vocabulary.RoleType.student)
                                         .Include(u => u.UserOrgs).ThenInclude(uo => uo.Org)
                                         .Include(u => u.UserAgents).ThenInclude(ua => ua.Agent);

            students = ApplyBinding(students);

            if (!students.Any())
            {
                return(NotFound());
            }

            serializer = new OneRosterSerializer("students");
            serializer.Writer.WriteStartArray();
            foreach (var student in students)
            {
                foreach (var org in student.UserOrgs)
                {
                    if (org.OrgId == id)
                    {
                        student.AsJson(serializer.Writer, BaseUrl());
                    }
                }
            }
            serializer.Writer.WriteEndArray();
            return(JsonOk(serializer.Finish(), ResponseCount));
        }
        public IActionResult GetClassesForSchool([FromRoute] string id)
        {
            var imsClasses = db.IMSClasses
                             .Include(k => k.IMSClassAcademicSessions)
                             .ThenInclude(kas => kas.AcademicSession)
                             .Include(k => k.Course)
                             .Include(k => k.School)
                             .Where(k => k.SchoolOrgId == id);

            imsClasses = ApplyBinding(imsClasses);

            if (!imsClasses.Any())
            {
                return(NotFound());
            }

            serializer = new OneRosterSerializer("classes");
            serializer.Writer.WriteStartArray();
            foreach (var imsClass in imsClasses)
            {
                imsClass.AsJson(serializer.Writer, BaseUrl());
            }
            serializer.Writer.WriteEndArray();
            return(JsonOk(serializer.Finish(), ResponseCount));
        }
        public IActionResult GetClassesForStudent([FromRoute] string id)
        {
            var student = db.Users
                          .Include(u => u.UserOrgs).ThenInclude(uo => uo.Org)
                          .Include(u => u.UserAgents).ThenInclude(ua => ua.Agent)
                          .Include(u => u.Enrollments).ThenInclude(e => e.IMSClass)
                          .ThenInclude(k => k.IMSClassAcademicSessions)
                          .ThenInclude(kas => kas.AcademicSession)
                          .Include(u => u.Enrollments).ThenInclude(e => e.IMSClass)
                          .ThenInclude(k => k.Course)
                          .Include(u => u.Enrollments).ThenInclude(e => e.IMSClass)
                          .ThenInclude(k => k.School)
                          .SingleOrDefault(u => u.Id == id && u.Role == Vocabulary.RoleType.student);

            if (student == null || !student.Enrollments.Any())
            {
                return(NotFound());
            }

            serializer = new OneRosterSerializer("classes");
            serializer.Writer.WriteStartArray();
            foreach (var enrollment in student.Enrollments)
            {
                enrollment.IMSClass.AsJson(serializer.Writer, BaseUrl());
            }
            serializer.Writer.WriteEndArray();
            return(JsonOk(serializer.Finish()));
        }
Exemple #10
0
 internal string FinishSerialization()
 {
     if (exceptions.Count > 0)
     {
         SerializeExceptions();
     }
     return(serializer.Finish());
 }
Exemple #11
0
        public IActionResult ErrorResult()
        {
            serializer = new OneRosterSerializer("statusInfoSet");
            SerializeExceptions();

            return(new OneRosterResult
            {
                Content = serializer.Finish(),
                ContentType = "application/json",
                StatusCode = 400
            });
        }
        public IActionResult GetTerm([FromRoute] string id)
        {
            var term = db.AcademicSessions.SingleOrDefault(a => a.Id == id && a.Type == Vocabulary.SessionType.term);

            if (term == null)
            {
                return(NotFound());
            }

            serializer = new OneRosterSerializer("term");
            term.AsJson(serializer.Writer, BaseUrl());
            return(JsonOk(serializer.Finish()));
        }
Exemple #13
0
        public IActionResult GetSchool([FromRoute] string id)
        {
            var org = LookupSchool(id);

            if (org == null)
            {
                return(NotFound());
            }

            serializer = new OneRosterSerializer("org");
            org.AsJson(serializer.writer, BaseUrl());
            return(JsonOk(serializer.Finish()));
        }
        public IActionResult GetResource([FromRoute] string id)
        {
            var resource = db.Resources.SingleOrDefault(a => a.Id == id);

            if (resource == null)
            {
                return(NotFound());
            }

            serializer = new OneRosterSerializer("resource");
            resource.AsJson(serializer.Writer, BaseUrl());
            return(JsonOk(serializer.Finish()));
        }
        public IActionResult GetAcademicSession([FromRoute] string id)
        {
            var academicSession = db.AcademicSessions.SingleOrDefault(a => a.Id == id);

            if (academicSession == null)
            {
                return(NotFound());
            }

            serializer = new OneRosterSerializer("academicSession");
            academicSession.AsJson(serializer.writer, BaseUrl());
            return(JsonOk(serializer.Finish()));
        }
        public IActionResult GetGradingPeriod(string id)
        {
            var session = db.AcademicSessions.FirstOrDefault(a => a.Id == id && a.Type == Vocabulary.SessionType.gradingPeriod);

            if (session == null)
            {
                return(NotFound());
            }

            serializer = new OneRosterSerializer("academicSession");
            session.AsJson(serializer.Writer, BaseUrl());
            return(JsonOk(serializer.Finish()));
        }
        public IActionResult GetAcademicSession([FromRoute] string id)
        {
            using (var client = _client)
            {
                var response = client.GetAsync(BuildSingleRecordUrl <AcademicSession>(id));
                var decoded  = response.Result.Content.ReadAsStringAsync().Result;
                var result   = JsonConvert.DeserializeObject <CrmAcademicSession>(decoded);

                var session = new AcademicSession(result);

                serializer = new OneRosterSerializer("user");
                session.AsJson(serializer.writer, BaseUrl());
                return(JsonOk(serializer.Finish()));
            }
        }
        public IActionResult GetCourse([FromRoute] string id)
        {
            var course = db.Courses
                         .Include(c => c.SchoolYearAcademicSession)
                         .Include(c => c.Org)
                         .FirstOrDefault(c => c.Id == id);

            if (course == null)
            {
                return(NotFound());
            }
            serializer = new OneRosterSerializer("course");
            course.AsJson(serializer.writer, BaseUrl());
            return(JsonOk(serializer.Finish()));
        }
Exemple #19
0
        public IActionResult GetEnrollment([FromRoute] string id)
        {
            var enrollment = db.Enrollments
                             .Include(e => e.User)
                             .Include(e => e.IMSClass)
                             .Include(e => e.School)
                             .SingleOrDefault(a => a.Id == id);

            if (enrollment == null)
            {
                return(NotFound());
            }
            serializer = new OneRosterSerializer("enrollment");
            enrollment.AsJson(serializer.Writer, BaseUrl());
            return(JsonOk(serializer.Finish()));
        }
Exemple #20
0
        public IActionResult GetResult([FromRoute] string id)
        {
            var result = db.Results
                         .Include(r => r.LineItem)
                         .Include(r => r.Student)
                         .SingleOrDefault(li => li.Id == id);

            if (result == null)
            {
                return(NotFound());
            }

            serializer = new OneRosterSerializer("result");
            result.AsJson(serializer.Writer, BaseUrl());
            return(JsonOk(serializer.Finish()));
        }
        public IActionResult GetOrg([FromRoute] string id)
        {
            var org = db.Orgs
                      .Include(o => o.Parent)
                      .Include(o => o.Children)
                      .SingleOrDefault(a => a.Id == id);

            if (org == null)
            {
                return(NotFound());
            }

            serializer = new OneRosterSerializer("org");
            org.AsJson(serializer.writer, BaseUrl());
            return(JsonOk(serializer.Finish()));
        }
        public IActionResult GetClass([FromRoute] string id)
        {
            var imsClasses = db.IMSClasses
                             .Include(k => k.IMSClassAcademicSessions)
                             .ThenInclude(kas => kas.AcademicSession)
                             .Include(k => k.Course)
                             .Include(k => k.School)
                             .SingleOrDefault(k => k.Id == id);

            if (imsClasses == null)
            {
                return(NotFound());
            }
            serializer = new OneRosterSerializer("class");
            imsClasses.AsJson(serializer.Writer, BaseUrl());
            return(JsonOk(serializer.Finish()));
        }
        public IActionResult GetStudent([FromRoute] string id)
        {
            var student = db.Users
                          .Include(u => u.UserOrgs).ThenInclude(uo => uo.Org)
                          .Include(u => u.UserAgents).ThenInclude(ua => ua.Agent)
                          .SingleOrDefault(u => u.Id == id && u.Role == Vocabulary.RoleType.student);

            if (student == null)
            {
                return(NotFound());
            }

            serializer = new OneRosterSerializer("user");
            student.AsJson(serializer.Writer, BaseUrl());

            return(JsonOk(serializer.Finish()));
        }
Exemple #24
0
        public IActionResult GetUser([FromRoute] string id)
        {
            using (var client = _client)
            {
                var response = client.GetAsync(BuildSingleRecordUrl <User>(id));
                var decoded  = response.Result.Content.ReadAsStringAsync().Result;
                var result   = JsonConvert.DeserializeObject <CrmUser>(decoded);

                if (result == null)
                {
                    return(NotFound());
                }

                var user = new User(result);

                serializer = new OneRosterSerializer("user");
                user.AsJson(serializer.writer, BaseUrl());
                return(JsonOk(serializer.Finish()));
            }
        }
        public IActionResult GetSchool([FromRoute] string id)
        {
            using (var client = _client)
            {
                var response = client.GetAsync(BuildSingleRecordUrl <Org>(id));
                var decoded  = response.Result.Content.ReadAsStringAsync().Result;
                var result   = JsonConvert.DeserializeObject <CrmOrg>(decoded);

                if (result == null || result.msk12_accounttype != OrgType.school)
                {
                    return(NotFound());
                }

                var school = new Org(result);

                serializer = new OneRosterSerializer("org");
                school.AsJson(serializer.writer, BaseUrl());
                return(JsonOk(serializer.Finish()));
            }
        }
Exemple #26
0
        public IActionResult GetCoursesForSchool([FromRoute] string id)
        {
            var courses = db.Courses
                          .Include(c => c.SchoolYearAcademicSession)
                          .Include(c => c.Org)
                          .Where(c => c.OrgId == id);

            if (!courses.Any())
            {
                return(NotFound());
            }
            serializer = new OneRosterSerializer("courses");
            serializer.writer.WriteStartArray();
            foreach (var course in courses)
            {
                course.AsJson(serializer.writer, BaseUrl());
            }
            serializer.writer.WriteEndArray();

            return(JsonOk(serializer.Finish()));
        }
        public IActionResult GetResourcesForCourse([FromRoute] string courseId)
        {
            var course = db.Courses
                         .FirstOrDefault(c => c.Id == courseId);

            if (course == null || course.Resources == null)
            {
                return(NotFound());
            }

            serializer = new OneRosterSerializer("resources");
            serializer.writer.WriteStartArray();
            foreach (string resourceId in course.Resources)
            {
                var resource = db.Resources
                               .FirstOrDefault(r => r.Id == resourceId);

                resource.AsJson(serializer.writer, BaseUrl());
            }
            serializer.writer.WriteEndArray();
            return(JsonOk(serializer.Finish()));
        }
        public IActionResult GetGradingPeriodsForTerm([FromRoute] string id)
        {
            var term = db.AcademicSessions
                       .Include(s => s.Children)
                       .SingleOrDefault(a => a.Id == id && a.Type == Vocabulary.SessionType.term);

            if (term == null)
            {
                return(NotFound());
            }

            serializer = new OneRosterSerializer("gradingPeriods");
            serializer.Writer.WriteStartArray();
            foreach (var child in term.Children)
            {
                if (child.Type == Vocabulary.SessionType.gradingPeriod)
                {
                    child.AsJson(serializer.Writer, BaseUrl());
                }
            }
            serializer.Writer.WriteEndArray();
            return(JsonOk(serializer.Finish()));
        }
        public IActionResult GetClassesForCourse([FromRoute] string id)
        {
            var imsClasses = db.IMSClasses
                             .Include(c => c.IMSClassAcademicSessions)
                             .ThenInclude(cas => cas.AcademicSession)
                             .Include(c => c.Course)
                             .Include(c => c.School)
                             .Where(c => c.CourseId == id);

            if (!imsClasses.Any())
            {
                return(NotFound());
            }

            serializer = new OneRosterSerializer("resources");
            serializer.writer.WriteStartArray();
            foreach (var imsClass in imsClasses)
            {
                imsClass.AsJson(serializer.writer, BaseUrl());
            }
            serializer.writer.WriteEndArray();
            return(JsonOk(serializer.Finish()));
        }
        public IActionResult GetTermsForSchool([FromRoute] string id)
        {
            IQueryable <Course> courses = db.Courses
                                          .Include(c => c.SchoolYearAcademicSession)
                                          .Where(c => c.OrgId == id);

            courses = ApplyBinding(courses);

            if (!courses.Any())
            {
                return(NotFound());
            }

            var terms = courses.Select(c => c.SchoolYearAcademicSession);

            serializer = new OneRosterSerializer("terms");
            serializer.Writer.WriteStartArray();
            foreach (var term in terms)
            {
                term.AsJson(serializer.Writer, BaseUrl());
            }
            serializer.Writer.WriteEndArray();
            return(JsonOk(serializer.Finish(), ResponseCount));
        }