public override async Task OnNavigatedToAsync(INavigationParameters parameters)
        {
            if (parameters.GetNavigationMode() == NavigationMode.New)
            {
                using (_userDialogs.Loading(ConstantStrings.Loading))
                {
                    Request = parameters.GetValue <EvlRequestItemSource>(nameof(Request));

                    List <PhotoTypeDto> photos;

                    if (Request.InsuranceType == InsuranceType.Sales)
                    {
                        photos = await _initialDataService.GetSalesPhotos();
                    }
                    else
                    {
                        photos = await _initialDataService.GetBadanePhotos();
                    }

                    List <EvlRequestFileItemSource> files = photos.Select(i =>
                                                                          new EvlRequestFileItemSource
                    {
                        IsRequired = i.IsRequired,
                        TypeId     = i.ID,
                        TypeName   = i.Name,
                        Image      = ImageSource.FromResource("Sanaap.App.Images.photo.jpg")
                    }).ToList();

                    Files = new ObservableCollection <EvlRequestFileItemSource>(files);

                    await base.OnNavigatedToAsync(parameters);
                }
            }
        }
示例#2
0
        public override async Task OnNavigatingToAsync(INavigationParameters parameters)
        {
            _evlRequest = parameters.GetValue <EvlRequestItemSource>(nameof(EvlRequestItemSource));

            Message         = ConstantStrings.ExpertFinding;
            IsVisibleBefore = true;
            IsVisibleAfter  = false;
            string result = null;

            EvlRequestExpertDto expertDto = await _evlRequestService.FindEvlRequestExpert(_evlRequest.Id);

            try
            {
                CustomerDto customer = await _initialDataService.GetCurrentUserInfo();

                FindExpertRequestDto findExpertDto = new FindExpertRequestDto();
                findExpertDto.UserID          = customer.Id.ToString();
                findExpertDto.RequestID       = _evlRequest.Id.ToString();
                findExpertDto.Type            = _evlRequest.InsuranceType == InsuranceType.Sales ? 2 : 1;
                findExpertDto.AccidentDate    = _dateTimeUtils.ConvertMiladiToShamsi(DateTimeOffset.Now);
                findExpertDto.MapLat          = _evlRequest.Latitude.ToString();
                findExpertDto.MapLng          = _evlRequest.Longitude.ToString();
                findExpertDto.LostName        = _evlRequest.LostFirstName;
                findExpertDto.LostFamily      = _evlRequest.LostLastName;
                findExpertDto.LostInsuranceID = 1;     // 1
                findExpertDto.LostCarID       = _evlRequest.LostCarId;
                findExpertDto.LostCarType     = "415"; // 415
                findExpertDto.Address         = "یوسف آباد کوچه هفتم";
            }
            catch (Exception ex)
            {
                await NavigationService.NavigateAsync($"/{nameof(NavigationPage)}/{nameof(MainMenuView)}");

                await _pageDialogService.DisplayAlertAsync("", ConstantStrings.FindNearExpertError, ErrorMessages.Ok);
            }

            if (result == "NotResult")
            {
                await NavigationService.NavigateAsync($"/{nameof(NavigationPage)}/{nameof(MainMenuView)}");

                await _pageDialogService.DisplayAlertAsync("", ConstantStrings.FindNearExpertNotResult, ErrorMessages.Ok);

                return;
            }


            IsVisibleBefore = false;
            IsVisibleAfter  = true;
            Message         = ConstantStrings.ExpertFind;
            if (result != null)
            {
                string[] res = result.Split('^');
                ExpertFullName = res[0];
                ExpertMobileNo = res[1];
                byte[] imageAsBytes = Convert.FromBase64String(res[2].Split(',')[1]);
                ExpertImage = ImageSource.FromStream(() => new MemoryStream(imageAsBytes));
            }

            await base.OnNavigatingToAsync(parameters);
        }
