Beispiel #1
0
        public int CreateConnection(int ID, string connectionName, int lessonID)
        {
            User   _currentUser = userManager.GetUser(ID);
            Lesson lesson       = lessonManager.GetLesson(lessonID);

            List <Connection> connections = new List <Connection>();

            connections.AddRange(_currentUser.ConnectionsAsSharer);
            connections.AddRange(_currentUser.ConnectionsAsViewer);

            if (connections.Where(w => w.IsConnectionEnded == false).Count() == 0)
            {
                Connection _newConnection = new Connection();

                _newConnection.ConnectionName = connectionName;
                _newConnection.ConnectionDate = DateTime.Now;

                switch (_currentUser.PendingStatus)
                {
                case "Viewer":
                    _newConnection.Viewer = _currentUser;
                    _currentUser.ConnectionsAsViewer.Add(_newConnection);
                    lesson.Connections.Add(_newConnection);
                    _newConnection.Lesson = lesson;
                    break;

                case "Sharer":
                    _newConnection.Sharer = _currentUser;
                    _currentUser.ConnectionsAsSharer.Add(_newConnection);
                    lesson.Connections.Add(_newConnection);
                    _newConnection.Lesson = lesson;
                    break;

                default:
                    return(-1);
                }

                //entities.Users.Attach(_currentUser);

                connectionManager.AddConnection(_newConnection);

                uow.Save();

                return(_newConnection.ID);
            }
            else
            {
                return(-1);
            }
        }
        public TransactionObject AddLesson(AddLessonFormData alFormData)
        {
            TransactionObject response = new TransactionObject();

            try
            {
                Education education = educationManager.GetEducation(alFormData.StudentID, alFormData.LessonID);

                Student selectedStudent = studentManager.GetStudent(alFormData.StudentID);
                Lesson  selectedLesson  = lessonManager.GetLesson(alFormData.LessonID);

                if (education != null)
                {
                    Period currentPeriod = periodManager.GetPeriod(selectedLesson.Period.Year, selectedLesson.Period.Semester);


                    Note note = new Note
                    {
                        ResultPoint = alFormData.Result,
                        Description = alFormData.Description,
                        EffectRate  = alFormData.Effect,
                        Education   = education
                    };

                    note.Education = education;
                    education.Notes.Add(note);


                    noteManager.AddNote(note);
                }
                else
                {
                    education         = new Education();
                    education.Student = selectedStudent;
                    selectedStudent.Educations.Add(education);

                    education.Lesson = selectedLesson;
                    selectedLesson.Educations.Add(education);


                    Note note = new Note
                    {
                        ResultPoint = alFormData.Result,
                        Description = alFormData.Description,
                        EffectRate  = alFormData.Effect,
                        Education   = education
                    };

                    education.Notes.Add(note);

                    note.Education = education;

                    noteManager.AddNote(note);
                    educationManager.AddEducation(education);
                }

                double avg = 0;
                education.Notes.ForEach(note => avg += (note.EffectRate / 100) * note.ResultPoint);
                education.Average = avg;

                uow.Save();
                response.IsSuccess = true;
            }
            catch (Exception ex)
            {
                response.IsSuccess   = false;
                response.Explanation = base.GetExceptionMessage(ex);
            }


            return(response);
        }
Beispiel #3
0
 public Lesson GetLesson(int ID)
 {
     return(lessonManager.GetLesson(ID));
 }
        private async void btn_Done_AddLesson_Click(object sender, RoutedEventArgs e)
        {
            bool       cont                = true;
            int        daynumber           = cmb_Day_AddLesson.SelectedIndex;
            DayOfWeek  day                 = DayOfWeek.Monday;
            bool       day_complete        = true;
            LessonTime lessontime          = LessonTimeManager.GetLessonTimes()[0];
            bool       lessontime_complete = true;
            Subject    subject             = SubjectManager.GetSubjects()[0];
            bool       subject_complete    = true;

            if (daynumber == 0)
            {
                day = DayOfWeek.Monday;
            }
            else if (daynumber == 1)
            {
                day = DayOfWeek.Tuesday;
            }
            else if (daynumber == 2)
            {
                day = DayOfWeek.Wednesday;
            }
            else if (daynumber == 3)
            {
                day = DayOfWeek.Thursday;
            }
            else if (daynumber == 4)
            {
                day = DayOfWeek.Friday;
            }
            else
            {
                day_complete = false;
            }

            if (cmb_LessonTime_AddLesson.SelectedIndex != -1)
            {
                lessontime = (LessonTime)cmb_LessonTime_AddLesson.SelectedItem;
            }
            else
            {
                lessontime_complete = false;
            }

            if (cmb_Subject_AddLesson.SelectedIndex != -1)
            {
                subject = (Subject)cmb_Subject_AddLesson.SelectedItem;
            }
            else
            {
                subject_complete = false;
            }

            if (day_complete == false || lessontime_complete == false || subject_complete == false)
            {
                LessonManager.not_completed_dialog();
            }
            else
            {
                if (LessonManager.GetLesson(day, lessontime) != null)
                {
                    ContentDialogResult result = await LessonManager.already_exists_dialog();

                    if (result == ContentDialogResult.Secondary)
                    {
                        edit_lesson = LessonManager.GetLesson(day, lessontime);
                    }
                    else
                    {
                        cont = false;
                    }
                }
                if (cont)
                {
                    if (edit_lesson != null)
                    {
                        LessonManager.DeleteLesson(edit_lesson.day, edit_lesson.lesson_time);
                    }
                    LessonManager.AddLesson(new Lesson {
                        day = day, lesson_time = lessontime, subject_id = subject.id
                    });
                }
            }
            if (cont)
            {
                Frame.GoBack();
            }
        }