/// <summary> /// Method to retrieve changes made on the page containing my lessons /// This method adds the new element to the table and sorts it according to the dates of the lessons /// </summary> /// <param name="id"></param> private void MessageReceived(int id) { Items.Add(DrivingLessonService.GetByIdWithInstructor(id)); List <DrivingLessonInstructor> liste = Items.OrderBy(s => s.DateTime).ToList(); Items.Clear(); foreach (DrivingLessonInstructor item in liste) { Items.Add(item); } }
/// <summary> /// Display a PopUp and perform an action depending on the chosen option /// </summary> /// <param name="DrivingLessonInstructor"></param> private async void ShowExitDialog(DrivingLessonInstructor DrivingLessonInstructor) { int id = DrivingLessonInstructor.DrivingLessonId; TimeSpan difference = DrivingLessonInstructor.DateTime - DateTime.Now; // If the course takes place in 3 days or more if (difference.Days >= 3) { var answer = await Application.Current.MainPage.DisplayAlert("Confirmation de désinscription", "Êtes vous sûr de vouloir vous désinscrire à la leçon du \n" + DrivingLessonInstructor.DateTime + "? \n\nInstructeur : " + DrivingLessonInstructor.InstructorFirstName + " " + DrivingLessonInstructor.InstructorLastName, "Oui", "Non"); // If the user responds positively if (answer) { // The driving lesson loses the id of the user int updateLessonId = DrivingLessonService.UpdateUserIdForDrivingLesson(id, 0); ListeDrivingLessons = DrivingLessonService.GetMyDrivingLessonsByUserId(int.Parse(Application.Current.Properties["UserId"].ToString()), true); if (ListeDrivingLessons != null) { // The lesson is removed from the table Items.Remove(DrivingLessonInstructor); } // Informations of this lesson are sent to the page containing all available lessons _ea.GetEvent <DrivingSentEventUnregister>().Publish(updateLessonId); if (updateLessonId != 0) { // Deleting notifications for canceled lesson InitializeItems(); NotificationCenter.Current.Cancel(int.Parse(DrivingLessonInstructor.DrivingLessonId.ToString() + "1")); NotificationCenter.Current.Cancel(int.Parse(DrivingLessonInstructor.DrivingLessonId.ToString() + "3")); } else { await Application.Current.MainPage.DisplayAlert("Erreur", "Une erreur est survenue pendant l'annulation de l'inscription à la séssion. Veuillez réésayer. Si le problème persiste, veuillez contacter l'auto école.", "Ok"); } } } // Otherwise, the user can not cancel the course else { await Application.Current.MainPage.DisplayAlert("Erreur", "Vous ne pouvez pas supprimer une session qui est prévue pour dans moins de 72h.", "Ok"); } }
// Initialization of datas into table private void InitializeItems() { ListeDrivingLessons = DrivingLessonService.GetMyDrivingLessonsByUserId(int.Parse(Application.Current.Properties["UserId"].ToString()), false); Items = new ObservableCollection <DrivingLessonInstructor>(ListeDrivingLessons); }
/// <summary> /// Constructor of the viewModel /// </summary> /// <param name="navigationService"></param> /// <param name="drivingLessonService"></param> public HistoryDrivingLessonsPageViewModel(INavigationService navigationService, DrivingLessonService drivingLessonService) : base(navigationService, drivingLessonService) { Title = "Historique des leçons"; InitializeItems(); CommentLessonCommand = new DelegateCommand <DrivingLessonInstructor>(CommentLesson); }
/// <summary> /// Popup to validate or not a registration to a driving court /// </summary> /// <param name="DrivingLessonInstructor"></param> private async void ShowExitDialog(DrivingLessonInstructor DrivingLessonInstructor) { int id = DrivingLessonInstructor.DrivingLessonId; int userId = int.Parse(Application.Current.Properties["UserId"].ToString()); bool answer = await Application.Current.MainPage.DisplayAlert("Confirmation d'inscription", "Êtes-vous sûr de vouloir vous inscrire à la leçon du \n" + DrivingLessonInstructor.DateTime + " ?\n \nInstructeur : \n" + DrivingLessonInstructor.InstructorFirstName + " " + DrivingLessonInstructor.InstructorLastName, "Oui", "Non"); // If the user responds positively to the popup if (answer) { int drivingLessonId = DrivingLessonService.UpdateUserIdForDrivingLesson(id, userId); ListeDrivingLessons = DrivingLessonService.GetDrivingLessonsByUserId(userId); if (ListeDrivingLessons != null) { // Actualization of table Items.Clear(); foreach (DrivingLessonInstructor item in ListeDrivingLessons) { Items.Add(item); } } if (drivingLessonId != 0) { // Notification one hour before class var notification = new NotificationRequest { NotificationId = int.Parse(DrivingLessonInstructor.DrivingLessonId.ToString() + "1"), Title = "Seance de conduite", Description = "Attention, vous avez une leçon de conduite à " + DrivingLessonInstructor.DateTime.Hour + "h et " + DrivingLessonInstructor.DateTime.Minute + "m.", ReturningData = "Dummy data", // Returning data when tapped on notification. NotifyTime = DrivingLessonInstructor.DateTime.AddHours(-1) }; NotificationCenter.Current.Show(notification); DateTime dateLecon = new DateTime(DrivingLessonInstructor.DateTime.Year, DrivingLessonInstructor.DateTime.Month, DrivingLessonInstructor.DateTime.Day); DateTime dateJour = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day); // If the lesson goes well in at least a day if (dateLecon > dateJour) { // Notification one day before class notification = new NotificationRequest { NotificationId = int.Parse(DrivingLessonInstructor.DrivingLessonId.ToString() + "3"), Title = "Seance de conduite", Description = "Attention, vous avez une leçon de conduite demain à " + DrivingLessonInstructor.DateTime.Hour + "h et " + DrivingLessonInstructor.DateTime.Minute + "m.", ReturningData = "Dummy data", // Returning data when tapped on notification. NotifyTime = DrivingLessonInstructor.DateTime.AddDays(-1) }; NotificationCenter.Current.Show(notification); } // Registration information for this lesson is sent to the page containing all my lessons _ea.GetEvent <DrivingSentEvent>().Publish(drivingLessonId); await Application.Current.MainPage.DisplayAlert("Validation", "Vous êtes désormais inscrit à la session du : " + DrivingLessonInstructor.DateTime, "Ok"); } else { await Application.Current.MainPage.DisplayAlert("Erreur", "Une erreur est survenue pendant l'inscription à la séssion. Veuillez réésayer. Si le problème persiste, veuillez contacter l'auto école.", "Ok"); } } }
/// <summary> /// Constructor of the viewModel /// </summary> /// <param name="navigationService"></param> /// <param name="ea"></param> /// <param name="drivingLessonService"></param> public DrivingLessonsListPageViewModel(INavigationService navigationService, IEventAggregator ea, DrivingLessonService drivingLessonService) : base(navigationService, drivingLessonService) { Title = "Leçons disponibles"; InitializeItems(); _ea = ea; _ea.GetEvent <DrivingSentEventUnregister>().Subscribe(MessageReceived); InscriptionLessonCommand = new DelegateCommand <DrivingLessonInstructor>(InscriptionLesson); }
public ViewModelBase(INavigationService navigationService, DrivingLessonService drivingLessonService) { NavigationService = navigationService; DrivingLessonService = drivingLessonService; }
/// <summary> /// Constructor of the viewModel /// </summary> /// <param name="navigationService"></param> /// <param name="ea"></param> /// <param name="drivingLessonService"></param> public MyLessonsPageViewModel(INavigationService navigationService, IEventAggregator ea, DrivingLessonService drivingLessonService) : base(navigationService, drivingLessonService) { Title = "Mes leçons"; InitializeItems(); _ea = ea; _ea.GetEvent <DrivingSentEvent>().Subscribe(MessageReceived); AnnulerLeconCommand = new DelegateCommand <DrivingLessonInstructor>(AnnulerLecon); }