public void UpdateTutoringSession(TutoringSession ts) { if (ts != null) { try { //Vi måste väl ta bort tutoingsession ur kursen och lägga till en ny väl? Course tmpCourse = Courses.FirstOrDefault(c => c.Code.Equals(ts.Code)); TutoringSessionUpdateDTO tsDTO = new TutoringSessionUpdateDTO(selectedTutoringSession, ts); dal.UpdateTutoringSession(tsDTO); Status = "Tutoring Session was updated"; } catch (Exception ex) { Status = ExceptionHandler.GetErrorMessage(ex); } TutoringSessions = new ObservableCollection <TutoringSession>(dal.GetAllTutoringSessions()); NotifyPropertyChanged("TutoringSessions"); Courses = new ObservableCollection <Course>(dal.GetAllCourses()); NotifyPropertyChanged("Courses"); SelectedTutoringSession = null; NotifyPropertyChanged("SelectedTutoringSession"); SelectedCourse = Courses.FirstOrDefault(c => c.Code.Equals(ts.Code)); NotifyPropertyChanged("SelectedCourse"); } }
public void AddTutor(TutoringSession ts) { if (ts != null) { TutorTutoringSession tmptts = new TutorTutoringSession(selectedTutor, ts); try { TutoringSessionUpdateDTO updateDTO = new TutoringSessionUpdateDTO(ts, ts); ts.Tutors.Add(tmptts); selectedTutor.TutoringSessions.Add(tmptts); dal.UpdateTutoringSession(updateDTO); Status = "Added to planned sessions"; } catch (Exception ex) { // Rollback ts.Tutors.Remove(tmptts); selectedTutor.TutoringSessions.Remove(tmptts); Status = ExceptionHandler.GetErrorMessage(ex); } NotifyPropertyChanged("TutorTutoredHours"); NotifyPropertyChanged("TutorPlannedHours"); NotifyPropertyChanged("TutorLastSession"); NotifyPropertyChanged("TutorNextSession"); NotifyPropertyChanged("AvailableTutoringSessions"); NotifyPropertyChanged("PlannedTutoringSessions"); } }
public void DeleteTutor(TutoringSession ts) { if (ts != null) { ICollection <TutorTutoringSession> tutorTutoringSessionsToBeDeleted = new List <TutorTutoringSession>(); foreach (TutorTutoringSession tts in ts.Tutors) { if (tts.Tutor.Equals(selectedTutor)) { tutorTutoringSessionsToBeDeleted.Add(tts); } } foreach (TutorTutoringSession tts in tutorTutoringSessionsToBeDeleted) { ts.Tutors.Remove(tts); selectedTutor.TutoringSessions.Remove(tts); } try { TutoringSessionUpdateDTO updateDTO = new TutoringSessionUpdateDTO(ts, ts); dal.UpdateTutoringSession(updateDTO); Status = "Removed from planned sessions"; } catch (Exception ex) { // Rollback foreach (TutorTutoringSession tts in ts.Tutors) { ts.Tutors.Add(tts); selectedTutor.TutoringSessions.Add(tts); } Status = ExceptionHandler.GetErrorMessage(ex); } NotifyPropertyChanged("TutorTutoredHours"); NotifyPropertyChanged("TutorPlannedHours"); NotifyPropertyChanged("TutorLastSession"); NotifyPropertyChanged("TutorNextSession"); NotifyPropertyChanged("AvailableTutoringSessions"); NotifyPropertyChanged("PlannedTutoringSessions"); } }