示例#3
0
        public InsuranceListPopupViewModel(IEventAggregator eventAggregator, IPolicyService policyService, IUserDialogs userDialogs)
        {
            _policyService = policyService;
            _userDialogs   = userDialogs;

            EvlRequestItemSource _request = new EvlRequestItemSource();

            SubscriptionToken = eventAggregator.GetEvent <InsuranceEvent>().SubscribeAsync(async(request) =>
            {
                _request = request;

                insuranceCancellationTokenSource?.Cancel();
                insuranceCancellationTokenSource = new CancellationTokenSource();

                using (_userDialogs.Loading(ConstantStrings.Loading, cancelText: ConstantStrings.Loading_Cancel, onCancel: insuranceCancellationTokenSource.Cancel))
                {
                    await loadInsurances();
                }
            }, keepSubscriberReferenceAlive: true, threadOption: ThreadOption.UIThread);

            SelectPolicy = new BitDelegateCommand <PolicyItemSource>(async(policy) =>
            {
                eventAggregator.GetEvent <OpenInsurancePopupEvent>().Publish(new OpenInsurancePopupEvent());

                //await NavigationService.NavigateAsync(nameof(EvaluationRequestView), new NavigationParameters {
                //    { "Insurance",policy},
                //    {nameof(EvlRequestItemSource),_request }
                //});
            });
        }
