Exemple #1
0
        /// <summary>
        /// Method used to add the selected lessons to the database for the user
        /// </summary>
        /// <returns>Returns true if all the lessons are succesfully added</returns>
        private bool AddLesson()
        {
            int  numberOfLessons = lessonsComboBox.SelectedIndex + 1;
            bool result          = true;

            if (addedFirstLesson)
            {
                numberOfLessons -= 1;

                Lesson firstLesson = Session.GetLastLessonFromType(_appointment.LessonType);
                firstLesson.Progress = 1;
                Lesson newLesson = new Lesson(
                    Session.LoggedInUser.Id,
                    _appointment.Id,
                    firstLesson.TemplateID,
                    firstLesson.Progress,
                    addThisLessonLessonTemplate,
                    startDateTime,
                    startDateTime = startDateTime.AddMinutes(45),
                    false);

                result = DatabaseParser.AddLesson(newLesson);

                if (result) // if lesson is added its manually added to lessons in appointment id
                {
                    Session.LoggedInUser.LessonsList.Add(newLesson);
                    Session.UpdateCurrentLesson();
                }

                addThisLessonProgress = firstLesson.Progress;
            }
            for (int i = 0; i < numberOfLessons; i++)
            {
                if (!result)
                {
                    return(false);
                }

                Lesson newLesson = new Lesson(
                    Session.LoggedInUser.Id,
                    _appointment.Id,
                    Session.NextLesson.TemplateID,
                    Session.NextLesson.Progress,
                    Session.NextLesson.LessonTemplate,
                    startDateTime,
                    startDateTime = startDateTime.AddMinutes(45),
                    false);


                result = DatabaseParser.AddLesson(newLesson);


                Session.LoggedInUser.LessonsList.Add(newLesson);
                Session.UpdateCurrentLesson();
            }

            return(true);
        }