public EvaluationRequestLostDetailViewModel(
            IUserDialogs userDialogs,
            ILicenseHelper licenseHelper,
            ISanaapAppTranslateService translateService,
            IEvlRequestValidator evlRequestValidator,
            IInitialDataService initialDataService,
            IPageDialogService dialogService)
        {
            _initialDataService = initialDataService;
            _userDialogs        = userDialogs;
            _licenseHelper      = licenseHelper;

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

            GoToNextLevel = new BitDelegateCommand(async() =>
            {
                requestCancellationTokenSource?.Cancel();
                requestCancellationTokenSource = new CancellationTokenSource();

                using (userDialogs.Loading(ConstantStrings.Loading, cancelText: ConstantStrings.Loading_Cancel, onCancel: requestCancellationTokenSource.Cancel))
                {
                    if (SelectedCar == null)
                    {
                        await dialogService.DisplayAlertAsync(ConstantStrings.Error, ConstantStrings.CarIsNull, ConstantStrings.Ok);
                        return;
                    }
                    if (SelectedAlphabet == null)
                    {
                        await dialogService.DisplayAlertAsync(ConstantStrings.Error, ConstantStrings.NumberPlateIsNotValid, ConstantStrings.Ok);
                        return;
                    }

                    Request.LostCarId = SelectedCar.PrmID;

                    LostLicense.Alphabet = SelectedAlphabet.Name;
                    if (licenseHelper.ConvertToPlateNumber(LostLicense, out string licensePlate))
                    {
                        Request.LostPlateNumber = licensePlate;
                    }
                    else
                    {
                        return;
                    }

                    if (!evlRequestValidator.IsLostDetailValid(Request, out string message))
                    {
                        await dialogService.DisplayAlertAsync(string.Empty, translateService.Translate(message), ConstantStrings.Ok);
                        return;
                    }

                    await NavigationService.NavigateAsync(nameof(EvaluationRequestDescriptionView), new NavigationParameters
                    {
                        { nameof(Request), Request }
                    });
                }
            });
        }
Exemplo n.º 2
0
        public CreateInsurancePolicyViewModel(
            IUserDialogs userDialogs,
            HttpClient httpClient,
            IInitialDataService initialDataService,
            IODataClient oDataClient,
            IInsuranceValidator insuranceValidator,
            IPageDialogService dialogService,
            IPolicyService policyService,
            ILicenseHelper licenseHelper,
            IDateHelper dateHelper,
            ISanaapAppTranslateService translateService
            )
        {
            _oDataClient        = oDataClient;
            _userDialogs        = userDialogs;
            _initialDataService = initialDataService;
            _licenseHelper      = licenseHelper;
            _dialogService      = dialogService;
            _dateHelper         = dateHelper;

            foreach (InsuranceType item in (InsuranceType[])Enum.GetValues(typeof(InsuranceType)))
            {
                InsuranceTypes.Add(new InsuranceTypeItemSource
                {
                    InsuranceType     = item,
                    InsuranceTypeName = EnumHelper <InsuranceType> .GetDisplayValue(item)
                });
            }

            SelectedInsuranceType = InsuranceTypes[0];

            Submit = new BitDelegateCommand(async() =>
            {
                insuranceCancellationTokenSource?.Cancel();
                insuranceCancellationTokenSource = new CancellationTokenSource();

                using (_userDialogs.Loading(ConstantStrings.Loading, cancelText: ConstantStrings.Loading_Cancel, onCancel: insuranceCancellationTokenSource.Cancel))
                {
                    if (SelectedCar == null)
                    {
                        await dialogService.DisplayAlertAsync(ConstantStrings.Error, ConstantStrings.CarIsNull, ConstantStrings.Ok);
                        return;
                    }
                    if (SelectedInsurer == null)
                    {
                        await dialogService.DisplayAlertAsync(ConstantStrings.Error, ConstantStrings.InsurerIsNull, ConstantStrings.Ok);
                        return;
                    }
                    if (SelectedAlphabet == null)
                    {
                        await dialogService.DisplayAlertAsync(ConstantStrings.Error, ConstantStrings.NumberPlateIsNotValid, ConstantStrings.Ok);
                        return;
                    }
                    if (SelectedColor == null)
                    {
                        await dialogService.DisplayAlertAsync(ConstantStrings.Error, ConstantStrings.ColorIsNull, ConstantStrings.Ok);
                        return;
                    }

                    if (SelectedDate == null)
                    {
                        await dialogService.DisplayAlertAsync(ConstantStrings.Error, ConstantStrings.ExpirationDateIsNotValid, ConstantStrings.Ok);
                        return;
                    }

                    License.Alphabet = SelectedAlphabet.Name;

                    Policy.ExpirationDate = new DateTimeOffset((DateTime)SelectedDate, DateTimeOffset.Now.Offset);

                    if (licenseHelper.ConvertToPlateNumber(License, out string licensePlate))
                    {
                        Policy.PlateNumber = licensePlate;
                    }
                    else
                    {
                        return;
                    }

                    if (!insuranceValidator.IsValid(Policy, out string errorMessage))
                    {
                        await dialogService.DisplayAlertAsync(string.Empty, translateService.Translate(errorMessage), ConstantStrings.Ok);
                        return;
                    }

                    Policy.ColorId       = SelectedColor.PrmID;
                    Policy.CarId         = SelectedCar.PrmID;
                    Policy.InsuranceType = SelectedInsuranceType.InsuranceType;
                    Policy.InsurerId     = SelectedInsurer.ID;


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

                    using (userDialogs.Loading(ConstantStrings.Loading, cancelText: ConstantStrings.Loading_Cancel, onCancel: policyCancellationTokenSource.Cancel))
                    {
                        if (method == EditMethod.Create)
                        {
                            await policyService.AddAsync(Policy);
                        }
                        else
                        {
                            await policyService.UpdateAsync(Policy);
                        }
                    }
                }
                await dialogService.DisplayAlertAsync(string.Empty, ConstantStrings.SuccessfulProcess, ConstantStrings.Ok);

                await NavigationService.GoBackAsync();
            });


            SelectInsurer = new BitDelegateCommand <InsurersItemSource>(async(parameter) =>
            {
                foreach (InsurersItemSource insurer in Insurers)
                {
                    insurer.IsSelected = false;
                }

                parameter.IsSelected = true;

                SelectedInsurer = parameter;
            });
        }