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 }
                    });
                }
            });
        }
Ejemplo n.º 2
0
        public EvaluationRequestDescriptionViewModel(
            IDateHelper dateHelper,
            ISanaapAppTranslateService translateService,
            IInitialDataService initialDataService,
            IPageDialogService dialogService,
            IEvlRequestValidator evlRequestValidator)
        {
            _dateHelper         = dateHelper;
            _dialogService      = dialogService;
            _initialDataService = initialDataService;

            GoToNextLevel = new BitDelegateCommand(async() =>
            {
                if (SelectedDate == null)
                {
                    await dialogService.DisplayAlertAsync(ConstantStrings.Error, ConstantStrings.AccidentDateIsNull, ConstantStrings.Ok);
                    return;
                }

                Request.AccidentDate = new DateTimeOffset((DateTime)SelectedDate, DateTimeOffset.Now.Offset);

                if (SelectedAccidentReason != null)
                {
                    Request.AccidentReason = SelectedAccidentReason.Name;
                }

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

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