示例#1
0
        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);
            }
        }
示例#2
0
        /// <summary>
        /// Register a user to a training Session and publish it to add the training to user's trainings list
        /// </summary>
        /// <param name="obj">The training on which the user would like to register </param>
        private async void SaveRegister(PictureTrainingSessionViewModel obj)
        {
            try
            {
                // If there is not a single seat available for this training session, we show an alert.
                if (obj.AvailableSeat <= 0)
                {
                    await Application.Current.MainPage.DisplayAlert("Aucune place disponible pour cette session.", "", "OK");

                    return;
                }

                bool answer = await Application.Current.MainPage.DisplayAlert("Confirmation d'inscription", "Êtes-vous sûr de vouloir vous inscrire à 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 add = TrainingSessionService.SaveRegister(userId, obj.Id);

                    if (add != 0)
                    {
                        TrainingSession t = new TrainingSession()
                        {
                            Id            = obj.Id,
                            AvailableSeat = obj.AvailableSeat,
                            Date          = obj.Date
                        };
                        //Update the number of available seats
                        t.AvailableSeat -= 1;
                        TrainingSessionService.Update(t);

                        //Remove the session into the available sessions for the user.
                        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 <SentEvent>().Publish(obj.Id);
                        Event.GetEvent <RefreshAvailableTrainingSessionsListEvent>().Publish();

                        await Application.Current.MainPage.DisplayAlert("Validation", "Vous êtes désormais inscrit à la session du : " + obj.Date, "Ok");
                    }
                    else
                    {
                        //Message d'erreur;
                    }
                }
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
        }
示例#3
0
 private void InitializeItems()
 {
     LstTrainingSession = TrainingSessionService.GetAllByUserId(int.Parse(Application.Current.Properties["UserId"].ToString()));
     Items = new ObservableCollection <TrainingSession>(LstTrainingSession);
 }