Exemplo n.º 1
0
        public List <StructredCourseScheduleViewModel> GetCourseScheduleByDeptCode(string deptcode)
        {
            Command.CommandText = "SELECT * FROM dbo.vw_CourseSchedual WHERE DeptCode = '" + deptcode + "'";
            Connection.Open();
            SqlDataReader reader = Command.ExecuteReader();
            List <StructredCourseScheduleViewModel> result = new List <StructredCourseScheduleViewModel>();

            while (reader.Read())
            {
                CourseScheduleViewModel temp = new CourseScheduleViewModel();
                temp.Code       = reader["Code"] != null ? reader["Code"].ToString(): "-1";
                temp.CourseName = reader["CourseName"] != null ? reader["CourseName"].ToString(): "-1";
                temp.DayName    = reader["DayName"] != null ? reader["DayName"].ToString() : "-1";
                temp.DeptCode   = reader["DeptCode"] != DBNull.Value ? reader["DeptCode"].ToString() : "-1";
                temp.FromTime   = reader["FromTime"] != DBNull.Value ? (int)reader["FromTime"] : 0;
                temp.ToTime     = reader["ToTime"] != DBNull.Value ? (int)reader["ToTime"] : 0;
                temp.RoomNo     = reader["RoomNo"] != DBNull.Value ? reader["RoomNo"].ToString() : "-1";
                if (temp.Code.Equals("-1"))
                {
                    continue;
                }
                RoomAndTime rt = new RoomAndTime();
                rt.RoomNo   = temp.RoomNo.Equals("-1") ? "Not Scheduled Yet" : temp.RoomNo;
                rt.DayName  = temp.DayName.Equals("-1") ? string.Empty : temp.DayName;
                rt.ToTime   = temp.ToTime;
                rt.FromTime = temp.FromTime;

                if (result.FirstOrDefault(x => x.Code.Equals(temp.Code)) != null)
                {
                    // existing
                    var t = result.FirstOrDefault(x => x.Code.Equals(temp.Code));
                    t.RoomAndTimes.Add(rt);
                }
                else
                {
                    var t = new StructredCourseScheduleViewModel();
                    t.Code       = temp.Code;
                    t.CourseName = temp.CourseName;

                    t.RoomAndTimes.Add(rt);
                    result.Add(t);
                    // new
                }
            }

            reader.Close();
            Connection.Close();
            return(result);
        }
Exemplo n.º 2
0
        public ActionResult Course(Guid semId, Guid currId, Guid courseId)
        {
            var semester = SemesterService.GetSemester(semId);
            var curr     = Db.Curricula.SingleOrDefault(x => x.Id == currId);
            var course   = Db.Activities.OfType <Course>().SingleOrDefault(x => x.Id == courseId);

            var model = new CourseScheduleViewModel
            {
                Semester   = semester,
                Curriculum = curr,
                Course     = course
            };

            return(View(model));
        }
        private CourseScheduleViewModel PrepareViewModel(
            List <CourseScheduleModel> input,
            CourseScheduleParameters parameters)
        {
            if (input == null || parameters == null)
            {
                throw new ArgumentNullException(nameof(input));
            }

            try
            {
                _logger.LogInformation("PrepareViewModel: " +
                                       "CourseScheduleModel: " + input.Count + " " +
                                       "CourseScheduleParameters: " + parameters.DatetimeRequest + " " +
                                       "GroupName: " + parameters.GroupName
                                       );

                // если отсутствуют данные о расписании, возвращаем пустую модель
                if (IsEmptyCourseSchedule(input))
                {
                    var emptyCourseScheduleViewModel = new CourseScheduleViewModel
                    {
                        NameOfDayWeek =
                            parameters.NameOfDayWeek.ToUpper(),
                        DatetimeRequest  = parameters.DatetimeRequest.Date.ToShortDateString(),
                        UpdateDatetime   = _fileService.GetLastWriteTime(parameters.FileName).Result.ToShortDateString(),
                        CoursesViewModel = new List <CourseViewModel> {
                            new CourseViewModel()
                        },
                        NumberWeek = _parityOfTheWeekService.GetCountParityOfWeek(parameters.DatetimeRequest.Date)
                    };

                    return(emptyCourseScheduleViewModel);
                }

                // маппим список предметов из бд в модель представления
                var coursesViewModel = _mapper.Map <List <CourseViewModel> >(input);

                // удаляем пустые предметы и сортируем по позиции в раписании
                var sortedCoursesViewModel = coursesViewModel
                                             .Where(w => !string.IsNullOrEmpty(w.CourseName))
                                             .OrderBy(o => o.CourseNumber)
                                             .ToList();

                // создаем результирующую модель представления
                var resultCourseScheduleViewModel = new CourseScheduleViewModel
                {
                    CoursesViewModel = sortedCoursesViewModel,
                    NameOfDayWeek    = parameters.NameOfDayWeek.ToUpper(),
                    DatetimeRequest  = parameters.DatetimeRequest.Date.ToShortDateString(),
                    UpdateDatetime   = _fileService.GetLastWriteTime(parameters.FileName).Result.Date.ToShortDateString(),
                    NumberWeek       = _parityOfTheWeekService.GetCountParityOfWeek(parameters.DatetimeRequest)
                };

                _logger.LogInformation("PrepareViewModel: "
                                       + "CoursesViewModel: " + "DatetimeRequest: " +
                                       resultCourseScheduleViewModel.DatetimeRequest + " " +
                                       "CoursesViewModel.Count: " + resultCourseScheduleViewModel.CoursesViewModel.Count
                                       );

                return(resultCourseScheduleViewModel);
            }
            catch (Exception ex)
            {
                _logger.LogInformation("PrepareViewModel Exception: " + ex);
                throw new NotSupportedException("Ошибка во время выполнения." + ex);
            }
        }