Esempio n. 1
0
        public List <Tuple <DateTime, DateTime> > GetAllTimeForCourse(long courseId)
        {
            Course course = GetObject(courseId);
            List <Tuple <DateTime, DateTime> > ret = new List <Tuple <DateTime, DateTime> >();
            List <CourseChange> changes            = courseChangeRepository.GetObjectList(c => c.CourseId == courseId, c => c.CourseTime, OrderingType.Ascending, 0, 0);
            DateTime            start   = course.SemesterStart;
            DateTime            current = course.SemesterStart;
            byte weekIndex = 1;

            while (weekIndex <= 25)
            {
                if (current.DayOfWeek == (DayOfWeek)course.Weekday && course.Weeks.Contains(weekIndex))
                {
                    DateTime courseStart = current.AddHours(course.StartTime.Hours).AddMinutes(course.StartTime.Minutes);
                    DateTime courseEnd   = current.AddHours(course.EndTime.Hours).AddMinutes(course.EndTime.Minutes);
                    ret.Add(new Tuple <DateTime, DateTime>(courseStart, courseEnd));
                }

                current.AddDays(1);
                if (current.DayOfWeek == DayOfWeek.Sunday)
                {
                    weekIndex++;
                }
            }

            foreach (CourseChange change in changes)
            {
                if ((CourseChangeType)change.ChangeType == CourseChangeType.DateModified)
                {
                    DateTime dateAfterChange = DateTime.Parse(change.ChangedValue);
                    ret.RemoveAll(x => x.Item1.Date == change.CourseTime.Date);
                    DateTime courseStart = dateAfterChange.AddHours(course.StartTime.Hours).AddMinutes(course.StartTime.Minutes);
                    DateTime courseEnd   = dateAfterChange.AddHours(course.EndTime.Hours).AddMinutes(course.EndTime.Minutes);
                    ret.Add(new Tuple <DateTime, DateTime>(courseStart, courseEnd));
                }
                else if ((CourseChangeType)change.ChangeType == CourseChangeType.TimeModified)
                {
                    DateTime startTimeAfterChange = DateTime.Parse(change.ChangedValue.Split('-')[0]);
                    DateTime endTimeAfterChange   = DateTime.Parse(change.ChangedValue.Split('-')[1]);
                    ret.RemoveAll(x => x.Item1.Date == change.CourseTime.Date);
                    DateTime courseStart = change.CourseTime.Date.AddHours(startTimeAfterChange.Hour).AddMinutes(startTimeAfterChange.Minute);
                    DateTime courseEnd   = change.CourseTime.Date.AddHours(endTimeAfterChange.Hour).AddMinutes(endTimeAfterChange.Minute);
                    ret.Add(new Tuple <DateTime, DateTime>(courseStart, courseEnd));
                }
                else if ((CourseChangeType)change.ChangeType == CourseChangeType.Cancelled)
                {
                    ret.RemoveAll(x => x.Item1.Date == change.CourseTime.Date);
                }
            }

            return(ret);
        }
Esempio n. 2
0
        public ActionResult GetCourseChanges()
        {
            try
            {
                ICourseChangeRepository repository = StructureMap.ObjectFactory.GetInstance <ICourseChangeRepository>();
                List <CourseChange>     changes    = null;
                if (Account.UserType == 2)
                {
                    changes = repository.GetObjectList(
                        m => m.Course.Classes.Where(x => x.Classes_Id == Account.ClassId).FirstOrDefault() != null,
                        x => x.CourseId, Core.Enums.OrderingType.Ascending, 0, 0);
                }
                else
                {
                    changes = repository.GetObjectList(
                        m => Account.Courses.Where(x => x.Id == m.CourseId) != null,
                        x => x.CourseId, Core.Enums.OrderingType.Ascending, 0, 0);
                }
                List <object> list = new List <object>();
                foreach (CourseChange change in changes)
                {
                    list.Add(new
                    {
                        courseId     = change.CourseId,
                        type         = ((Core.Enums.CourseChangeType)change.ChangeType).ToString(),
                        date         = change.CourseTime,
                        changedValue = change.ChangedValue,
                    });
                }

                return(Json(new { errCode = 0, changes = list }, JsonRequestBehavior.AllowGet));
            }
            catch (Exception e)
            {
                return(Json(new { errCode = -1, msg = e.Message }, JsonRequestBehavior.AllowGet));
            }
        }
Esempio n. 3
0
        public ActionResult DeleteCourse(string courseId)
        {
            try
            {
                Course c = service.GetObject(Int64.Parse(courseId));

                ICourseChangeRepository            courseChangeRepository            = ObjectFactory.GetInstance <ICourseChangeRepository>();
                ICourseClassRepository             courseClassRepository             = ObjectFactory.GetInstance <ICourseClassRepository>();
                ICourseTimeRepository              courseTimeRepository              = ObjectFactory.GetInstance <ICourseTimeRepository>();
                IAttachmentCourseRepository        attachmentCourseRepository        = ObjectFactory.GetInstance <IAttachmentCourseRepository>();
                ISelectableCourseStudentRepository selectableCourseStudentRepository = ObjectFactory.GetInstance <ISelectableCourseStudentRepository>();

                foreach (var x in attachmentCourseRepository.GetObjectList(x => x.CourseId == c.Id, x => x.CourseId, Core.Enums.OrderingType.Ascending, 0, 0))
                {
                    attachmentCourseRepository.Delete(x);
                }

                foreach (var x in courseClassRepository.GetObjectList(x => x.Courses_Id == c.Id, x => x.Courses_Id, Core.Enums.OrderingType.Ascending, 0, 0))
                {
                    courseClassRepository.Delete(x);
                }

                foreach (var x in courseChangeRepository.GetObjectList(x => x.CourseId == c.Id, x => x.CourseId, Core.Enums.OrderingType.Ascending, 0, 0))
                {
                    courseChangeRepository.Delete(x);
                }

                foreach (var x in courseTimeRepository.GetObjectList(x => x.CourseId == c.Id, x => x.CourseId, Core.Enums.OrderingType.Ascending, 0, 0))
                {
                    courseTimeRepository.Delete(x);
                }

                foreach (var x in selectableCourseStudentRepository.GetObjectList(x => x.SelectedCourses_Id == c.Id, x => x.SelectedCourses_Id, Core.Enums.OrderingType.Ascending, 0, 0))
                {
                    selectableCourseStudentRepository.Delete(x);
                }

                service.DeleteObject(c);
                return(Content("success"));
            }
            catch (Exception e)
            {
                return(Content(e.Message));
            }
        }