Exemplo n.º 1
0
 private void UpdateSchedule(Schedule findedSchedule, Schedule schedule)
 {
     findedSchedule.TeacherId = teacherService.GetIdByName(schedule.Teacher.FirstName, schedule.Teacher.LastName, schedule.Teacher.MiddleName);
     findedSchedule.SubjectId = subjectService.GetAllSubjects().FirstOrDefault(s => s.Name == schedule.Subject.Name).Id;
     this.unitOfWork.ScheduleRepository.Update(findedSchedule);
 }
Exemplo n.º 2
0
 public void RemoveSchedule(Schedule schedule)
 {
     this.unitOfWork.ScheduleRepository.Delete(schedule);
 }
Exemplo n.º 3
0
        private void AddSchedule(Schedule schedule)
        {
            schedule.TeacherId = this.teacherService.GetIdByName(schedule.Teacher.FirstName, schedule.Teacher.LastName, schedule.Teacher.MiddleName);
            schedule.SubjectId = subjectService.GetAllSubjects().FirstOrDefault(s => s.Name == schedule.Subject.Name).Id;
            schedule.ClassRoomId = unitOfWork.ClassRoomRepository.GetMany(c => c.Name == schedule.ClassRoom.Name).First().Id;

            schedule.Teacher = null;
            schedule.Subject = null;
            schedule.ClassRoom = null;

            unitOfWork.ScheduleRepository.Add(schedule);
            SaveSchedule();
            Schedule getedSchedule = unitOfWork.ScheduleRepository.GetMany(s=>s.GroupId==schedule.GroupId&&s.DayOfTheWeek==schedule.DayOfTheWeek&&s.OrderNumber==schedule.OrderNumber).First();
            this.lessonDetailService.GenereteLessonDeatail(getedSchedule);
        }
        public void GenereteLessonDeatail(Schedule addedSchedule)
        {
            bool IsLessonDateInHolidays = false;
            var holidays = this.unitOfWork.HolidaysRepository.GetAll();
            var IsExistLessonDetalis = this.unitOfWork.LessonDetailRepository.GetMany(p => p.ScheduleId == addedSchedule.Id);
            DateTime DataOfLesson;
            DateTime StartTerm = new DateTime(2015, 09, 1);
            DateTime EndTerm = new DateTime(2015, 12, 30);
            DateTime FirstDateOfLesson = StartTerm;
            LessonDetail NewLessonDetail;
                do
                {
                    if ((int)StartTerm.DayOfWeek == addedSchedule.DayOfTheWeek)
                    {
                        FirstDateOfLesson = StartTerm;
                        break;
                    }
                    else
                    {
                        StartTerm = StartTerm.AddDays(1);
                    }
                } while (StartTerm < EndTerm);

            if (IsExistLessonDetalis.Count() == 0)
            {
                DataOfLesson = FirstDateOfLesson;
                do
                {
                    IsLessonDateInHolidays = false;

                    foreach (var holiday in holidays)
                    {
                        if (holiday.Name.Contains("Semestr") == false)
                        {
                            if (DataOfLesson > holiday.StartDay && DataOfLesson < holiday.EndDay)
                            {
                                IsLessonDateInHolidays = true;
                                break;
                            }
                        }
                    }
                    if (!IsLessonDateInHolidays)
                    {
                        NewLessonDetail = new LessonDetail { ScheduleId = addedSchedule.Id, Date = DataOfLesson, SchoolId = 1 };
                        this.unitOfWork.LessonDetailRepository.Add(NewLessonDetail);
                        this.SaveLessonDetail();
                    }
                    DataOfLesson = DataOfLesson.AddDays(7);
                } while (DataOfLesson <= EndTerm);
            }
            else
            {
                foreach (var lessonDetail in IsExistLessonDetalis)
                {
                    lessonDetail.ScheduleId = addedSchedule.Id;
                    UpdateLessonDetail(lessonDetail);
                    this.SaveLessonDetail();
                }

            }
        }