public async Task <IActionResult> Create([FromBody] SetPolicyDTO policy, ApiVersion version) { //if (policy == null) return BadRequest(); //not needed as middleware only calls this action when policy is deserialized (possibly default); otherwise, it sends 400 (Bad Request) on its own (e.g. if malformed JSON payload). var svcRslt = await _policyService.AddAsync(policy); if (!svcRslt.Success) { return(BadRequest(svcRslt.Message)); } return(CreatedAtRoute("GetPolicyById", new { id = svcRslt.Value.Id, version = version.ToString() }, svcRslt.Value)); }
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; }); }