Esempio n. 1
0
        public HttpResponseMessage AddSubject([FromBody] TtLesson newSubject, [FromUri] string schoolYear)
        {
            try
            {
                using (var ctx = new TeachersBookEntities2())
                {
                    var identity = (ClaimsIdentity)User.Identity;
                    var id       = ((ClaimsIdentity)User.Identity).FindFirst("id");

                    var returnObj = new List <TtLesson>();

                    var userQuery =
                        from u in ctx.UserData
                        where u.id.ToString() == id.Value.ToString()
                        select u;

                    var user = userQuery.FirstOrDefault <UserData>();

                    var schoolYearsQuery =
                        from sy in user.SchoolYears
                        where sy.schoolYear.ToString() == schoolYear
                        select sy;

                    var _schoolYear = schoolYearsQuery.FirstOrDefault <SchoolYears>();

                    var currentSchoolClass =
                        from sy in ctx.Classes
                        where sy.SchoolYears.schoolYear == schoolYear && sy.id.ToString() == newSubject.TtClass.id
                        select sy;

                    var newSubjectItem = new Subjects();
                    newSubjectItem.color       = newSubject.color;
                    newSubjectItem.description = newSubject.name;
                    newSubjectItem.id          = Guid.NewGuid();
                    newSubjectItem.@class      = currentSchoolClass.FirstOrDefault <Classes>().id;
                    _schoolYear.Subjects.Add(newSubjectItem);

                    ctx.SaveChanges();

                    return(Request.CreateResponse(HttpStatusCode.OK, "success! New item id: " + newSubjectItem.id.ToString()));
                }
            }
            catch (Exception ex)
            {
                return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, "error: " + ex.Message.ToString()));
            }
        }
Esempio n. 2
0
        public IHttpActionResult GetAllSubjects(string schoolYear)
        {
            using (var ctx = new TeachersBookEntities2())
            {
                var identity = (ClaimsIdentity)User.Identity;
                var id       = ((ClaimsIdentity)User.Identity).FindFirst("id");

                var returnObj = new List <TtLesson>();

                var userQuery =
                    from u in ctx.UserData
                    where u.id.ToString() == id.Value.ToString()
                    select u;

                var user = userQuery.FirstOrDefault <UserData>();

                var schoolYearsQuery =
                    from sy in user.SchoolYears
                    where sy.schoolYear.ToString() == schoolYear
                    select sy;

                var _schoolYear = schoolYearsQuery.FirstOrDefault <SchoolYears>();
                var subjects    = _schoolYear.Subjects.ToList <Subjects>();

                foreach (var subject in subjects.OrderBy(x => x.description))
                {
                    TtLesson subjectToAdd = new TtLesson();
                    subjectToAdd.id    = subject.id.ToString();
                    subjectToAdd.name  = subject.description;
                    subjectToAdd.color = subject.color;
                    var subjectClass = new TtClass();
                    subjectClass.id      = subject.Classes.id.ToString();
                    subjectClass.name    = subject.Classes.name;
                    subjectToAdd.TtClass = subjectClass;

                    returnObj.Add(subjectToAdd);
                }

                return(Ok(returnObj));
            }
        }
Esempio n. 3
0
        public IHttpActionResult GetComplete(string schoolYear)
        {
            using (var ctx = new TeachersBookEntities2())
            {
                var identity = (ClaimsIdentity)User.Identity;
                var id       = ((ClaimsIdentity)User.Identity).FindFirst("id");

                var userQuery =
                    from u in ctx.UserData
                    where u.id.ToString() == id.Value.ToString()
                    select u;

                var user = userQuery.FirstOrDefault <UserData>();

                var schoolYearsQuery =
                    from sy in user.SchoolYears
                    where sy.schoolYear.ToString() == schoolYear
                    select sy;

                var _schoolYear = schoolYearsQuery.FirstOrDefault <SchoolYears>();

                var timetabel = _schoolYear.TimeTables.FirstOrDefault <TimeTables>();

                var returnObj = new Timetable();

                foreach (var timetablerow in timetabel.TimeTableRows.OrderBy(x => x.rowNo))
                {
                    TtSubjectsRow newRow = new TtSubjectsRow();
                    newRow.id    = timetablerow.id.ToString();
                    newRow.start = timetablerow.start;
                    newRow.end   = timetablerow.end;
                    int currentRowNo = timetablerow.rowNo ?? default(int);

                    TtSubjectsRowItem TeachersBookDescriptionItem = new TtSubjectsRowItem();
                    TeachersBookDescriptionItem.day         = 0;
                    TeachersBookDescriptionItem.hour        = currentRowNo;
                    TeachersBookDescriptionItem.description = timetablerow.start + " - " + timetablerow.end;

                    newRow.subjects.Add(TeachersBookDescriptionItem);

                    var items = timetablerow.TimeTableIItems.ToList <TimeTableIItems>();

                    foreach (TimeTableIItems item in items)
                    {
                        if (item.type == "subject")
                        {
                            newRow.rowType = "subject";
                            TtSubjectsRowItem newRowItem = new TtSubjectsRowItem();
                            newRowItem.day         = item.day ?? default(int);
                            newRowItem.hour        = currentRowNo;
                            newRowItem.description = item.description;
                            newRowItem.id          = item.id.ToString();

                            TtLesson newLesson = new TtLesson();
                            newLesson.id    = item.SubjectToTimeTableHours.Subjects.id.ToString();
                            newLesson.name  = item.SubjectToTimeTableHours.Subjects.description;
                            newLesson.color = item.SubjectToTimeTableHours.Subjects.color;

                            TtClass newClass = new TtClass();
                            newClass.id   = item.SubjectToTimeTableHours.Subjects.Classes.id.ToString();
                            newClass.name = item.SubjectToTimeTableHours.Subjects.Classes.name;

                            newLesson.TtClass = newClass;
                            newRowItem.lesson = newLesson;

                            newRow.subjects.Add(newRowItem);
                        }
                        else
                        {
                            newRow.rowType = "break";
                            TtSubjectsRowItem newRowItem = new TtSubjectsRowItem();
                            newRowItem.id          = item.id.ToString();
                            newRowItem.day         = item.day ?? default(int);
                            newRowItem.hour        = currentRowNo;
                            newRowItem.description = item.description;

                            newRow.subjects.Add(newRowItem);
                        }
                    }

                    returnObj.rows.Add(newRow);
                }

                return(Ok(returnObj));
            }
        }