public async Task <ApiResponse <PolicyCoverageDto, UpdatePolicyCoverageStatus> > UpdatePolicyCoverageAsync(UpdatePolicyCoveragePayload payload) { StartLog(); ApiResponse <PolicyCoverageDto, UpdatePolicyCoverageStatus> response = null; if (!Validate(payload, out string message, out string property)) { response = Error <UpdatePolicyCoverageStatus>(message, property); EndLog(); return(response); } var policyCoverage = await GetPolicyCoverageById(payload.PolicyCoverageId); if (policyCoverage == null) { response = Error(UpdatePolicyCoverageStatus.PolicyCoverageIdNotFound); EndLog(); return(response); } var usage = await _clientPolicySvc.CheckPolicyUsageAsync( new CheckPolicyUsagePayload { PolicyId = policyCoverage.PolicyId }); if (usage.Data.IsInUse) { response = Error(UpdatePolicyCoverageStatus.PolicyInUse); EndLog(); return(response); } var policy = await _policyService.GetPolicyAsync( new GetPolicyPayload { PolicyId = policyCoverage.PolicyId }); if (payload.Percentage > policy.Data.MaxCoverage) { response = new ApiResponse <PolicyCoverageDto, UpdatePolicyCoverageStatus> { Message = InsuranceResources.Get("MaxCoverageExceeded", policy.Data.MaxCoverage), MessageType = ApiMessageType.Error, StatusCode = UpdatePolicyCoverageStatus.MaxCoverageExceeded }; EndLog(); return(response); } policyCoverage.Percentage = payload.Percentage; await SaveAsync(ApiChangeAction.Update, policyCoverage); response = Ok <PolicyCoverageDto, UpdatePolicyCoverageStatus>(policyCoverage, UpdatePolicyCoverageStatus.UpdatePolicyCoverageOk); EndLog(); return(response); }
public async Task UpdatePolicyCoverageOk() { var PolicyCoverageSvc = GetService <IPolicyCoverageService>(); var payload = GetValidPayload(); var response = await PolicyCoverageSvc.UpdatePolicyCoverageAsync(payload); var expectedMsg = InsuranceResources.Get("UpdatePolicyCoverageOk"); Assert.AreEqual(payload.PolicyCoverageId, response.Data.PolicyCoverageId); Assert.AreEqual(payload.Percentage, response.Data.Percentage); Assert.AreNotEqual(null, response.Data.CoverageDescription); Assert.AreEqual(expectedMsg, response.Message); Assert.AreEqual(ApiMessageType.Success, response.MessageType); Assert.AreEqual(UpdatePolicyCoverageStatus.UpdatePolicyCoverageOk, response.StatusCode); Assert.AreEqual(true, response.Success); }
public async Task CreateClientPolicyOk() { var clientPolicySvc = GetService <IClientPolicyService>(); var payload = GetValidPayload(); var response = await clientPolicySvc.CreateClientPolicyAsync(payload); var expectedMsg = InsuranceResources.Get("CreateClientPolicyOk"); Assert.AreNotEqual(0, response.Data.ClientPolicyId); Assert.AreNotEqual(null, response.Data.PolicyName); Assert.AreNotEqual(null, response.Data.PolicyStatusDescription); Assert.AreEqual(payload.StartDate, response.Data.StartDate); Assert.AreEqual(expectedMsg, response.Message); Assert.AreEqual(ApiMessageType.Success, response.MessageType); Assert.AreEqual(CreateClientPolicyStatus.CreateClientPolicyOk, response.StatusCode); Assert.AreEqual(true, response.Success); }
public async Task UpdatePolicyOk() { var policySvc = GetService <IPolicyService>(); var payload = GetValidPayload(); var response = await policySvc.UpdatePolicyAsync(payload); var expectedMsg = InsuranceResources.Get("UpdatePolicyOk"); Assert.AreEqual(payload.PolicyId, response.Data.PolicyId); Assert.AreEqual(payload.Description, response.Data.Description); Assert.AreEqual(payload.Name, response.Data.Name); Assert.AreEqual(payload.Periods, response.Data.Periods); Assert.AreEqual(payload.Price, response.Data.Price); Assert.AreEqual(payload.RiskId, response.Data.RiskId); Assert.AreNotEqual(null, response.Data.RiskDescripition); Assert.AreNotEqual(0, response.Data.MaxCoverage); Assert.AreNotEqual(0, response.Data.Coverages.Count()); Assert.AreEqual(expectedMsg, response.Message); Assert.AreEqual(ApiMessageType.Success, response.MessageType); Assert.AreEqual(UpdatePolicyStatus.UpdatePolicyOk, response.StatusCode); Assert.AreEqual(true, response.Success); }
public async Task <ApiResponse <PolicyCoverageDto, CreatePolicyCoverageStatus> > CreatePolicyCoverageAsync(CreatePolicyCoveragePayload payload) { StartLog(); ApiResponse <PolicyCoverageDto, CreatePolicyCoverageStatus> response; if (!Validate(payload, out string message, out string property)) { response = Error <CreatePolicyCoverageStatus>(message, property); EndLog(); return(response); } var policy = await _policyService.GetPolicyAsync( new GetPolicyPayload { PolicyId = payload.PolicyId }); if (policy.Data == null) { response = Error(CreatePolicyCoverageStatus.PolicyIdNotFound); EndLog(); return(response); } var usage = await _clientPolicySvc.CheckPolicyUsageAsync( new CheckPolicyUsagePayload { PolicyId = payload.PolicyId }); if (usage.Data.IsInUse) { response = Error(CreatePolicyCoverageStatus.PolicyInUse); EndLog(); return(response); } var coverage = await _masterDataSvc.GetCoverageAsync( new GetCoveragePayload { CoverageId = payload.CoverageId }); if (coverage.Data == null) { response = Error(CreatePolicyCoverageStatus.CoverageIdNotFound); EndLog(); return(response); } var coverageExists = policy.Data.Coverages.Any( c => c.CoverageDescription == coverage.Data.Description); if (coverageExists) { response = Error(CreatePolicyCoverageStatus.CoverageAlreadyAdded); EndLog(); return(response); } if (payload.Percentage > policy.Data.MaxCoverage) { response = new ApiResponse <PolicyCoverageDto, CreatePolicyCoverageStatus> { Message = InsuranceResources.Get("MaxCoverageExceeded", policy.Data.MaxCoverage), MessageType = ApiMessageType.Error, StatusCode = CreatePolicyCoverageStatus.MaxCoverageExceeded }; EndLog(); return(response); } var policyCoverage = Mapper.Map <PolicyCoverage>(payload); await SaveAsync(ApiChangeAction.Insert, policyCoverage); response = Ok <PolicyCoverageDto, CreatePolicyCoverageStatus>(policyCoverage, CreatePolicyCoverageStatus.CreatePolicyCoverageOk); EndLog(); return(response); }