Ejemplo n.º 1
0
        private void tasksModelSynchronization(object sender, NotifyCollectionChangedEventArgs e)
        {
            switch (e.Action)
            {
            case NotifyCollectionChangedAction.Add:
                SingleTaskViewModel newTaskViewModel = (SingleTaskViewModel)e.NewItems[0];
                if (newTaskViewModel != null)
                {
                    tasksModel.AddTask(newTaskViewModel.GetModel());
                }
                break;

            case NotifyCollectionChangedAction.Remove:
                SingleTaskViewModel removedTask = (SingleTaskViewModel)e.OldItems[0];
                if (removedTask != null)
                {
                    tasksModel.RemoveTask(removedTask.GetModel());
                }
                break;
            }
        }
        private void onAcceptBtnClick(object sender, RoutedEventArgs e)
        {
            // get DateTime for begining of week
            DateTime mondayDateTime = DateTime.Now;

            while (mondayDateTime.DayOfWeek != DayOfWeek.Monday)
            {
                mondayDateTime = mondayDateTime.AddDays(-1);
            }

            ScheduleModel schedule = Data.ScheduleDAL.GetSchedule();
            string        subject  = schedule.Schedule[day][lesson];

            // get date when task was assigned;
            DateTime assigned = mondayDateTime.AddDays(day);

            // get date of next lesson
            int weekDay      = day;
            int lessonOffset = 0;

            int      deadlineAtLesson = Convert.ToInt32(numOfLessonsTextBlock.Text);
            DateTime deadline         = assigned;

            while (deadlineAtLesson > 0)
            {
                int dayCount = 1;
                weekDay++;
                if (weekDay == 5)
                {
                    weekDay   = 0;
                    dayCount += 2;
                }
                while (schedule.Schedule[weekDay][lessonOffset] != subject)
                {
                    lessonOffset++;
                    if (lessonOffset == schedule.MaxHours)
                    {
                        lessonOffset = 0;
                        weekDay++;
                        dayCount++;
                        if (weekDay == 5)
                        {
                            weekDay   = 0;
                            dayCount += 2;
                        }
                    }
                }
                deadlineAtLesson--;
                deadline = deadline.AddDays(dayCount);
            }


            DateTime notification = deadline.Date.AddDays(-1).AddHours(17);

            Models.TaskModel task = new Models.TaskModel();

            task.Description  = descritpionTextBox.Text;
            task.Subject      = subject;
            task.Assigned     = assigned.Date;
            task.Notification = notification;
            task.Deadline     = deadline;
            tasks.AddTask(task);
            this.Frame.Navigate(typeof(Pages.SchedulePage));
        }