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 } }); } }); }
public LoginViewModel( ISecurityService securityService, ISanaapAppLoginValidator loginValidator, IPageDialogService pageDialogService, ISanaapAppTranslateService translateService, IUserDialogs userDialogs) { Login = new BitDelegateCommand(async() => { registerCancellationTokenSource?.Cancel(); registerCancellationTokenSource = new CancellationTokenSource(); using (userDialogs.Loading(ConstantStrings.Loading, cancelText: ConstantStrings.Loading_Cancel, onCancel: registerCancellationTokenSource.Cancel)) { if (!loginValidator.IsValid(NationalCode, Mobile, out string errorMessage)) { await pageDialogService.DisplayAlertAsync("", translateService.Translate(errorMessage), "باشه"); return; } try { await securityService.LoginWithCredentials(NationalCode, Mobile, "SanaapResOwner", "secret"); await NavigationService.NavigateAsync($"/{nameof(NavigationPage)}/{nameof(MainMenuView)}"); } catch (Exception ex) { if (ex.Message.Contains("CustomerCouldNotBeFound")) { await pageDialogService.DisplayAlertAsync("", "کاربری با این مشخصات یافت نشد", "باشه"); } else if (translateService.Translate(ex.GetMessage(), out string translateErrorMessage)) { await pageDialogService.DisplayAlertAsync("", translateErrorMessage, "باشه"); } else { string error = ex.ToString(); throw; } } } }); Register = new BitDelegateCommand(async() => { await NavigationService.NavigateAsync(nameof(RegisterView)); }); }
public LoginViewModel(INavigationService navigationService, ISecurityService securityService, ISanaapOperatorAppLoginValidator loginValidator, IPageDialogService pageDialogService, ISanaapAppTranslateService translateService, IConnectivity connectivity) { Login = new BitDelegateCommand(async() => { IsBusy = true; try { if (!loginValidator.IsValid(UserName, Password, out string errorMessage)) { await pageDialogService.DisplayAlertAsync("", translateService.Translate(errorMessage), "باشه"); return; } if (connectivity.IsConnected == false) { await pageDialogService.DisplayAlertAsync("", "ارتباط با اینترنت برقرار نیست", "باشه"); return; } try { await securityService.LoginWithCredentials(UserName, Password, "SanaapOperatorAppResOwner", "secret"); await navigationService.NavigateAsync("Menu/Nav/Main"); } catch (Exception ex) { Crashes.TrackError(ex, new Dictionary <string, string> { { "Message", ex.GetMessage() }, { "ViewModel", nameof(LoginViewModel) } }); } } finally { IsBusy = false; } }); }
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(); }); }
public RegisterViewModel( IODataClient oDataClient, ICustomerValidator customerValidator, IPageDialogService pageDialogService, ISecurityService securityService, ISanaapAppTranslateService translateService, IUserDialogs userDialogs) { Register = new BitDelegateCommand(async() => { registerCancellationTokenSource?.Cancel(); registerCancellationTokenSource = new CancellationTokenSource(); using (userDialogs.Loading(ConstantStrings.Loading, cancelText: ConstantStrings.Loading_Cancel, onCancel: registerCancellationTokenSource.Cancel)) { if (!customerValidator.IsValid(Customer, out string errorMessage)) { await pageDialogService.DisplayAlertAsync("", translateService.Translate(errorMessage), "باشه"); return; } try { Customer = await oDataClient.For <CustomerDto>("Customers") .Action("RegisterCustomer") .Set(new { customer = Customer }) .ExecuteAsSingleAsync(registerCancellationTokenSource.Token); IsEnterDataVisible = false; IsVerifySectionVisible = true; startVerifyTimer(); } catch (Exception ex) { if (translateService.Translate(ex.GetMessage(), out string translateErrorMessage)) { await pageDialogService.DisplayAlertAsync("", translateErrorMessage, "باشه"); } else { throw; } } } }); SendVerificationCodeAgain = new BitDelegateCommand(async() => { registerCancellationTokenSource?.Cancel(); registerCancellationTokenSource = new CancellationTokenSource(); using (userDialogs.Loading(ConstantStrings.Loading, cancelText: ConstantStrings.Loading_Cancel, onCancel: registerCancellationTokenSource.Cancel)) { try { Customer = await oDataClient.For <CustomerDto>("Customers") .Action("SendVerificationCodeAgain") .Set(new { customer = Customer }) .ExecuteAsSingleAsync(registerCancellationTokenSource.Token); startVerifyTimer(); } catch (Exception ex) { if (translateService.Translate(ex.GetMessage(), out string translateErrorMessage)) { await pageDialogService.DisplayAlertAsync("", translateErrorMessage, "باشه"); } else { throw; } } } }, () => TimerValue == 0); SendVerificationCodeAgain.ObservesProperty(() => TimerValue); VerifyCode = new BitDelegateCommand(async() => { if (VerificationCode == Customer.VerifyCode) { IsVerifySectionVisible = false; await securityService.LoginWithCredentials(Customer.NationalCode, Customer.Mobile, "SanaapResOwner", "secret", cancellationToken: registerCancellationTokenSource.Token); await NavigationService.NavigateAsync($"/{nameof(NavigationPage)}/{nameof(MainMenuView)}"); } else { await pageDialogService.DisplayAlertAsync(ConstantStrings.Error, ConstantStrings.InvalidVerifyCode, ConstantStrings.Ok); VerificationCode = string.Empty; } }); }
public CommentListViewModel(IODataClient oDataClient, ICommentValidator commentValidator, ISanaapAppTranslateService translateService, IUserDialogs userDialogs, IEventAggregator eventAggregator, ICommentService commentService, IPageDialogService pageDialogService) { _oDataClient = oDataClient; _userDialogs = userDialogs; _commentService = commentService; CommentTypes = EnumHelper <CommentType> .GetDisplayValues(CommentType.Complaint); SelectedCommentType = CommentTypes[1]; CreateComment = new BitDelegateCommand(async() => { submitCancellationTokenSource?.Cancel(); submitCancellationTokenSource = new CancellationTokenSource(); using (userDialogs.Loading(ConstantStrings.Loading, cancelText: ConstantStrings.Loading_Cancel, onCancel: submitCancellationTokenSource.Cancel)) { Comment.CommentType = (CommentType)CommentTypes.IndexOf(SelectedCommentType); if (!commentValidator.IsValid(Comment, out string errorMessage)) { await pageDialogService.DisplayAlertAsync(string.Empty, translateService.Translate(errorMessage), ConstantStrings.Ok); return; } Comment = await commentService.AddAsync(Comment); await pageDialogService.DisplayAlertAsync(string.Empty, ConstantStrings.SuccessfulProcess, ConstantStrings.Ok); Comment = new CommentDto(); eventAggregator.GetEvent <OpenCreateCommentPopupEvent>().Publish(new OpenCreateCommentPopupEvent()); await loadComments(); } }); ShowComment = new BitDelegateCommand <CommentItemSource>(async(comment) => { if (string.IsNullOrEmpty(comment.Answer)) { comment.Answer = ConstantStrings.ResponseNotFoundFromSupport; } await NavigationService.NavigateAsync(nameof(CommentAnswerPopupView), new NavigationParameters { { nameof(Comment), comment } }); }); OpenCreatePopup = new BitDelegateCommand(async() => { eventAggregator.GetEvent <OpenCreateCommentPopupEvent>().Publish(new OpenCreateCommentPopupEvent()); }); }
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; }); }