public async Task <bool> Post([FromBody] PolicyQuoteViewModel policyquote) { try { var policy = new PolicyArtifact { Number = policyquote.Number, CreationDate = DateTime.Now, Price = policyquote.Price, IsActive = policyquote.IsActive, Id = Guid.NewGuid() }; return(await _service.AddPolicyQuote(policy)); } catch (Exception ex) { throw; } }
public async Task <bool> AddPolicyQuote(PolicyArtifact policy) { try { var policies = await _stateManager.GetOrAddAsync <IReliableDictionary <Guid, PolicyArtifact> >("policyquotes"); using (var transaction = _stateManager.CreateTransaction()) { await policies.AddOrUpdateAsync(transaction, policy.Id, policy, (id, value) => policy); await transaction.CommitAsync(); } return(true); } catch (Exception) { return(false); } }
public async Task <CheckoutSummary> CheckoutQuote(string userId) { var result = new CheckoutSummary(); result.Date = DateTime.UtcNow; result.Artifacts = new List <CheckoutArtifact>(); //call user actor to get the basket IProfile userActor = GetUserActor(userId); Dictionary <Guid, int> basket = await userActor.GetQuote(); //get catalog client IPolicyArtifactService catalogService = GetPolicyArtifactService(); //constuct CheckoutProduct items by calling to the catalog foreach (KeyValuePair <Guid, int> basketLine in basket) { PolicyArtifact artifact = await catalogService.GetPolicyQuoteById(basketLine.Key); var checkoutProduct = new CheckoutArtifact { Artifact = artifact, Price = artifact.Price, Quantity = basketLine.Value }; result.Artifacts.Add(checkoutProduct); } //generate total price result.TotalPrice = result.Artifacts.Sum(p => p.Price); //clear user basket await userActor.ClearQuote(); await AddToHistory(result); return(result); }
public async Task <bool> AddPolicyQuote(PolicyArtifact policy) => await _repository.AddPolicyQuote(policy);