示例#1
0
        public MainPageViewModel(INavigation navigation)
        {
            _navigation = navigation;
            Setup();

            TakePhotoCommand = new Command(async() =>
            {
                var isSimulator = DependencyService.Get <ISpecificPlatform>().CheckIfSimulator();
                if (isSimulator)
                {
                    Utilities.DisplayMessage("Action not supported, image will be loaded in simulator mode.");
                }
                else
                {
                    await TakePictureAsync();
                }
            });

            NextPageCommand = new Command(async() =>
            {
                var isSimulator = DependencyService.Get <ISpecificPlatform>().CheckIfSimulator();
                if (isSimulator)
                {
                    PictureStream = processProvider.GetDummyStream();
                }

                if (string.IsNullOrEmpty(Fullname) || string.IsNullOrEmpty(Age) || string.IsNullOrEmpty(Weight) || SelectedGender == "Select a gender" || PictureStream == null)
                {
                    Utilities.DisplayMessage("Please ensure all required fields are filled.");
                }
                else
                {
                    IsRunning     = true;
                    IsNextEnabled = false;

                    Participant participant = new Participant();
                    participant.FullName    = Fullname;
                    participant.Age         = Age;
                    participant.Weight      = Weight;
                    participant.Gender      = SelectedGender;

                    //save participant in cloud.
                    await processProvider.ProcessParticipantAsync(PictureStream)
                    .ContinueWith(async(b) =>
                    {
                        if (b.Result == string.Empty)
                        {
                            IsRunning     = false;
                            IsNextEnabled = true;

                            Utilities.DisplayMessage("There was a problem with the blob service.");
                        }
                        else
                        {
                            participant.FileName = b.Result;

                            //save record in cloud.
                            await Sender.SaveDataInCloudAsync(participant)
                            .ContinueWith((c) =>
                            {
                                if (c.Result)
                                {
                                    Device.BeginInvokeOnMainThread(() =>
                                    {
                                        IsRunning     = false;
                                        IsNextEnabled = true;

                                        Utilities.DisplayMessage("Record saved successfully.");
                                    });
                                }
                                else
                                {
                                    IsRunning     = false;
                                    IsNextEnabled = true;

                                    Utilities.DisplayMessage("There was a problem with the service.");
                                }
                            });
                        }
                    });
                }
            });
        }