public static InsuranceTypes CombineIntoSingle(ICollection <InsuranceTypes> value) { InsuranceTypes temp = InsuranceTypes.Unspecified; foreach (var type in value) { temp |= type; } return(temp); }
public override async Task OnNavigatedToAsync(INavigationParameters parameters) { insuranceCancellationTokenSource?.Cancel(); insuranceCancellationTokenSource = new CancellationTokenSource(); using (_userDialogs.Loading(ConstantStrings.Loading, cancelText: ConstantStrings.Loading_Cancel, onCancel: insuranceCancellationTokenSource.Cancel)) { await syncData(); parameters.TryGetValue("Method", out method); if (parameters.TryGetValue("Policy", out InsurancePolicyDto policy)) { Policy = new InsurancePolicyDto { CarId = policy.CarId, ChasisNo = policy.ChasisNo, ColorId = policy.ColorId, CustomerId = policy.CustomerId, Id = policy.Id, InsuranceType = policy.InsuranceType, InsurerId = policy.InsurerId, InsurerNo = policy.InsurerNo, ExpirationDate = policy.ExpirationDate, PlateNumber = policy.PlateNumber, VIN = policy.VIN }; SelectedDate = Policy.ExpirationDate.DateTime; SelectedColor = Colors.FirstOrDefault(c => c.PrmID == Policy.ColorId); SelectedCar = Cars.FirstOrDefault(c => c.PrmID == Policy.CarId); SelectedInsuranceType = InsuranceTypes.FirstOrDefault(c => c.InsuranceType == Policy.InsuranceType); SelectedInsurer = Insurers.FirstOrDefault(c => c.ID == Policy.InsurerId); License = _licenseHelper.ConvertToItemSource(policy.PlateNumber); SelectedAlphabet = Alphabets.FirstOrDefault(a => a.Name == License.Alphabet); } } }
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; }); }