コード例 #1
0
ファイル: AdminController.cs プロジェクト: kingcity71/Diary
        public IActionResult LessonEdit(Guid id, Guid classId, int year, int month, int day, int hour, int min)
        {
            var dateTime = new DateTime(year, month, day, hour, min, 0);

            var schedModel = _scheduleService.GetSchedule(id);

            var viewModel = new LessonEditModel();

            viewModel.DateTime    = dateTime;
            viewModel.ClassId     = schedModel != null? schedModel.Class.Id : classId;
            viewModel.Classes     = _classService.GetClasses().ToDictionary(x => x.Id, y => y.FullName);
            viewModel.TeacherId   = schedModel == null ? Guid.Empty : schedModel.Teacher.Id;
            viewModel.TeacherName = schedModel == null ? string.Empty : schedModel.Teacher.Name;
            viewModel.Subjects    = _repoSubject.GetAllItems().ToDictionary(x => x.Id, y => y.Name);
            viewModel.SubjectId   = schedModel == null ? Guid.Empty : viewModel.Subjects.FirstOrDefault(x => x.Value == schedModel.Subject).Key;
            viewModel.Id          = schedModel == null ? Guid.Empty: schedModel.Id;

            return(View(viewModel));
        }
コード例 #2
0
ファイル: AdminController.cs プロジェクト: kingcity71/Diary
        public bool LessonEdit(LessonEditDto lessonDto)
        {
            if (lessonDto.classId == Guid.Empty ||
                !DateTime.TryParse(lessonDto.date, out var date) ||
                string.IsNullOrEmpty(lessonDto.teacherName) ||
                lessonDto.teacherId == Guid.Empty ||
                lessonDto.subjectId == Guid.Empty)
            {
                var dateTime = DateTime.Parse(lessonDto.date);

                var teacherModel = _teacherService.GetTeacherModel(lessonDto.teacherId);

                var viewModel = new LessonEditModel();
                viewModel.DateTime    = dateTime;
                viewModel.ClassId     = lessonDto.classId;
                viewModel.Classes     = _classService.GetClasses().ToDictionary(x => x.Id, y => y.FullName);
                viewModel.TeacherId   = lessonDto.teacherId;
                viewModel.TeacherName = teacherModel != null ? teacherModel.Name : string.Empty;
                viewModel.Subjects    = _repoSubject.GetAllItems().ToDictionary(x => x.Id, y => y.Name);
                viewModel.SubjectId   = lessonDto.schedId;
                viewModel.Id          = lessonDto.schedId;

                ViewBag.IsInvalid = true;
                return(false);
            }

            var schedModel = Activator.CreateInstance <ScheduleModel>();

            schedModel.Id    = lessonDto.schedId;
            schedModel.Date  = DateTime.Parse(lessonDto.date);
            schedModel.Class = new ClassModel {
                Id = lessonDto.classId
            };
            schedModel.Teacher = new TeacherModel {
                Id = lessonDto.teacherId
            };
            schedModel.Subject = _repoSubject.GetAllItems().FirstOrDefault(x => x.Id == lessonDto.subjectId).Name;

            _scheduleService.UpdateSchedule(schedModel);

            return(true);
        }