示例#1
0
        public ActionResult SaveClass(ClassViewModel classModel)
        {
            classModel.Duration += ((double)DateTime.Parse(classModel.EndTime).Subtract(DateTime.Parse(classModel.StartTime)).TotalMinutes / 60);

            var insertLocation = new Location {
                Address = classModel.Address,
                City = classModel.City,
                Country = classModel.Country,
                ZipCode = classModel.ZipCode,
                State = classModel.State
            };

            _locationService.Insert(insertLocation);

            var insertClass = new Class {
                Description = classModel.Description,
                StartTime = TimeSpan.Parse(classModel.StartTime),
                EndTime = TimeSpan.Parse(classModel.EndTime),
                Duration = classModel.Duration,
                TeacherId = SessionDataHelper.UserId,
                Active = false,
                SubjectID = classModel.SubjectId,
                LocationId = insertLocation.Id
            };
            _classService.Insert(insertClass);

            DateTime start = classModel.DateStart;
            DateTime end = classModel.DateEnd;
            while (start.DayOfYear <= end.DayOfYear) {
                Class_Meeting_Dates insertMeetingDate = new Class_Meeting_Dates();

                if (classModel.Monday && start.DayOfWeek == System.DayOfWeek.Monday) {
                    insertMeetingDate = new Class_Meeting_Dates {
                        ClassId = insertClass.Id,
                        Date = start
                    };
                } else if (classModel.Tuesday && start.DayOfWeek == System.DayOfWeek.Tuesday) {
                    insertMeetingDate = new Class_Meeting_Dates {
                        ClassId = insertClass.Id,
                        Date = start
                    };
                } else if (classModel.Wednesday && start.DayOfWeek == System.DayOfWeek.Wednesday) {
                    insertMeetingDate = new Class_Meeting_Dates {
                        ClassId = insertClass.Id,
                        Date = start
                    };
                } else if (classModel.Thursday && start.DayOfWeek == System.DayOfWeek.Thursday) {
                    insertMeetingDate = new Class_Meeting_Dates {
                        ClassId = insertClass.Id,
                        Date = start
                    };
                } else if (classModel.Friday && start.DayOfWeek == System.DayOfWeek.Friday) {
                    insertMeetingDate = new Class_Meeting_Dates {
                        ClassId = insertClass.Id,
                        Date = start
                    };
                }
                if (insertMeetingDate.ClassId != 0) {
                    _classMeetingDatesService.Insert(insertMeetingDate);
                }
                start = start.AddDays(1);
            }

            return RedirectToAction("DisplayClasses", "Account");
        }
示例#2
0
        public ActionResult getClassesToDisplay()
        {
            var teacherClasses = _classService.GetTableQuery().Where(c => c.TeacherId == SessionDataHelper.UserId);

            var tables = new List<ClassViewModel>();

            foreach (var c in teacherClasses) {
                var meetingDates = _classMeetingDatesService.GetTableQuery().Where(m => m.ClassId == c.Id).OrderBy(o => o.Date);
                var loc = _locationService.GetById(c.Id);
                var teacher = _teacherUserService.GetById(c.TeacherId);
                var classModel = new ClassViewModel {
                    LocationId = c.LocationId,
                    EndTime = c.EndTime.ToString(),
                    StartTime = c.StartTime.ToString(),
                    Duration = c.Duration,
                    Description = c.Description,
                    Id = c.Id,
                    SubjectId = c.SubjectID,
                    TeacherId = c.TeacherId,
                    Status = c.Active ? "Active" : "Pending",

                };
                if (meetingDates.Count() > 0) {
                    classModel.DateStart = meetingDates.First().Date;
                    classModel.DateEnd = meetingDates.OrderByDescending(x => x.Date).First().Date;
                }
                if (loc != null) {
                    classModel.Address = loc.Address;
                    classModel.City = loc.City;
                    classModel.Country = loc.Country;
                    classModel.State = loc.State;
                    classModel.ZipCode = loc.ZipCode;
                }
                if (teacher != null) {
                    classModel.TeacherName = teacher.User.FirstName + " " + teacher.User.LastName;
                }
                tables.Add(classModel);
            }

            return Json(new { Result = "OK", Records = tables });
        }
示例#3
0
        public ActionResult GetStudentClassesToDisplay()
        {
            var enrolled = _enrolledService.GetTableQuery().Where(e => e.StudentId == SessionDataHelper.UserId);

            var tables = new List<ClassViewModel>();

            foreach (var c in enrolled) {
                var enrolledClass = _classService.GetById(c.ClassId);
                if (enrolledClass != null) {
                    var meetingDates = _classMeetingDatesService.GetTableQuery().Where(m => m.ClassId == enrolledClass.Id).OrderBy(o => o.Date);

                    var loc = _locationService.GetById(enrolledClass.Id);
                    var teacher = _teacherUserService.GetById(enrolledClass.TeacherId);
                    var classModel = new ClassViewModel {
                        LocationId = enrolledClass.LocationId,
                        EndTime = enrolledClass.EndTime.ToString(),
                        StartTime = enrolledClass.StartTime.ToString(),
                        Review = enrolledClass.ReviewClass.SingleOrDefault(x => x.StudentId == SessionDataHelper.UserId),
                        AverageRating = enrolledClass.ReviewClass.FirstOrDefault() != null ? Math.Round(enrolledClass.ReviewClass.Average(a => a.Rating), 1).ToString() : "No Ratings",
                        Description = enrolledClass.Description,
                        Email = teacher.User.Email,
                        Id = enrolledClass.Id,
                        SubjectId = enrolledClass.SubjectID,
                        TeacherId = enrolledClass.TeacherId,
                    };
                    if (meetingDates.Count() > 0) {
                        classModel.DateStart = meetingDates.First().Date;
                        classModel.DateEnd = meetingDates.OrderByDescending(x => x.Date).First().Date;
                    }
                    if (loc != null) {
                        classModel.Address = loc.Address;
                        classModel.City = loc.City;
                        classModel.Country = loc.Country;
                        classModel.State = loc.State;
                        classModel.ZipCode = loc.ZipCode;
                    }
                    if (teacher != null) {
                        classModel.TeacherName = teacher.User.FirstName + " " + teacher.User.LastName;
                    }
                    tables.Add(classModel);
                }

            }

            return Json(new { Result = "OK", Records = tables });
        }
示例#4
0
        public ActionResult CreateClass()
        {
            var subjects = _subjectService.GetAll();
            var today = DateTime.Today.DayOfWeek;
            var model = new ClassViewModel {
                SubjectId = 1,
                Subjects = new SelectList(subjects, "Id", "Name")
            };

            return View(model);
        }