예제 #1
0
        public ActionResult SaveUserLocation(Location loc)
        {
            loc.Id = SessionDataHelper.UserId;

            _locationService.Update(loc);
            return Json(new {
                Result = "OK"
            });
        }
예제 #2
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");
        }