public IPolicy GetPolicy(string nameOfInsuredObject, DateTime effectiveDate) { var policyId = IdGenerator.ConstructPolicyId(nameOfInsuredObject, effectiveDate); var policyModel = _policyRepository.Get(policyId); if (policyModel == null) { throw new NoSuchPolicyException(nameOfInsuredObject, effectiveDate); } var policyRisks = _riskRepository .GetAll() .Where(riskModel => riskModel.PolicyId == policyId) .Select(riskModel => new Risk { Name = riskModel.Name, YearlyPrice = riskModel.YearlyPrice }) .ToList(); decimal premium = _premiumCalculator.CalculatePremiumOfSoldPolicy(nameOfInsuredObject, effectiveDate); return(new Policy() { NameOfInsuredObject = policyModel.NameOfInsuredObject, ValidFrom = policyModel.ValidFrom, ValidTill = policyModel.ValidTill, InsuredRisks = policyRisks, Premium = premium }); }
public void AddRisk(string nameOfInsuredObject, Risk risk, DateTime validFrom, DateTime effectiveDate) { if (validFrom < effectiveDate) { throw new RiskValidityPeriodException(); } var policyId = IdGenerator.ConstructPolicyId(nameOfInsuredObject, effectiveDate); var policyModel = _policyRepository.Get(policyId); if (validFrom > policyModel.ValidTill) { throw new RiskValidityPeriodException(); } if (policyModel.InsuredRisks.Contains(risk)) { throw new DuplicateRiskException(risk.Name); } var riskId = IdGenerator.ConstructRiskId(risk.Name, policyModel.NameOfInsuredObject, effectiveDate); var riskModel = new RiskModel { Name = risk.Name, ValidFrom = validFrom, PolicyEffectiveDate = effectiveDate, PolicyId = policyId, Id = riskId, ValidTill = policyModel.ValidTill, YearlyPrice = risk.YearlyPrice }; _riskRepository.Add(riskModel); }
// GET: Clients/Create public ActionResult Create() { ViewBag.Policies = policyRepository.Get().Select(policy => new SelectListItem { Text = policy.Name, Value = policy.Id.ToString() }); return(View()); }
public Quote GetQuote(int policyId, IEnumerable <int> memberIds) { var existingMainPolicy = policyRepository.Get(policyId); var additionalMembers = memberRepository.Get(memberIds); // pass entities into Domain Service var multiMemberQuote = calculator.CalculatePremium(existingMainPolicy, additionalMembers); return(multiMemberQuote); }
public async Task <bool> Execute(UpdatePolicyParameter updatePolicyParameter) { if (updatePolicyParameter == null) { throw new ArgumentNullException(nameof(updatePolicyParameter)); } if (string.IsNullOrWhiteSpace(updatePolicyParameter.PolicyId)) { throw new BaseUmaException(ErrorCodes.InvalidRequestCode, string.Format(ErrorDescriptions.TheParameterNeedsToBeSpecified, "id")); } _umaServerEventSource.StartUpdateAuthorizationPolicy(JsonConvert.SerializeObject(updatePolicyParameter)); var policy = await _repositoryExceptionHelper.HandleException( string.Format(ErrorDescriptions.TheAuthorizationPolicyCannotBeRetrieved, updatePolicyParameter.PolicyId), () => _policyRepository.Get(updatePolicyParameter.PolicyId)); if (policy == null) { return(false); } foreach (var resourceSetId in policy.ResourceSetIds) { var resourceSet = await _resourceSetRepository.Get(resourceSetId).ConfigureAwait(false); if (updatePolicyParameter.Scopes.Any(r => !resourceSet.Scopes.Contains(r))) { throw new BaseUmaException(ErrorCodes.InvalidScope, ErrorDescriptions.OneOrMoreScopesDontBelongToAResourceSet); } } policy.Scopes = updatePolicyParameter.Scopes; policy.IsResourceOwnerConsentNeeded = updatePolicyParameter.IsResourceOwnerConsentNeeded; policy.Claims = new List <Claim>(); policy.Script = updatePolicyParameter.Script; if (updatePolicyParameter.Claims != null) { policy.Claims = updatePolicyParameter.Claims.Select(c => new Claim { Type = c.Type, Value = c.Value }).ToList(); } var result = await _repositoryExceptionHelper.HandleException( string.Format(ErrorDescriptions.TheAuthorizationPolicyCannotBeUpdated, updatePolicyParameter.PolicyId), () => _policyRepository.Update(policy)); _umaServerEventSource.FinishUpdateAuhthorizationPolicy(JsonConvert.SerializeObject(updatePolicyParameter)); return(result); }
public async Task <bool> Execute(UpdatePolicyParameter updatePolicyParameter) { if (updatePolicyParameter == null) { throw new ArgumentNullException(nameof(updatePolicyParameter)); } if (updatePolicyParameter.Rules == null || !updatePolicyParameter.Rules.Any()) { throw new BaseUmaException(ErrorCodes.InvalidRequestCode, string.Format(ErrorDescriptions.TheParameterNeedsToBeSpecified, Constants.AddPolicyParameterNames.Rules)); } var policy = await _repositoryExceptionHelper.HandleException( string.Format(ErrorDescriptions.TheAuthorizationPolicyCannotBeRetrieved, updatePolicyParameter.PolicyId), () => _policyRepository.Get(updatePolicyParameter.PolicyId)); if (policy == null) { return(false); } policy.Rules = new List <PolicyRule>(); foreach (var ruleParameter in updatePolicyParameter.Rules) { var claims = new List <Claim>(); if (ruleParameter.Claims != null) { claims = ruleParameter.Claims.Select(c => new Claim { Type = c.Type, Value = c.Value }).ToList(); } policy.Rules.Add(new PolicyRule { Id = ruleParameter.Id, ClientIdsAllowed = ruleParameter.ClientIdsAllowed, IsResourceOwnerConsentNeeded = ruleParameter.IsResourceOwnerConsentNeeded, Scopes = ruleParameter.Scopes, Script = ruleParameter.Script, Claims = claims, OpenIdProvider = ruleParameter.OpenIdProvider }); } return(await _repositoryExceptionHelper.HandleException( string.Format(ErrorDescriptions.TheAuthorizationPolicyCannotBeUpdated, updatePolicyParameter.PolicyId), () => _policyRepository.Update(policy))); }
public async Task <Policy> Execute(string policyId) { if (string.IsNullOrWhiteSpace(policyId)) { throw new ArgumentNullException(nameof(policyId)); } var policy = await _repositoryExceptionHelper.HandleException( string.Format(ErrorDescriptions.TheAuthorizationPolicyCannotBeRetrieved, policyId), () => _policyRepository.Get(policyId)); return(policy); }
public async Task <bool> Execute(AddResourceSetParameter addResourceSetParameter) { if (addResourceSetParameter == null) { throw new ArgumentNullException(nameof(addResourceSetParameter)); } if (string.IsNullOrWhiteSpace(addResourceSetParameter.PolicyId)) { throw new BaseUmaException(ErrorCodes.InvalidRequestCode, string.Format(ErrorDescriptions.TheParameterNeedsToBeSpecified, Constants.AddResourceSetParameterNames.PolicyId)); } if (addResourceSetParameter.ResourceSets == null || !addResourceSetParameter.ResourceSets.Any()) { throw new BaseUmaException(ErrorCodes.InvalidRequestCode, string.Format(ErrorDescriptions.TheParameterNeedsToBeSpecified, Constants.AddResourceSetParameterNames.ResourceSet)); } _umaServerEventSource.StartAddResourceToAuthorizationPolicy(addResourceSetParameter.PolicyId, string.Join(",", addResourceSetParameter.ResourceSets)); var policy = await _repositoryExceptionHelper.HandleException( string.Format(ErrorDescriptions.TheAuthorizationPolicyCannotBeRetrieved, addResourceSetParameter.PolicyId), () => _policyRepository.Get(addResourceSetParameter.PolicyId)); if (policy == null) { return(false); } foreach (var resourceSetId in addResourceSetParameter.ResourceSets) { var resourceSet = await _repositoryExceptionHelper.HandleException( string.Format(ErrorDescriptions.TheResourceSetCannotBeRetrieved, resourceSetId), () => _resourceSetRepository.Get(resourceSetId)); if (resourceSet == null) { throw new BaseUmaException(ErrorCodes.InvalidResourceSetId, string.Format(ErrorDescriptions.TheResourceSetDoesntExist, resourceSetId)); } } var resourceSetIds = policy.ResourceSetIds.ToList(); resourceSetIds.AddRange(addResourceSetParameter.ResourceSets); policy.ResourceSetIds = resourceSetIds; var result = await _repositoryExceptionHelper.HandleException( ErrorDescriptions.ThePolicyCannotBeUpdated, () => _policyRepository.Update(policy)); _umaServerEventSource.FinishAddResourceToAuthorizationPolicy(addResourceSetParameter.PolicyId, string.Join(",", addResourceSetParameter.ResourceSets)); return(result); }
public async Task <bool> Execute(string id, string resourceId) { if (string.IsNullOrWhiteSpace(id)) { throw new ArgumentNullException(nameof(id)); } if (string.IsNullOrWhiteSpace(resourceId)) { throw new ArgumentNullException(nameof(resourceId)); } _umaServerEventSource.StartRemoveResourceFromAuthorizationPolicy(id, resourceId); var policy = await _repositoryExceptionHelper.HandleException( string.Format(ErrorDescriptions.TheAuthorizationPolicyCannotBeRetrieved, id), () => _policyRepository.Get(id)); if (policy == null) { return(false); } var resourceSet = await _repositoryExceptionHelper.HandleException( string.Format(ErrorDescriptions.TheResourceSetCannotBeRetrieved, resourceId), () => _resourceSetRepository.Get(resourceId)); if (resourceSet == null) { throw new BaseUmaException(ErrorCodes.InvalidResourceSetId, string.Format(ErrorDescriptions.TheResourceSetDoesntExist, resourceId)); } if (policy.ResourceSetIds == null || !policy.ResourceSetIds.Contains(resourceId)) { throw new BaseUmaException(ErrorCodes.InvalidResourceSetId, ErrorDescriptions.ThePolicyDoesntContainResource); } var resourceSetIds = policy.ResourceSetIds.ToList(); resourceSetIds.Remove(resourceId); policy.ResourceSetIds = resourceSetIds; var result = await _policyRepository.Update(policy).ConfigureAwait(false); _umaServerEventSource.FinishRemoveResourceFromAuthorizationPolicy(id, resourceId); return(result); }
public async Task <bool> Execute(string policyId) { _umaServerEventSource.StartToRemoveAuthorizationPolicy(policyId); if (string.IsNullOrWhiteSpace(policyId)) { throw new ArgumentNullException(nameof(policyId)); } var policy = await _repositoryExceptionHelper.HandleException( string.Format(ErrorDescriptions.TheAuthorizationPolicyCannotBeRetrieved, policyId), () => _policyRepository.Get(policyId)); if (policy == null) { return(false); } await _repositoryExceptionHelper.HandleException( string.Format(ErrorDescriptions.TheAuthorizationPolicyCannotBeUpdated, policyId), () => _policyRepository.Delete(policyId)); _umaServerEventSource.FinishToRemoveAuthorizationPolicy(policyId); return(true); }
public ActionResult Get() { var model = _policyRepository.Get(); return(Ok(model)); }
// GET api/values public IList <Policy> Get() { return(policyRepository.Get()); }
public string Get() { return(JsonConvert.SerializeObject(_policyRepository.Get(), Formatting.Indented)); }
public async Task <bool> Execute(UpdatePolicyParameter updatePolicyParameter) { // Check the parameters if (updatePolicyParameter == null) { throw new ArgumentNullException(nameof(updatePolicyParameter)); } if (string.IsNullOrWhiteSpace(updatePolicyParameter.PolicyId)) { throw new BaseUmaException(ErrorCodes.InvalidRequestCode, string.Format(ErrorDescriptions.TheParameterNeedsToBeSpecified, "id")); } if (updatePolicyParameter.Rules == null || !updatePolicyParameter.Rules.Any()) { throw new BaseUmaException(ErrorCodes.InvalidRequestCode, string.Format(ErrorDescriptions.TheParameterNeedsToBeSpecified, Constants.AddPolicyParameterNames.Rules)); } _umaServerEventSource.StartUpdateAuthorizationPolicy(JsonConvert.SerializeObject(updatePolicyParameter)); // Check the authorization policy exists. var policy = await _repositoryExceptionHelper.HandleException( string.Format(ErrorDescriptions.TheAuthorizationPolicyCannotBeRetrieved, updatePolicyParameter.PolicyId), () => _policyRepository.Get(updatePolicyParameter.PolicyId)); if (policy == null) { return(false); } policy.Rules = new List <PolicyRule>(); // Check all the scopes are valid. foreach (var resourceSetId in policy.ResourceSetIds) { var resourceSet = await _resourceSetRepository.Get(resourceSetId); if (updatePolicyParameter.Rules.Any(r => r.Scopes != null && !r.Scopes.All(s => resourceSet.Scopes.Contains(s)))) { throw new BaseUmaException(ErrorCodes.InvalidScope, ErrorDescriptions.OneOrMoreScopesDontBelongToAResourceSet); } } // Update the authorization policy. foreach (var ruleParameter in updatePolicyParameter.Rules) { var claims = new List <Claim>(); if (ruleParameter.Claims != null) { claims = ruleParameter.Claims.Select(c => new Claim { Type = c.Type, Value = c.Value }).ToList(); } policy.Rules.Add(new PolicyRule { Id = ruleParameter.Id, ClientIdsAllowed = ruleParameter.ClientIdsAllowed, IsResourceOwnerConsentNeeded = ruleParameter.IsResourceOwnerConsentNeeded, Scopes = ruleParameter.Scopes, Script = ruleParameter.Script, Claims = claims, OpenIdProvider = ruleParameter.OpenIdProvider }); } var result = await _repositoryExceptionHelper.HandleException( string.Format(ErrorDescriptions.TheAuthorizationPolicyCannotBeUpdated, updatePolicyParameter.PolicyId), () => _policyRepository.Update(policy)); _umaServerEventSource.FinishUpdateAuhthorizationPolicy(JsonConvert.SerializeObject(updatePolicyParameter)); return(result); }
public async Task <IEnumerable <Policy> > Get() { return(await _repository.Get()); }
public IEnumerable <Policy> Get() { return(_policyRepository.Get().OrderBy(policy => policy.PolicyNumber).ToList <Policy>()); }
// GET: Policies public ActionResult Index() { var policies = policyRepository.Get(); return(View(policies)); }
public IActionResult Get() { return(Ok(_policyRepository.Get())); }
public IEnumerable <Policy> Get() { return(_policyRepository.Get()); }