public void DeletePolicy(PolicyDto policeDto) { var policy = convert(policeDto); _context.Policy.Remove(policy); _context.SaveChanges(); }
private void ExecuteChoosePolicyCommand(PolicyDto policy) { Func <OrderDto> func = () => { IsBusy = true; OrderDto result = new OrderDto(); CommunicateManager.Invoke <IOrderService>(service => { result = service.ChoosePolicy(policy, OrderId); if (result.OrderSource == EnumOrderSource.PnrContentImport && !result.IsAuthSuc) { UIManager.ShowMessage(result.AuthInfo); } }, UIManager.ShowErr); return(result); }; Task.Factory.StartNew <OrderDto>(func).ContinueWith((task) => { IsBusy = false; var model = task.Result as OrderDto; if (String.IsNullOrEmpty(model.OrderId)) { return; } //LocalUIManager.ShowPolicy(model.OrderId, null); LocalUIManager.ShowPayInsuranceAndRefund(model.OrderId, p => Module.PluginService.Run(Main.ProjectCode, Main.OrderQueryCode)); }); }
public async Task <Policy> GetPolicyAsync(string policyId) { var functionName = "policies"; var func = _contract.GetFunction(functionName); var policyDto = new PolicyDto(); try { policyDto = await func.CallDeserializingToObjectAsync <PolicyDto>(policyId); } catch (ArgumentNullException e) // catching this error because after successful transaction is time frame while blockchain data is not updated and returns unknown result. We are getting: Value cannot be null. Parameter name: value { _logger.Warn($"Cant deserialize contract response. functionName: {functionName}, policyId: {policyId}", e); } var result = new Policy(); result.Id = policyId; result.StartUtc = DateTimeHelper.UnixTimeStampToDateTime(policyDto.StartUtc); result.EndUtc = DateTimeHelper.UnixTimeStampToDateTime(policyDto.EndUtc); result.PayoutUtc = DateTimeHelper.UnixTimeStampToDateTime(policyDto.PayoutUtc); result.IsCanceled = policyDto.IsCanceled == 1; result.Premium = Web3.Convert.FromWei(policyDto.Premium); result.CalculatedPayout = Web3.Convert.FromWei(policyDto.CalculatedPayout); result.Properties = policyDto.Properties; result.Payout = Web3.Convert.FromWei(policyDto.Payout); result.ClaimProperties = policyDto.ClaimProperties; return(result); }
/// <summary> /// Handles the SaveChanges event of the EditSaveControl control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param> void EditSaveControl_SaveChanges(object sender, SaveControl.SaveEventArgs e) { // Validate form if (!this.Page.IsValid) { e.RunScript = false; return; } PolicyDto policy = (PolicyDto)Session[_PolicyDtoEditSessionKey]; if (PolicyId > 0 && policy == null) { policy = PolicyManager.GetPolicyDto(PolicyId); } else if (PolicyId == 0) { policy = new PolicyDto(); } IDictionary context = new ListDictionary(); context.Add(_PolicyDtoString, policy); ViewControl.SaveChanges(context); if (policy.HasChanges()) { PolicyManager.SavePolicy(policy); } // we don't need to store Dto in session any more Session.Remove(_PolicyDtoEditSessionKey); }
public static PolicyViewModel MapFromDto(this PolicyDto policyDto) { PolicyViewModel policyViewModel = new PolicyViewModel(); policyViewModel.Id = policyDto.Id; policyViewModel.Category = policyDto.Category.MapFromDto(); policyViewModel.SubCategory = policyDto.SubCategory.MapFromDto(); policyViewModel.Province = policyDto.Province.MapFromDto(); policyViewModel.City = policyDto.City.MapFromDto(); policyViewModel.CreateUser = policyDto.CreateUser.MapFromDto(); //policyViewModel.CreateDate = policyDto.CreateDate; policyViewModel.CreateDateText = policyDto.CreateDate.ToString("dd/MM/yyyy"); //policyViewModel.EditDate = policyDto.EditDate; policyViewModel.EditDateText = policyDto.EditDate.ToString("dd/MM/yyyy"); policyViewModel.Subject = policyDto.Subject; policyViewModel.Description = policyDto.Description; policyViewModel.NegotiableInd = policyDto.NegotiableInd; policyViewModel.OfferType = policyDto.OfferType; policyViewModel.Price = Converter.NullableTypeToString(policyDto.Price); policyViewModel.CrudOperation = CrudOperation.UPDATE; if (policyDto.PolicyImages != null && policyDto.PolicyImages.Count > 0) { policyDto.PolicyImages.ForEach(t => policyViewModel.PolicyImages.Add(t.MapFromDto())); } if (policyDto.PolicySubCategoryAdditionalFields != null && policyDto.PolicySubCategoryAdditionalFields.Count > 0) { policyDto.PolicySubCategoryAdditionalFields.ForEach(t => policyViewModel.PolicySubCategoryAdditionalFields.Add(t.MapFromDto())); } return(policyViewModel); }
public void UpdatePolicy(PolicyDto policeDto) { var policy = convert(policeDto); _context.Entry(policy).State = EntityState.Modified; _context.SaveChanges(); }
/// <summary> /// Gets the Policy dto, checks permissions and caches results. /// </summary> /// <param name="policyId">The policy id.</param> /// <returns></returns> public static PolicyDto GetPolicyDto(int policyId) { // Assign new cache key, specific for site guid and response groups requested //string cacheKey = MarketingCache.CreateCacheKey("Policy", PolicyId.ToString()); PolicyDto dto = null; // check cache first //object cachedObject = MarketingCache.Get(cacheKey); //if (cachedObject != null) // dto = (PolicyDto)cachedObject; // Load the object if (dto == null) { PolicyAdmin Policy = new PolicyAdmin(); Policy.Load(policyId); dto = Policy.CurrentDto; // Insert to the cache collection //MarketingCache.Insert(cacheKey, dto, MarketingConfiguration.CacheConfig.PolicyCollectionTimeout); } dto.AcceptChanges(); return(dto); }
/// <summary> /// Saves the policy. /// </summary> /// <param name="dto">The dto.</param> public static void SavePolicy(PolicyDto dto) { if (dto == null) { throw new ArgumentNullException("dto", String.Format("PolicyDto can not be null")); } //TODO: check concurrency when updating the records //TODO: need to check security roles here, // The procedure will be following: // 1. Retrieve the record from the database for each category that is about to be updated // 2. Check Write permissions (if failed generate the error and exit) // 3. Otherwise proceed to update // Continue with security checks and other operations /* * foreach (PolicyDto.PolicyRow row in dto.Policy.Rows) * { * // Check Security * IDataReader reader = DataHelper.CreateDataReader(dto.PolicySecurity, String.Format("PolicyId = -1 or PolicyId = {0}", row.PolicyId)); * PermissionRecordSet recordSet = new PermissionRecordSet(PermissionHelper.ConvertReaderToRecords(reader)); * if (!PermissionManager.CheckPermission(PolicyScope.Policy, Permission.Read, recordSet)) * { * row.Delete(); * continue; * } * } * */ PolicyAdmin admin = new PolicyAdmin(dto); admin.Save(); }
/// <summary> /// Loads the context. /// </summary> private void LoadContext() { if (PolicyId > 0) { PolicyDto policy = null; if (!this.IsPostBack && (!this.Request.QueryString.ToString().Contains("Callback=yes"))) // load fresh on initial load { policy = LoadFresh(); } else // load from session { policy = (PolicyDto)Session[_PolicyDtoEditSessionKey]; if (policy == null) { policy = LoadFresh(); } } // Put a dictionary key that can be used by other tabs IDictionary dic = new ListDictionary(); dic.Add(_PolicyDtoString, policy); // Call tabs load context ViewControl.LoadContext(dic); _Policy = policy; } }
public void Setup() { var mock = new Mock <IPolicyService>(); listPolicies = new List <PolicyDto>(); policyDto = new PolicyDto(ResourceUnitTests.policyid2, Convert.ToDecimal(ResourceUnitTests.amountInsured2), ResourceUnitTests.policyEmail2, Convert.ToDateTime(ResourceUnitTests.policyDateTime2), true, ResourceUnitTests.policyIdClient2 ); for (var i = 0; i < 91; i++) { listPolicies.Add(policyDto); } mock.Setup(x => x.GetPoliciesByUserName(ResourceUnitTests.nameOfUserTest1)) .Returns(listPolicies); mockObject = mock.Object; }
public IHttpActionResult Post(PolicyDto policyDto) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } PolicyDto policyDtoAdded = new PolicyDto(); try { policyDtoAdded = policyService.Add(policyDto); } #region Exceptions & Log catch (VuelingException e) { Log.Error(ResourceApi.AddError + e.InnerException + ResourceApi.ErrorLogSeparation + e.Message + ResourceApi.ErrorLogSeparation + e.Data + ResourceApi.ErrorLogSeparation + e.StackTrace); var response = new HttpResponseMessage(HttpStatusCode.NotFound); throw new HttpResponseException(response); #endregion } return(CreatedAtRoute(ResourceApi.HttpRoute, new { id = policyDtoAdded.Id }, policyDtoAdded)); }
private async Task SetupHttpClientAsync(RelayCallDto relayCallDto) { PolicyDto policyDto = relayCallDto.HybridConnection.PolicyDtos.First(x => x.PolicyType == PolicyClaim.Send); var tokenProvider = TokenProvider.CreateSharedAccessSignatureTokenProvider(policyDto.PolicyName, policyDto.PolicyKey); var token = (await tokenProvider.GetTokenAsync(relayCallDto.HybridConnection.HybridConnectionUrl.AbsoluteUri, TimeSpan.FromHours(1))).TokenString; _httpClient.DefaultRequestHeaders.Add("ServiceBusAuthorization", token); }
/// <summary> /// Initializes a new instance of the <see cref="MarketingHelper"/> class. /// </summary> /// <param name="campaigns">The campaigns.</param> /// <param name="expressions">The expressions.</param> /// <param name="policies">The policies.</param> /// <param name="promotions">The promotions.</param> /// <param name="segments">The segments.</param> public MarketingHelper(CampaignDto campaigns, ExpressionDto expressions, PolicyDto policies, PromotionDto promotions, SegmentDto segments) { _Campaigns = campaigns; _Expressions = expressions; _Policies = policies; _Promotions = promotions; _Segments = segments; }
public IEnumerable <Policy> GetAllProducts() { var policyDto = new PolicyDto { Id = 1, LastUpdated = DateTime.Now, PolicyNo = "PN1", Firstname = "Ian", Surname = "Baker" }; Policy policies = mapper.Map <PolicyDto, Policy>(policyDto); yield return(policies); }
public PolicyDto InsertPolicy(PolicyDto policeDto) { var policy = convert(policeDto); _context.Policy.Add(policy); _context.SaveChanges(); return(convertDto(policy)); }
/// <summary> /// Loads the fresh. /// </summary> /// <returns></returns> private PolicyDto LoadFresh() { PolicyDto policy = PolicyManager.GetPolicyDto(PolicyId); // persist in session Session[_PolicyDtoEditSessionKey] = policy; return(policy); }
public static async void UpdatePolicyDetails(PolicyDto policyDetails) { CustomerPolicy.Instance.CustomerId = Convert.ToInt32(ThisOrThat(CreateCustomer.Instance.CustomerId.ToString(), policyDetails.customerId)); //CustomerPolicy.Instance.PolicyNumber = Convert.ToInt32(ThisOrThat(CreateCustomer.Instance.PolicyNumber.ToString(), policyDetails.policyNumber)); CustomerPolicy.Instance.PolicyEffectiveDate = ThisOrThat(CustomerPolicy.Instance.PolicyEffectiveDate, policyDetails.policyEffectiveDate); CustomerPolicy.Instance.PolicyExpiryDate = ThisOrThat(CustomerPolicy.Instance.PolicyExpiryDate, policyDetails.policyExpiryDate); CustomerPolicy.Instance.PaymentOption = ThisOrThat(CustomerPolicy.Instance.PaymentOption, policyDetails.paymentOption); CustomerPolicy.Instance.TotalAmount = Convert.ToDouble(ThisOrThat(CustomerPolicy.Instance.TotalAmount.ToString(), policyDetails.totalAmount)); CustomerPolicy.Instance.Active = ThisOrThat(CustomerPolicy.Instance.Active, policyDetails.active); }
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) { if (value is PolicyDto) { PolicyDto model = (PolicyDto)value; //return model.TicketPrice - model.Commission; return(model.PayMoney); } return(value); }
private Policy convert(PolicyDto policeDto) { return(new Policy { Id = policeDto.Id, PolicyId = policeDto.PolicyId, Document = policeDto.Document, Board = policeDto.Board, Price = policeDto.Price }); }
public async Task <IActionResult> UpdatePolicy(int id, PolicyDto policyForUpdateDto) { var policyFromRepo = await _repo.GetPolicy(id); _mapper.Map(policyForUpdateDto, policyFromRepo); if (await _repo.SaveAll()) { return(Ok()); } throw new Exception($"updating policy {id} failed on save"); }
public IHttpActionResult CreatePolicy(PolicyDto policyDto) { if (!ModelState.IsValid) { return(BadRequest()); } var policy = Mapper.Map <PolicyDto, Policy>(policyDto); policy.Id = policyRepository.CreatePolicy(policy); return(Ok(policy.Id)); }
public PolicyDto GetAsync(string userId) { PolicyDto policy = null; var request = new RestRequest("/Identity/" + userId, DataFormat.Json); var result = _client.GetAsync <PolicyDto>(request); result.Wait(); if (result.IsCompletedSuccessfully) { policy = result.Result; } return(policy); }
public async Task <bool> SavePolicy(PolicyDto dto) { try { Policy Data = Mapper.Map <PolicyDto, Policy>(dto); context.Policy.Add(Data); await context.SaveChangesAsync(); return(true); } catch (Exception) { throw; } }
/// <summary> /// 将源值转换为绑定源的值。数据绑定引擎在将值从绑定源传播给绑定目标时,调用此方法。 /// </summary> /// <param name="values"><see cref="T:System.Windows.Data.MultiBinding" /> 中源绑定生成的值的数组。值 <see cref="F:System.Windows.DependencyProperty.UnsetValue" /> 表示源绑定没有要提供以进行转换的值。</param> /// <param name="targetType">绑定目标属性的类型。</param> /// <param name="parameter">要使用的转换器参数。</param> /// <param name="culture">要用在转换器中的区域性。</param> /// <returns> /// 转换后的值。如果该方法返回 null,则使用有效的 null 值。<see cref="T:System.Windows.DependencyProperty" />.<see cref="F:System.Windows.DependencyProperty.UnsetValue" /> 的返回值表示转换器没有生成任何值,且绑定将使用 <see cref="P:System.Windows.Data.BindingBase.FallbackValue" />(如果可用),否则将使用默认值。<see cref="T:System.Windows.Data.Binding" />.<see cref="F:System.Windows.Data.Binding.DoNothing" /> 的返回值表示绑定不传输值,或不使用 <see cref="P:System.Windows.Data.BindingBase.FallbackValue" /> 或默认值。 /// </returns> /// <exception cref="System.NotImplementedException"></exception> public object Convert(object[] values, Type targetType, object parameter, System.Globalization.CultureInfo culture) { if (values == null || values.Length < 2) { return(null); } if (values[0] is PolicyDto && values[1] is decimal) { PolicyDto model = values[0] as PolicyDto; var result = (decimal)values[1] * model.Point / 100; return(result.ToString("f2")); } return(0);//方便blend设计样式 }
public async Task <IActionResult> CreatePolicy(PolicyDto policyForCreateDto) { var policyToCreate = new Policy(); //Auto maping Dto to entity _mapper.Map(policyForCreateDto, policyToCreate); _repo.Add(policyToCreate); if (await _repo.SaveAll()) { return(Ok()); } throw new Exception($"Creating policy {policyForCreateDto.Name} failed on save"); }
public IHttpActionResult CreatePolicy(PolicyDto customerDto) { if (!ModelState.IsValid) { return(BadRequest()); } var policy = Mapper.Map <PolicyDto, Policy>(customerDto); _context.Policies.Add(policy); _context.SaveChanges(); customerDto.Id = policy.Id; return(Created(new Uri(Request.RequestUri + "/" + policy.Id), customerDto)); }
public async Task <bool> UpdatePolicy(PolicyDto dto) { try { Policy Data = Mapper.Map <PolicyDto, Policy>(dto); context.Entry(Data).State = System.Data.Entity.EntityState.Modified; await context.SaveChangesAsync(); return(true); } catch (Exception) { throw; } }
async Task <HybridConnectionDto> IRelayAzureManagementService.CreateHybridConnection(CreateRelayDto createRelayStorageDto) { if (createRelayStorageDto is null) { throw new ArgumentNullException(nameof(createRelayStorageDto)); } Uri hybridConnectionUrl = await _relayManagementApiClient.CreateHybridConnectionAsync(createRelayStorageDto.TenantId); PolicyDto policySendKey = await _relayManagementApiClient.CreatePolicykeyAsync(createRelayStorageDto.TenantId, PolicyClaim.Send); PolicyDto policyListenKey = await _relayManagementApiClient.CreatePolicykeyAsync(createRelayStorageDto.TenantId, PolicyClaim.Listen); return(new HybridConnectionDto(hybridConnectionUrl, new PolicyDto[] { policySendKey, policyListenKey })); }
public static void MapToDto(this PolicyDto policyDto, PolicyViewModel policyViewModel) { policyDto.Id = policyViewModel.Id == null ? int.MinValue : policyViewModel.Id.Value; policyDto.Category.MapToDto(policyViewModel.Category); policyDto.SubCategory.MapToDto(policyViewModel.SubCategory); policyDto.Province.MapToDto(policyViewModel.Province); policyDto.City.MapToDto(policyViewModel.City); if (policyViewModel.CrudOperation == CrudOperation.CREATE) { if (policyViewModel.RegisterUser != null) { policyDto.CreateUser.MapToDto(policyViewModel.RegisterUser); } else { policyDto.CreateUser = new UserDto { Id = policyViewModel.CreateUserId.Value }; } } else { policyDto.CreateUser.MapToDto(policyViewModel.CreateUser); } foreach (PolicyImageViewModel policyImageViewModel in policyViewModel.PolicyImages) { PolicyImageDto policyImage = new PolicyImageDto(); policyImage.MapToDto(policyImageViewModel); policyDto.PolicyImages.Add(policyImage); } foreach (PolicySubCategoryAdditionalFieldViewModel policySubCategoryAdditionalFieldViewModel in policyViewModel.PolicySubCategoryAdditionalFields) { PolicySubCategoryAdditionalFieldDto policySubCategoryAdditionalFieldDto = new PolicySubCategoryAdditionalFieldDto(); policySubCategoryAdditionalFieldDto.MapToDto(policySubCategoryAdditionalFieldViewModel); policyDto.PolicySubCategoryAdditionalFields.Add(policySubCategoryAdditionalFieldDto); } policyDto.Subject = policyViewModel.Subject; policyDto.Description = policyViewModel.Description; policyDto.NegotiableInd = policyViewModel.NegotiableInd; policyDto.OfferType = policyViewModel.OfferType; policyDto.Price = Converter.StringToDecimal(policyViewModel.Price); }
public IHttpActionResult CreateCoverageByPolicy(PolicyDto policyDto) { var policy = Mapper.Map <PolicyDto, Policy>(policyDto); var typeOfRisk = typeOfRiskRepository.GetTypeOfRisk(policy.TypeOfRiskId); policy.TypeOfRisk = typeOfRisk; var coverageByPolicyNoCreationReason = policyBL.CoverageByPolicyCanBeCreated(policy); if (coverageByPolicyNoCreationReason != "") { return(BadRequest(coverageByPolicyNoCreationReason)); } return(Ok()); }