private async void SaveUnregister(TrainingSession obj) { try { bool answer = await Application.Current.MainPage.DisplayAlert("Confirmation d'annulation", "Êtes-vous sûr de vouloir vous désinscrire à la session du : " + obj.Date, "Oui", "Non"); if (answer) { int userId = int.Parse(Application.Current.Properties["UserId"].ToString()); //Register the user to the training Session in parameter int delete = TrainingSessionService.SaveUnregister(userId, obj.Id); if (delete != 0) { obj.AvailableSeat += 1; TrainingSessionService.Update(obj); ObservableCollection <TrainingSession> trainingSessions = new ObservableCollection <TrainingSession>(TrainingSessionService.GetAllByUserId(userId)); if (trainingSessions != null) { Items.Remove(obj); } //Event publish to refresh the user's trainings list Event.GetEvent <SentEventUnregister>().Publish(obj.Id); Event.GetEvent <RefreshAvailableTrainingSessionsListEvent>().Publish(); await Application.Current.MainPage.DisplayAlert("Confirmation", "Vous êtes désinscrit à la session du : " + obj.Date, "Ok"); } else { //Message d'erreur; } } } catch (Exception ex) { throw new Exception(ex.Message); } }