示例#4
0
        public override async Task OnNavigatedToAsync(INavigationParameters parameters)
        {
            if (parameters.TryGetValue("IsOpenInsurance", out bool isOpen))
            {
                _eventAggregator.GetEvent <OpenInsurancePopupEvent>().Publish(new OpenInsurancePopupEvent());

                _request = parameters.GetValue <EvlRequestItemSource>("Request");

                insuranceCancellationTokenSource?.Cancel();
                insuranceCancellationTokenSource = new CancellationTokenSource();

                using (_userDialogs.Loading(ConstantStrings.Loading, cancelText: ConstantStrings.Loading_Cancel, onCancel: insuranceCancellationTokenSource.Cancel))
                {
                    await loadInsurances(_request.InsuranceType);
                }
            }
        }
        public EvaluationRequestFilesViewModel(IMedia media,
                                               IODataClient oDataClient,
                                               IUserDialogs userDialogs,
                                               IInitialDataService initialDataService,
                                               IPageDialogService dialogService,
                                               IClientAppProfile clientApp,
                                               IEventAggregator eventAggregator,
                                               ISecurityService securityService)
        {
            _oDataClient        = oDataClient;
            _userDialogs        = userDialogs;
            _initialDataService = initialDataService;

            TakePhoto = new BitDelegateCommand <EvlRequestFileItemSource>(async(file) =>
            {
                //500 is ID for More pictures
                if (file.TypeId == 500)
                {
                    Files.Add(new EvlRequestFileItemSource {
                        TypeId = file.TypeId, TypeName = file.TypeName, Image = file.Image
                    });
                }

                _fileIndex = Files.IndexOf(file);

                eventAggregator.GetEvent <TakePhotoEvent>().Publish(new TakePhotoEvent());
            });

            GoBack = new BitDelegateCommand(async() =>
            {
                await NavigationService.GoBackAsync();
            });

            OpenCamera = new BitDelegateCommand(async() =>
            {
                eventAggregator.GetEvent <TakePhotoEvent>().Publish(new TakePhotoEvent());

                MediaFile mediaFile = await media.TakePhotoAsync(new StoreCameraMediaOptions
                {
                    Directory          = "Sanaap",
                    SaveToAlbum        = true,
                    CompressionQuality = 25,
                    CustomPhotoSize    = 30,
                    PhotoSize          = PhotoSize.Medium,
                    MaxWidthHeight     = 2000,
                    AllowCropping      = true,
                    DefaultCamera      = CameraDevice.Rear
                });

                if (mediaFile != null)
                {
                    using (MemoryStream ms = new MemoryStream())
                    {
                        mediaFile.GetStream().CopyTo(ms);
                        Files[_fileIndex].Data = ms.ToArray();
                    }

                    Files[_fileIndex].Image    = ImageSource.FromStream(() => mediaFile.GetStream());
                    Files[_fileIndex].HasImage = true;
                }
                else
                {
                    await dialogService.DisplayAlertAsync(ConstantStrings.Error, ConstantStrings.PictureIsNull, ConstantStrings.Ok);
                }
            });

            Gallery = new BitDelegateCommand(async() =>
            {
                eventAggregator.GetEvent <TakePhotoEvent>().Publish(new TakePhotoEvent());

                MediaFile mediaFile = await media.PickPhotoAsync(new PickMediaOptions
                {
                    PhotoSize          = PhotoSize.Medium,
                    CompressionQuality = 25,
                });

                if (mediaFile != null)
                {
                    using (MemoryStream ms = new MemoryStream())
                    {
                        mediaFile.GetStream().CopyTo(ms);
                        Files[_fileIndex].Data = ms.ToArray();
                    }

                    Files[_fileIndex].Image    = ImageSource.FromStream(() => mediaFile.GetStream());
                    Files[_fileIndex].HasImage = true;
                }
                else
                {
                    await dialogService.DisplayAlertAsync(ConstantStrings.Error, ConstantStrings.PictureIsNull, ConstantStrings.Ok);
                }
            });

            Submit = new BitDelegateCommand(async() =>
            {
                if (Files.Any(f => f.IsRequired && f.HasImage == false))
                {
                    await dialogService.DisplayAlertAsync(ConstantStrings.Error, ConstantStrings.PictureIsRequired, ConstantStrings.Ok);

                    return;
                }

                if (await dialogService.DisplayAlertAsync(string.Empty, ConstantStrings.AreYouSure, ConstantStrings.Yes, ConstantStrings.No))
                {
                    using (HttpClient http = new HttpClient())
                    {
                        http.BaseAddress = clientApp.HostUri;

                        http.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", (await securityService.GetCurrentTokenAsync()).access_token);

                        using (userDialogs.Loading(ConstantStrings.SendingRequestAndPictures))
                        {
                            MultipartFormDataContent submitEvlRequestContents = new MultipartFormDataContent
                            {
                                new StringContent(JsonConvert.SerializeObject(Request), Encoding.UTF8, "application/json")
                            };

                            foreach (EvlRequestFileDto file in Files.Where(f => f.Data != null))
                            {
                                submitEvlRequestContents.Add(new ByteArrayContent(file.Data), file.TypeId.ToString(), file.TypeId.ToString());
                            }

                            HttpRequestMessage submitEvlRequest = new HttpRequestMessage(HttpMethod.Post, "api/evl-requests/submit-evl-request")
                            {
                                Content = submitEvlRequestContents
                            };

                            HttpResponseMessage submitEvlRequestExpertResponse = await http.SendAsync(submitEvlRequest);

                            submitEvlRequestExpertResponse.EnsureSuccessStatusCode();

                            Request = JsonConvert.DeserializeObject <EvlRequestItemSource>(await submitEvlRequestExpertResponse.Content.ReadAsStringAsync());

                            await NavigationService.NavigateAsync(nameof(EvaluationRequestWaitView), new NavigationParameters
                            {
                                { nameof(Request), Request }
                            });
                        }
                    }
                }
            });

            OpenPhoto = new BitDelegateCommand <EvlRequestFileItemSource>(async(image) =>
            {
                await NavigationService.NavigateAsync(nameof(OpenImagePopup), new NavigationParameters
                {
                    { nameof(image.Image), image.Image }
                });
            });

            DeletePhoto = new BitDelegateCommand <EvlRequestFileItemSource>(async(image) =>
            {
                if (image.HasImage == false)
                {
                    return;
                }

                if (await dialogService.DisplayAlertAsync(ConstantStrings.Error, ConstantStrings.AreYouSureToDelete, ConstantStrings.Yes, ConstantStrings.No))
                {
                    image.Image    = null;
                    image.HasImage = false;

                    await NavigationService.GoBackAsync();
                }
            });
        }