Exemple #1
0
        private async void UsePhotoClicked(object obj)
        {
            if (IsBusy)
            {
                return;
            }
            IsBusy = true;
            string url = await Helpers.Utils.UploadFileS3(FileName);

            if (url != "")
            {
                var    bikeDetailViewModel = ViewModelLocator.Resolve <BikeDetailViewModel>();
                string uuid  = Preferences.Get("UUID", "");
                string user  = Preferences.Get("Email", "");
                string token = Preferences.Get("Token", "");


                if (imageType != (int)ImageTypes.Invoice)
                {
                    FrameNumberImage frameNumberImage = new FrameNumberImage()
                    {
                        ImageTitle = "Receipt", ImageType = imageType, ImageUrl = url
                    };
                    var result = await DataStore.RegisterImage(user, token, uuid, frameNumberImage, false);

                    if (result != null && result.ImageUrl != "")
                    {
                        Preferences.Set("ProfileImage", result.ImageUrl);
                        if (bikeDetailViewModel != null)
                        {
                            MessagingCenter.Send(bikeDetailViewModel, MessageKeys.UpdateState, 0);
                        }
                        await NavigationService.GoBackAsync();
                    }
                }
                else // if (imageType == (int)ImageTypes.Invoice)
                {
                    // Upload invoice picture as document.

                    FrameNumberDocument frameNumberDocument = new FrameNumberDocument()
                    {
                        DocumentTitle = "Receipt", DocumentType = imageType, DocumentUrl = url
                    };
                    var result = await DataStore.RegisterDocument(user, token, uuid, frameNumberDocument, false);

                    if (result != null && result.DocumentUrl != "")
                    {
                        FrameNumberStatus fns = new FrameNumberStatus()
                        {
                            LastUpdateTime     = DateTime.Now,
                            Latitude           = 0,
                            Longitude          = 0,
                            LastUpdateClientID = DeviceInfo.Name,
                            Status             = (int)FrameNumberStatusType.Registered
                        };

                        // Now set status to 'registered'

                        if (await DataStore.UpdateStatus(user, token, uuid, fns))
                        {
                            if (Preferences.Get("IsLoggedIn", "0") == "1")
                            {
                                Preferences.Set("RegisteredToBike", "1");
                            }
                        }
                    }
                    IsBusy = false;

                    // Update state
                    if (bikeDetailViewModel != null)
                    {
                        MessagingCenter.Send(bikeDetailViewModel, MessageKeys.UpdateState, 1);
                    }

                    //await NavigationService.GoBackAsync();
                    await NavigationService.NavigateToAsync <MainViewModel>(2);
                }
            }
            IsBusy = false;
        }