Пример #1
0
        private void IdReceived(int obj)
        {
            TrainingSession t = TrainingSessionService.GetByid(obj);

            // retrieve the good picture in regards to the available seats
            var pictureTraining = "";

            if (t.AvailableSeat == 0)
            {
                pictureTraining = "unavailable.png";
            }
            else if (t.AvailableSeat < 3)
            {
                pictureTraining = "warning.png";
            }

            PictureTrainingSessionViewModel pictureTrainingSessionViewModels = new PictureTrainingSessionViewModel(t, pictureTraining)
            {
                AvailableSeat = t.AvailableSeat, Date = t.Date, Id = t.Id, PictureTraining = pictureTraining
            };


            Items.Add(pictureTrainingSessionViewModels);
            List <PictureTrainingSessionViewModel> trainingSessions = Items.OrderBy(s => s.Date).ToList();

            Items.Clear();

            foreach (PictureTrainingSessionViewModel item in trainingSessions)
            {
                Items.Add(item);
            }
        }
Пример #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);
            }
        }