public PolicyDomainModel(PolicyEntity policyEntity)
 {
     Id = policyEntity.Id;
       Number = policyEntity.Number;
       SerialNumber = policyEntity.SerialNumber;
       DeviceName = policyEntity.DeviceName;
 }
        protected override void Seed(EDeviceClaims.Repositories.Contexts.EDeviceClaimsContext context)
        {
            var roleStore   = new RoleStore <IdentityRole>(context);
            var roleManager = new RoleManager <IdentityRole>(roleStore);

            roleManager.Create(new IdentityRole {
                Name = ApplicationRoles.Admin
            });
            roleManager.Create(new IdentityRole {
                Name = ApplicationRoles.Underwriter
            });
            roleManager.Create(new IdentityRole {
                Name = ApplicationRoles.PolicyHolder
            });

            var policyHolder = CreateUser("*****@*****.**", "*****@*****.**", context, ApplicationRoles.PolicyHolder, "Policy", "Holder");

            CreateUser("*****@*****.**", "*****@*****.**", context, ApplicationRoles.Admin, "Admin", "Istrator");
            CreateUser("*****@*****.**", "*****@*****.**", context, ApplicationRoles.Underwriter, "Under", "Writer");

            var p1 = new PolicyEntity
            {
                Id            = Guid.NewGuid(),
                Number        = "12345",
                SerialNumber  = "ABCDEF",
                DeviceName    = "iPhone 6+",
                CustomerEmail = "*****@*****.**",
                UserId        = policyHolder.Id
            };
            var p2 = new PolicyEntity
            {
                Id            = Guid.NewGuid(),
                Number        = "67890",
                SerialNumber  = "GHIJKL",
                DeviceName    = "Android",
                CustomerEmail = "*****@*****.**",
                UserId        = policyHolder.Id
            };


            context.Policies.AddOrUpdate(
                p => p.Number,
                p1,
                p2,
                new PolicyEntity {
                Id = Guid.NewGuid(), Number = "11121", SerialNumber = "MNOPQ", DeviceName = "iPhone 6+", CustomerEmail = "*****@*****.**"
            },
                new PolicyEntity {
                Id = Guid.NewGuid(), Number = "31415", SerialNumber = "RSTUV", DeviceName = "iPhone 6+", CustomerEmail = "*****@*****.**"
            },
                new PolicyEntity {
                Id = Guid.NewGuid(), Number = "16171", SerialNumber = "WXYZA", DeviceName = "iPhone 6+", CustomerEmail = "*****@*****.**"
            },
                new PolicyEntity {
                Id = Guid.NewGuid(), Number = "81920", SerialNumber = "BCDEF", DeviceName = "iPhone 6+", CustomerEmail = "*****@*****.**"
            },
                new PolicyEntity {
                Id = Guid.NewGuid(), Number = "21222", SerialNumber = "GHIJK", DeviceName = "iPhone 6+", CustomerEmail = "*****@*****.**"
            },
                new PolicyEntity {
                Id = Guid.NewGuid(), Number = "32425", SerialNumber = "LMNOP", DeviceName = "iPhone 6+", CustomerEmail = "*****@*****.**"
            },
                new PolicyEntity {
                Id = Guid.NewGuid(), Number = "26272", SerialNumber = "QRSTU", DeviceName = "iPhone 6+", CustomerEmail = "*****@*****.**"
            }
                );

            //policyHolder.UserPolicies.Add(p1);
            //policyHolder.UserPolicies.Add(p2);
            //context.SaveChanges();
        }
        public async Task GetPolicies()
        {
            var options = TestHelper.GetDbContext("GetPolicies");

            var user1   = TestHelper.InsertUserDetailed(options);
            var user2   = TestHelper.InsertUserDetailed(options, user1.Organisation);
            var client1 = TestHelper.InsertClient(options, user1.Organisation);
            var client2 = TestHelper.InsertClient(options, user1.Organisation);

            var user3   = TestHelper.InsertUserDetailed(options);
            var client3 = TestHelper.InsertClient(options, user3.Organisation);

            var company1 = TestHelper.InsertCompany(options);

            //Given
            var policy1 = new PolicyEntity
            {
                Id                  = Guid.NewGuid(),
                CompanyId           = company1.Id,
                ClientId            = client1.Client.Id,
                UserId              = user1.User.Id,
                Number              = "123465",
                StartDate           = DateTime.Now,
                Premium             = 500,
                PolicyTypeId        = Guid.NewGuid(),
                PolicyProductTypeId = Guid.NewGuid(),
                PolicyProductId     = Guid.NewGuid(),
                IsActive            = true,
            };

            var policy2 = new PolicyEntity
            {
                Id                  = Guid.NewGuid(),
                CompanyId           = company1.Id,
                ClientId            = client2.Client.Id,
                UserId              = user2.User.Id,
                Number              = "654321",
                PolicyTypeId        = Guid.NewGuid(),
                PolicyProductTypeId = Guid.NewGuid(),
                PolicyProductId     = Guid.NewGuid(),
                IsActive            = false,
            };

            var policy3 = new PolicyEntity
            {
                Id        = Guid.NewGuid(),
                CompanyId = company1.Id,
                ClientId  = client3.Client.Id,
                UserId    = user3.User.Id,
                Number    = "987654"
            };

            using (var context = new DataContext(options))
            {
                context.Policy.Add(policy1);
                context.Policy.Add(policy2);
                context.Policy.Add(policy3);

                context.SaveChanges();
            }

            using (var context = new DataContext(options))
            {
                var auditService = new AuditServiceMock();
                var service      = new PolicyService(context, auditService);

                //When
                var scope        = TestHelper.GetScopeOptions(user1);
                var queryOptions = new PolicyQueryOptions(scope, "", "", 0, 0);
                var policies     = await service.GetPolicies(queryOptions);

                //Then
                Assert.Equal(2, policies.TotalItems);
                Assert.Equal(2, policies.Items.Count());

                var actual = policies.Items.First();
                Assert.Equal(policy1.Id, actual.Id);
                Assert.Equal(policy1.ClientId, actual.ClientId);
                Assert.Equal(policy1.CompanyId, actual.CompanyId);
                Assert.Equal(policy1.Number, actual.Number);
                Assert.Equal(policy1.StartDate, actual.StartDate);
                Assert.Equal(policy1.Premium, actual.Premium);
                Assert.Equal(policy1.PolicyTypeId, actual.PolicyTypeId);
                Assert.Equal(policy1.PolicyProductTypeId, actual.PolicyProductTypeId);
                Assert.Equal(policy1.PolicyProductId, actual.PolicyProductId);
                Assert.Equal(policy1.IsActive, actual.IsActive);

                actual = policies.Items.Last();
                Assert.Equal(policy2.Id, actual.Id);
                Assert.Equal(policy2.IsActive, actual.IsActive);

                //Check scope
                scope        = TestHelper.GetScopeOptions(user1, Scope.User);
                queryOptions = new PolicyQueryOptions(scope, "", "", 0, 0);
                policies     = await service.GetPolicies(queryOptions);

                Assert.Single(policies.Items);

                actual = policies.Items.First();
                Assert.Equal(policy1.Id, actual.Id);
            }
        }
        public async Task GetPolicy()
        {
            var options = TestHelper.GetDbContext("GetPolicy");

            var user1   = TestHelper.InsertUserDetailed(options);
            var client1 = TestHelper.InsertClient(options, user1.Organisation);

            //Given
            var policy1 = new PolicyEntity
            {
                Id        = Guid.NewGuid(),
                CompanyId = Guid.NewGuid(),
                ClientId  = client1.Client.Id,
                UserId    = user1.User.Id,
                Number    = "123465",
                IsActive  = false,
            };

            var policy2 = new PolicyEntity
            {
                Id                  = Guid.NewGuid(),
                CompanyId           = Guid.NewGuid(),
                ClientId            = client1.Client.Id,
                UserId              = user1.User.Id,
                Number              = "654987",
                StartDate           = DateTime.Now,
                Premium             = 500,
                PolicyTypeId        = Guid.NewGuid(),
                PolicyProductTypeId = Guid.NewGuid(),
                PolicyProductId     = Guid.NewGuid(),
                IsActive            = false,
            };

            using (var context = new DataContext(options))
            {
                context.Policy.Add(policy1);
                context.Policy.Add(policy2);

                context.SaveChanges();
            }

            using (var context = new DataContext(options))
            {
                var auditService = new AuditServiceMock();
                var service      = new PolicyService(context, auditService);

                //When
                var scopeOptions = TestHelper.GetScopeOptions(user1);
                var actual       = await service.GetPolicy(scopeOptions, policy2.Id);

                //Then
                Assert.Equal(policy2.Id, actual.Id);
                Assert.Equal(policy2.ClientId, actual.ClientId);
                Assert.Equal(policy2.CompanyId, actual.CompanyId);
                Assert.Equal(policy2.UserId, actual.UserId);
                Assert.Equal(policy2.Number, actual.Number);
                Assert.Equal(policy2.StartDate, actual.StartDate);
                Assert.Equal(policy2.Premium, actual.Premium);
                Assert.Equal(policy2.PolicyTypeId, actual.PolicyTypeId);
                Assert.Equal(policy2.PolicyProductTypeId, actual.PolicyProductTypeId);
                Assert.Equal(policy2.PolicyProductId, actual.PolicyProductId);
                Assert.Equal(policy2.IsActive, actual.IsActive);
            }
        }
예제 #5
0
 public async Task <PolicyEntity> Create(PolicyEntity policyEntity)
 {
     _policyEntity.Add(policyEntity);
     _dbContext.SaveChanges();
     return(policyEntity);
 }
        public async Task AutoResolveMappingErrors_4Entries_AutoResolve3()
        {
            var options = TestHelper.GetDbContext("AutoResolveMappingErrors_4Entries_AutoResolve3");

            var user1   = TestHelper.InsertUserDetailed(options);
            var client1 = TestHelper.InsertClient(options, user1.Organisation);

            var statement = TestHelper.InsertCommissionStatement(options, user1.Organisation);

            var commissionTypeId = Guid.NewGuid();

            var company1 = TestHelper.InsertCompany(options);

            var policyAliasNumber1 = "98765";

            var policy1 = new PolicyEntity
            {
                Id            = Guid.NewGuid(),
                Number        = "123456",
                CompanyId     = company1.Id,
                ClientId      = client1.Client.Id,
                UserId        = user1.User.Id,
                NumberAliases = new List <string>()
                {
                    policyAliasNumber1
                }
            };

            // ENTRY 1: POLICY 1 -----------------------
            var ic1a = new ImportCommission
            {
                PolicyNumber       = policy1.Number,
                CommissionTypeCode = "gap_cover",
                AmountIncludingVAT = "11",
                VAT = "22"
            };

            var err1a = new CommissionErrorEntity
            {
                Id = Guid.NewGuid(),
                CommissionStatementId = statement.Id,
                CommissionTypeId      = commissionTypeId,
                Data = ic1a
            };
            //------------------------------------------


            // ENTRY 2: POLICY 1 -----------------------
            var ic1b = new ImportCommission
            {
                PolicyNumber       = policy1.Number,
                CommissionTypeCode = "gap_cover",
                AmountIncludingVAT = "33",
                VAT = "44"
            };

            var err1b = new CommissionErrorEntity
            {
                Id = Guid.NewGuid(),
                CommissionStatementId = statement.Id,
                CommissionTypeId      = commissionTypeId,
                Data = ic1b
            };
            //------------------------------------------


            // ENTRY 3: POLICY ? -----------------------
            var ic2 = new ImportCommission
            {
                PolicyNumber       = "654321",
                CommissionTypeCode = "gap_cover",
                AmountIncludingVAT = "55",
                VAT = "66"
            };

            var err2 = new CommissionErrorEntity
            {
                Id = Guid.NewGuid(),
                CommissionStatementId = statement.Id,
                CommissionTypeId      = commissionTypeId,
                Data = ic2
            };
            //------------------------------------------


            // ENTRY 4: POLICY 1 -----------------------
            var ic1c = new ImportCommission
            {
                PolicyNumber       = policyAliasNumber1,
                CommissionTypeCode = "gap_cover",
                AmountIncludingVAT = "77",
                VAT = "88"
            };
            var err1c = new CommissionErrorEntity
            {
                Id = Guid.NewGuid(),
                CommissionStatementId = statement.Id,
                CommissionTypeId      = commissionTypeId,
                Data = ic1c
            };

            //------------------------------------------


            using (var context = new DataContext(options))
            {
                context.CommissionError.Add(err1a);
                context.CommissionError.Add(err2);
                context.CommissionError.Add(err1b);
                context.CommissionError.Add(err1c);

                context.Policy.Add(policy1);

                context.SaveChanges();

                var error1 = new CommissionError
                {
                    Id = err1a.Id,
                    CommissionStatementId = statement.Id,
                    PolicyId         = policy1.Id,
                    ClientId         = policy1.ClientId,
                    CommissionTypeId = err1a.CommissionTypeId,
                    Data             = ic1a
                };

                var auditService                     = new AuditServiceMock();
                var commissionService                = new CommissionService(context, auditService);
                var clientService                    = new ClientService(context, auditService);
                var policyService                    = new PolicyService(context, auditService);
                var commissionSplitService           = new CommissionSplitService(context, auditService);
                var commissionSplitRulePolicyService = new CommissionSplitRulePolicyService(context, commissionSplitService, auditService);
                var service = new CommissionErrorService(context, commissionService, clientService, commissionSplitService, policyService, commissionSplitRulePolicyService, auditService);

                //When
                var scope = TestHelper.GetScopeOptions(user1);
                await service.AutoResolveMappingErrors(scope, statement.Id, policy1.Id);

                //Then
                var actualErrors = context.CommissionError.ToList();

                Assert.Single(actualErrors);
                Assert.Equal(err2.Id, actualErrors[0].Id);

                var commissions = context.Commission.ToList();

                Assert.Equal(3, commissions.Count);
                var actual = commissions[0];
                Assert.Equal(error1.PolicyId, actual.PolicyId);
                Assert.Equal(error1.CommissionStatementId, actual.CommissionStatementId);
                Assert.Equal(error1.CommissionTypeId, actual.CommissionTypeId);
                Assert.Equal(11, actual.AmountIncludingVAT);
                Assert.Equal(22, actual.VAT);
                Assert.Equal(err1a.Data, actual.SourceData);

                actual = commissions[1];
                Assert.Equal(error1.PolicyId, actual.PolicyId);
                Assert.Equal(error1.CommissionStatementId, actual.CommissionStatementId);
                Assert.Equal(error1.CommissionTypeId, actual.CommissionTypeId);
                Assert.Equal(33, actual.AmountIncludingVAT);
                Assert.Equal(44, actual.VAT);
                Assert.Equal(err1b.Data, actual.SourceData);

                actual = commissions[2];
                Assert.Equal(error1.PolicyId, actual.PolicyId);
                Assert.Equal(error1.CommissionStatementId, actual.CommissionStatementId);
                Assert.Equal(error1.CommissionTypeId, actual.CommissionTypeId);
                Assert.Equal(77, actual.AmountIncludingVAT);
                Assert.Equal(88, actual.VAT);
                Assert.Equal(err1c.Data, actual.SourceData);
            }
        }
        public async Task ResolveMappingError_Pass_UpdateMemberDetails()
        {
            var options = TestHelper.GetDbContext("ResolveMappingError_Pass_UpdateMemberDetails");

            var user1 = TestHelper.InsertUserDetailed(options);

            var statement = TestHelper.InsertCommissionStatement(options, user1.Organisation);

            var company1 = TestHelper.InsertCompany(options);

            var client1 = new ClientEntity
            {
                Id             = Guid.NewGuid(),
                ClientTypeId   = ClientType.CLIENT_TYPE_INDIVIDUAL,
                FirstName      = "",
                LastName       = "",
                IdNumber       = "",
                OrganisationId = user1.Organisation.Id,
                Initials       = "",
                DateOfBirth    = null,
                TaxNumber      = Guid.NewGuid().ToString()
            };

            var policy1 = new PolicyEntity
            {
                Id        = Guid.NewGuid(),
                CompanyId = company1.Id,
                ClientId  = client1.Id,
                UserId    = user1.User.Id
            };

            var ic1 = new ImportCommission
            {
                PolicyNumber       = "123456",
                CommissionTypeCode = "gap_cover",
                AmountIncludingVAT = "22",
                VAT         = "33",
                FirstName   = "Dean",
                LastName    = "van Niekerk",
                IdNumber    = "8210035032082",
                DateOfBirth = "1982-10-03",
                Initials    = "DJ"
            };

            var err1 = new CommissionErrorEntity
            {
                Id = Guid.NewGuid(),
                CommissionStatementId = statement.Id,
                Data = ic1
            };

            using (var context = new DataContext(options))
            {
                context.Client.Add(client1);

                context.CommissionError.Add(err1);

                context.Policy.Add(policy1);

                context.SaveChanges();

                var error1 = new CommissionErrorEdit
                {
                    Id = err1.Id,
                    CommissionStatementId = statement.Id,
                    PolicyId         = policy1.Id,
                    ClientId         = policy1.ClientId,
                    CommissionTypeId = Guid.NewGuid(),
                    Data             = ic1
                };

                var auditService                     = new AuditServiceMock();
                var commissionService                = new CommissionService(context, auditService);
                var clientService                    = new ClientService(context, auditService);
                var policyService                    = new PolicyService(context, auditService);
                var commissionSplitService           = new CommissionSplitService(context, auditService);
                var commissionSplitRulePolicyService = new CommissionSplitRulePolicyService(context, commissionSplitService, auditService);
                var service = new CommissionErrorService(context, commissionService, clientService, commissionSplitService, policyService, commissionSplitRulePolicyService, auditService);

                //When
                var scope  = TestHelper.GetScopeOptions(user1);
                var result = await service.ResolveMappingError(scope, error1);

                //Then
                Assert.True(result.Success);

                var actual = context.Commission.Single();

                Assert.Equal(error1.PolicyId, actual.PolicyId);
                Assert.Equal(error1.CommissionStatementId, actual.CommissionStatementId);
                Assert.Equal(error1.CommissionTypeId, actual.CommissionTypeId);
                Assert.Equal(22, actual.AmountIncludingVAT);
                Assert.Equal(33, actual.VAT);
                Assert.Equal(error1.Data, actual.SourceData);

                var actualClient = context.Client.Single();
                Assert.Equal(ic1.Initials, actualClient.Initials);
                Assert.Equal(ic1.FirstName, actualClient.FirstName);
                Assert.Equal(ic1.LastName, actualClient.LastName);
                Assert.Equal(ic1.IdNumber, actualClient.IdNumber);
                Assert.Equal(DateTime.Parse(ic1.DateOfBirth), actualClient.DateOfBirth);
            }
        }
        protected override void Seed(EDeviceClaims.Repositories.Contexts.EDeviceClaimsContext context)
        {
            //  This method will be called after migrating to the latest version.

            //  You can use the DbSet<T>.AddOrUpdate() helper extension method
            //  to avoid creating duplicate seed data. E.g.
            //
            //    context.People.AddOrUpdate(
            //      p => p.FullName,
            //      new Person { FullName = "Andrew Peters" },
            //      new Person { FullName = "Brice Lambson" },
            //      new Person { FullName = "Rowan Miller" }
            //    );
            //

            var policyHolder = CreateUser("*****@*****.**", "*****@*****.**", context, ApplicationRoles.PolicyHolder);

            CreateUser("*****@*****.**", "*****@*****.**", context, ApplicationRoles.Admin);
            CreateUser("*****@*****.**", "*****@*****.**", context, ApplicationRoles.Underwriter);

            var p1 = new PolicyEntity
            {
                Id            = Guid.NewGuid(),
                Number        = "12345",
                SerialNumber  = "ABCDEF",
                DeviceName    = "iPhone 6+",
                CustomerEmail = "*****@*****.**",
                UserId        = policyHolder.Id
            };
            var p2 = new PolicyEntity
            {
                Id            = Guid.NewGuid(),
                Number        = "67890",
                SerialNumber  = "GHIJKL",
                DeviceName    = "Android",
                CustomerEmail = "*****@*****.**",
                UserId        = policyHolder.Id
            };
            var p3 = new PolicyEntity
            {
                Id            = Guid.NewGuid(),
                Number        = "99999",
                SerialNumber  = "RF3C6000MNA",
                DeviceName    = "iPad Pro",
                CustomerEmail = "*****@*****.**",
                UserId        = policyHolder.Id
            };
            var p4 = new PolicyEntity
            {
                Id            = Guid.NewGuid(),
                Number        = "88888",
                SerialNumber  = "SN483-AB-448N7",
                DeviceName    = "Samsung Galaxy Note7",
                CustomerEmail = "*****@*****.**",
                UserId        = policyHolder.Id
            };

            context.Policies.AddOrUpdate(
                p => p.Number,
                p1,
                p2,
                new PolicyEntity {
                Id = Guid.NewGuid(), Number = "11121", SerialNumber = "MNOPQ", DeviceName = "iPhone 6+", CustomerEmail = "*****@*****.**"
            },
                new PolicyEntity {
                Id = Guid.NewGuid(), Number = "31415", SerialNumber = "RSTUV", DeviceName = "iPhone 6+", CustomerEmail = "*****@*****.**"
            },
                new PolicyEntity {
                Id = Guid.NewGuid(), Number = "16171", SerialNumber = "WXYZA", DeviceName = "iPhone 6+", CustomerEmail = "*****@*****.**"
            },
                new PolicyEntity {
                Id = Guid.NewGuid(), Number = "81920", SerialNumber = "BCDEF", DeviceName = "iPhone 6+", CustomerEmail = "*****@*****.**"
            },
                new PolicyEntity {
                Id = Guid.NewGuid(), Number = "21222", SerialNumber = "GHIJK", DeviceName = "iPhone 6+", CustomerEmail = "*****@*****.**"
            },
                new PolicyEntity {
                Id = Guid.NewGuid(), Number = "32425", SerialNumber = "LMNOP", DeviceName = "iPhone 6+", CustomerEmail = "*****@*****.**"
            },
                new PolicyEntity {
                Id = Guid.NewGuid(), Number = "26272", SerialNumber = "QRSTU", DeviceName = "iPhone 6+", CustomerEmail = "*****@*****.**"
            }
                );

            //policyHolder.UserPolicies.Add(p1);
            //policyHolder.UserPolicies.Add(p2);
            //policyHolder.UserPolicies.Add(p3);
            //policyHolder.UserPolicies.Add(p4);
            //context.SaveChanges();
        }
예제 #9
0
        public void Delete(PolicyEntity policyEntity)
        {
            var sql = @"DELETE FROM Policy WHERE PolicyGuid=@PolicyGuid";

            _context.Connection.Execute(sql, new { PolicyGuid = policyEntity.PolicyGuid });
        }
예제 #10
0
 public void SearchAccountByAccountNumber(PolicyEntity policy)
 {
     Pages.SearchSubmissionsPage.SearchAccountByAccountNumber(policy);
     Pages.SearchSubmissionsPage.ClickSearchResultByRowNumber(1);
 }
        public async Task DeleteCommissionSplitRulePolicy()
        {
            var options = TestHelper.GetDbContext("DeleteCommissionSplitRulePolicy");

            var user1   = TestHelper.InsertUserDetailed(options);
            var client1 = TestHelper.InsertClient(options, user1.Organisation);

            var user2 = TestHelper.InsertUserDetailed(options);

            var policy1 = new PolicyEntity
            {
                Id        = Guid.NewGuid(),
                CompanyId = Guid.NewGuid(),
                ClientId  = client1.Client.Id,
                UserId    = user1.User.Id,
                Number    = "123465",
            };

            var policy2 = new PolicyEntity
            {
                Id        = Guid.NewGuid(),
                CompanyId = Guid.NewGuid(),
                ClientId  = client1.Client.Id,
                UserId    = user1.User.Id,
                Number    = "123465",
            };

            var csrp1 = new CommissionSplitRulePolicyEntity
            {
                Id       = Guid.NewGuid(),
                PolicyId = policy1.Id,
                CommissionSplitRuleId = Guid.NewGuid()
            };

            var csrp2 = new CommissionSplitRulePolicyEntity
            {
                Id       = Guid.NewGuid(),
                PolicyId = policy1.Id,
                CommissionSplitRuleId = Guid.NewGuid()
            };

            using (var context = new DataContext(options))
            {
                context.Policy.Add(policy1);
                context.Policy.Add(policy2);

                context.CommissionSplitRulePolicy.Add(csrp1);
                context.CommissionSplitRulePolicy.Add(csrp2);

                context.SaveChanges();
            }
            using (var context = new DataContext(options))
            {
                var auditService = new AuditServiceMock();
                var service      = new CommissionSplitRulePolicyService(context, null, auditService);

                //When
                var scope  = TestHelper.GetScopeOptions(user1);
                var result = await service.DeleteCommissionSplitRulePolicy(scope, csrp2.Id);

                //Then
                Assert.True(result.Success);

                var actual = await context.CommissionSplitRulePolicy.FindAsync(csrp2.Id);

                Assert.Null(actual);

                //Out of scope
                scope  = TestHelper.GetScopeOptions(user2, Scope.User);
                result = await service.DeleteCommissionSplitRulePolicy(scope, csrp1.Id);

                Assert.False(result.Success);

                actual = await context.CommissionSplitRulePolicy.FindAsync(csrp1.Id);

                Assert.NotNull(actual);
            }
        }
        public async Task UpdateCommissionSplitRule_IsDefault_Deleted()
        {
            var options = TestHelper.GetDbContext("UpdateCommissionSplitRule_IsDefault_Deleted");

            var user1   = TestHelper.InsertUserDetailed(options);
            var client1 = TestHelper.InsertClient(options, user1.Organisation);

            var policy1 = new PolicyEntity
            {
                Id        = Guid.NewGuid(),
                CompanyId = Guid.NewGuid(),
                ClientId  = client1.Client.Id,
                UserId    = user1.User.Id,
                Number    = "123465",
            };

            var csr2 = new CommissionSplitRuleEntity
            {
                Id        = Guid.NewGuid(),
                UserId    = user1.User.Id,
                Name      = "Com Split Rule 2",
                IsDefault = true, //Is Default
                Split     = new List <CommissionSplit>()
                {
                    new CommissionSplit()
                    {
                        UserId     = user1.User.Id,
                        Percentage = 100
                    }
                }
            };

            var csrp1 = new CommissionSplitRulePolicyEntity
            {
                Id       = Guid.NewGuid(),
                PolicyId = policy1.Id,
                CommissionSplitRuleId = Guid.NewGuid()
            };

            var csrp2 = new CommissionSplitRulePolicyEntity
            {
                Id       = Guid.NewGuid(),
                PolicyId = policy1.Id,
                CommissionSplitRuleId = Guid.NewGuid()
            };

            using (var context = new DataContext(options))
            {
                context.Policy.Add(policy1);

                context.CommissionSplitRule.Add(csr2);

                context.CommissionSplitRulePolicy.Add(csrp1);
                context.CommissionSplitRulePolicy.Add(csrp2);

                context.SaveChanges();
            }

            using (var context = new DataContext(options))
            {
                var csrp2Updated = new CommissionSplitRulePolicy
                {
                    Id       = csrp2.Id,
                    PolicyId = policy1.Id,
                    CommissionSplitRuleId = csr2.Id
                };

                var auditService           = new AuditServiceMock();
                var commissionSplitService = new CommissionSplitService(context, auditService);
                var service = new CommissionSplitRulePolicyService(context, commissionSplitService, auditService);

                //When
                var scope  = TestHelper.GetScopeOptions(user1);
                var result = await service.UpdateCommissionSplitRulePolicy(scope, csrp2Updated);

                //Then
                Assert.True(result.Success);

                var actual = await context.CommissionSplitRulePolicy.FindAsync(csrp2Updated.Id);

                Assert.Null(actual);

                actual = await context.CommissionSplitRulePolicy.FindAsync(csrp1.Id);

                Assert.NotNull(actual);
            }
        }
        public async Task UpdateCommissionSplitRule()
        {
            var options = TestHelper.GetDbContext("UpdateCommissionSplitRule");

            var user1   = TestHelper.InsertUserDetailed(options);
            var client1 = TestHelper.InsertClient(options, user1.Organisation);

            var user2 = TestHelper.InsertUserDetailed(options);

            var policy1 = new PolicyEntity
            {
                Id        = Guid.NewGuid(),
                CompanyId = Guid.NewGuid(),
                ClientId  = client1.Client.Id,
                UserId    = user1.User.Id,
                Number    = "123465",
            };

            var policy2 = new PolicyEntity
            {
                Id        = Guid.NewGuid(),
                CompanyId = Guid.NewGuid(),
                ClientId  = client1.Client.Id,
                UserId    = user1.User.Id,
                Number    = "123465",
            };

            var csr2 = new CommissionSplitRuleEntity
            {
                Id        = Guid.NewGuid(),
                UserId    = user1.User.Id,
                Name      = "Com Split Rule 2",
                IsDefault = false,
                Split     = new List <CommissionSplit>()
                {
                    new CommissionSplit()
                    {
                        UserId     = user1.User.Id,
                        Percentage = 100
                    }
                }
            };

            var csrp1 = new CommissionSplitRulePolicyEntity
            {
                Id       = Guid.NewGuid(),
                PolicyId = policy1.Id,
                CommissionSplitRuleId = Guid.NewGuid()
            };

            var csrp2 = new CommissionSplitRulePolicyEntity
            {
                Id       = Guid.NewGuid(),
                PolicyId = policy1.Id,
                CommissionSplitRuleId = Guid.NewGuid()
            };

            using (var context = new DataContext(options))
            {
                context.Policy.Add(policy1);
                context.Policy.Add(policy2);

                context.CommissionSplitRule.Add(csr2);

                context.CommissionSplitRulePolicy.Add(csrp1);
                context.CommissionSplitRulePolicy.Add(csrp2);

                context.SaveChanges();
            }

            using (var context = new DataContext(options))
            {
                var csrp2Updated = new CommissionSplitRulePolicy
                {
                    Id       = csrp2.Id,
                    PolicyId = policy2.Id,
                    CommissionSplitRuleId = csr2.Id
                };

                var auditService           = new AuditServiceMock();
                var commissionSplitService = new CommissionSplitService(context, auditService);
                var service = new CommissionSplitRulePolicyService(context, commissionSplitService, auditService);

                //When
                var scope  = TestHelper.GetScopeOptions(user1);
                var result = await service.UpdateCommissionSplitRulePolicy(scope, csrp2Updated);

                //Then
                Assert.True(result.Success);

                var actual = await context.CommissionSplitRulePolicy.FindAsync(csrp2Updated.Id);

                Assert.Equal(csrp2Updated.Id, actual.Id);
                Assert.Equal(csrp2Updated.PolicyId, actual.PolicyId);
                Assert.Equal(csrp2Updated.CommissionSplitRuleId, actual.CommissionSplitRuleId);

                //Out of scope
                scope  = TestHelper.GetScopeOptions(user2, Scope.User);
                result = await service.InsertCommissionSplitRulePolicy(scope, csrp2Updated);

                Assert.False(result.Success);
                Assert.Equal("'Policy' does not exist.", result.ValidationFailures.First().ErrorMessage);
            }
        }
        public async Task GetCommissionSplitRulePolicy_UseDefault()
        {
            var options = TestHelper.GetDbContext("GetCommissionSplitRulePolicy_UseDefault");

            var user1   = TestHelper.InsertUserDetailed(options);
            var client1 = TestHelper.InsertClient(options, user1.Organisation);

            var policy1 = new PolicyEntity
            {
                Id        = Guid.NewGuid(),
                CompanyId = Guid.NewGuid(),
                ClientId  = client1.Client.Id,
                UserId    = user1.User.Id,
                Number    = "123465",
            };

            var csr1 = new CommissionSplitRuleEntity
            {
                Id        = Guid.NewGuid(),
                UserId    = user1.User.Id,
                Name      = "Com Split Rule 1",
                IsDefault = true,
                Split     = new List <CommissionSplit>()
                {
                    new CommissionSplit()
                    {
                        UserId     = user1.User.Id,
                        Percentage = 100
                    }
                }
            };

            var csr2 = new CommissionSplitRuleEntity
            {
                Id        = Guid.NewGuid(),
                UserId    = user1.User.Id,
                Name      = "Com Split Rule 2",
                IsDefault = false,
                Split     = new List <CommissionSplit>()
                {
                    new CommissionSplit()
                    {
                        UserId     = user1.User.Id,
                        Percentage = 100
                    }
                }
            };

            using (var context = new DataContext(options))
            {
                context.Policy.Add(policy1);

                context.CommissionSplitRule.Add(csr2);
                context.CommissionSplitRule.Add(csr1);

                context.SaveChanges();
            }

            using (var context = new DataContext(options))
            {
                var auditService           = new AuditServiceMock();
                var commissionSplitService = new CommissionSplitService(context, auditService);
                var service = new CommissionSplitRulePolicyService(context, commissionSplitService, auditService);

                //When
                var scope  = TestHelper.GetScopeOptions(user1);
                var actual = await service.GetCommissionSplitRulePolicy(scope, policy1.Id);

                //Then
                Assert.Null(actual.Id);
                Assert.Equal(policy1.Id, actual.PolicyId);
                Assert.Equal(csr1.Id, actual.CommissionSplitRuleId);
            }
        }
        public async Task Policies()
        {
            var options = TestHelper.GetDbContext("Policies");

            var user1   = TestHelper.InsertUserDetailed(options);
            var client1 = TestHelper.InsertClient(options, user1.Organisation);
            var client2 = TestHelper.InsertClient(options, user1.Organisation);
            var client3 = TestHelper.InsertClient(options, user1.Organisation);

            var policyType1 = TestHelper.InsertPolicyType(options);
            var policyType2 = TestHelper.InsertPolicyType(options);

            TestHelper.InsertClient(options); //Different org

            var policy1 = new PolicyEntity {
                Number = "123456", ClientId = client1.Client.Id, Premium = 200, StartDate = DateTime.Now.AddYears(-1), UserId = user1.User.Id, PolicyTypeId = policyType1.Id
            };
            var policy2 = new PolicyEntity {
                Number = "654321", ClientId = client2.Client.Id, Premium = 300, UserId = user1.User.Id, PolicyTypeId = policyType2.Id
            };
            var policy3 = new PolicyEntity {
                Number = "987654", ClientId = client1.Client.Id, StartDate = DateTime.Now.AddYears(-2), UserId = user1.User.Id
            };

            using (var context = new DataContext(options))
            {
                context.Policy.Add(policy1);
                context.Policy.Add(policy2);
                context.Policy.Add(policy3);

                context.Contact.Add(new ContactEntity {
                    ClientId = client2.Client.Id, ContactTypeId = ContactType.CONTACT_TYPE_EMAIL, Value = "*****@*****.**"
                });
                context.Contact.Add(new ContactEntity {
                    ClientId = client1.Client.Id, ContactTypeId = ContactType.CONTACT_TYPE_EMAIL, Value = "*****@*****.**"
                });
                context.Contact.Add(new ContactEntity {
                    ClientId = client1.Client.Id, ContactTypeId = ContactType.CONTACT_TYPE_CELLPHONE, Value = "0825728997"
                });

                context.SaveChanges();
            }

            using (var context = new DataContext(options))
            {
                var service = new ClientExportService(context);

                //When
                var renderer     = new MockClientExportRenderer <ClientPolicy>();
                var scopeOptions = TestHelper.GetScopeOptions(user1);
                await service.Policies(renderer, new MemoryStream(), scopeOptions);

                //Then
                Assert.Equal(4, renderer.Items.Count());

                var actual = renderer.Items.ToArray()[0];
                Assert.Equal(client1.Client.IdNumber, actual.IdNumber);
                Assert.Equal(client1.Client.FirstName, actual.FirstName);
                Assert.Equal(client1.Client.LastName, actual.LastName);
                Assert.Equal(client1.Client.DateOfBirth, actual.DateOfBirth);
                Assert.Equal(client1.Client.TaxNumber, actual.TaxNumber);
                Assert.Equal("*****@*****.**", actual.Email);
                Assert.Equal("0825728997", actual.CellPhone);
                Assert.Equal(policy1.Number, actual.PolicyNumber);
                Assert.Equal($"{user1.User.FirstName} {user1.User.LastName}", actual.PolicyBroker);
                Assert.Equal(policy1.Premium, actual.PolicyPremium);
                Assert.Equal(policyType1.Code, actual.PolicyTypeCode);
                Assert.Equal(policy1.StartDate, actual.PolicyStartDate);

                actual = renderer.Items.ToArray()[1];
                Assert.Equal(client1.Client.IdNumber, actual.IdNumber);
                Assert.Equal(client1.Client.FirstName, actual.FirstName);
                Assert.Equal(client1.Client.LastName, actual.LastName);
                Assert.Equal(client1.Client.DateOfBirth, actual.DateOfBirth);
                Assert.Equal(client1.Client.TaxNumber, actual.TaxNumber);
                Assert.Equal("*****@*****.**", actual.Email);
                Assert.Equal("0825728997", actual.CellPhone);
                Assert.Equal(policy3.Number, actual.PolicyNumber);
                Assert.Equal($"{user1.User.FirstName} {user1.User.LastName}", actual.PolicyBroker);
                Assert.Equal(policy3.Premium, actual.PolicyPremium);
                Assert.Null(actual.PolicyTypeCode);
                Assert.Equal(policy3.StartDate, actual.PolicyStartDate);

                actual = renderer.Items.ToArray()[2];
                Assert.Equal(client2.Client.IdNumber, actual.IdNumber);
                Assert.Equal(client2.Client.FirstName, actual.FirstName);
                Assert.Equal(client2.Client.LastName, actual.LastName);
                Assert.Equal(client2.Client.DateOfBirth, actual.DateOfBirth);
                Assert.Equal(client2.Client.TaxNumber, actual.TaxNumber);
                Assert.Equal("*****@*****.**", actual.Email);
                Assert.Null(actual.CellPhone);
                Assert.Equal(policy2.Number, actual.PolicyNumber);
                Assert.Equal($"{user1.User.FirstName} {user1.User.LastName}", actual.PolicyBroker);
                Assert.Equal(policy2.Premium, actual.PolicyPremium);
                Assert.Equal(policyType2.Code, actual.PolicyTypeCode);
                Assert.Equal(policy2.StartDate, actual.PolicyStartDate);

                actual = renderer.Items.ToArray()[3];
                Assert.Equal(client3.Client.IdNumber, actual.IdNumber);
                Assert.Equal(client3.Client.FirstName, actual.FirstName);
                Assert.Equal(client3.Client.LastName, actual.LastName);
                Assert.Equal(client3.Client.DateOfBirth, actual.DateOfBirth);
                Assert.Equal(client3.Client.TaxNumber, actual.TaxNumber);
                Assert.Null(actual.Email);
                Assert.Null(actual.CellPhone);
                Assert.Null(actual.PolicyNumber);
                Assert.Equal(" ", actual.PolicyBroker);
                Assert.Null(actual.PolicyPremium);
                Assert.Null(actual.PolicyTypeCode);
                Assert.Null(actual.PolicyStartDate);
            }
        }
        public async Task GetCommissionSplitRulePolicies()
        {
            var options = TestHelper.GetDbContext("GetCommissionSplitRulePolicies");

            var user1   = TestHelper.InsertUserDetailed(options);
            var user2   = TestHelper.InsertUserDetailed(options, user1.Organisation);
            var client1 = TestHelper.InsertClient(options, user1.Organisation);
            var client2 = TestHelper.InsertClient(options, user1.Organisation);

            var user3   = TestHelper.InsertUserDetailed(options);
            var client3 = TestHelper.InsertClient(options, user3.Organisation);

            //Given
            var policy1 = new PolicyEntity
            {
                Id        = Guid.NewGuid(),
                CompanyId = Guid.NewGuid(),
                ClientId  = client1.Client.Id,
                UserId    = user1.User.Id,
                Number    = "123465",
            };

            var policy2 = new PolicyEntity
            {
                Id        = Guid.NewGuid(),
                CompanyId = Guid.NewGuid(),
                ClientId  = client2.Client.Id,
                UserId    = user2.User.Id,
                Number    = "654321",
            };

            var policy3 = new PolicyEntity
            {
                Id        = Guid.NewGuid(),
                CompanyId = Guid.NewGuid(),
                ClientId  = client2.Client.Id,
                UserId    = user2.User.Id,
                Number    = "987654"
            };

            var policy4 = new PolicyEntity
            {
                Id        = Guid.NewGuid(),
                CompanyId = Guid.NewGuid(),
                ClientId  = client3.Client.Id,
                UserId    = user3.User.Id,
                Number    = "987654"
            };

            var csr1 = new CommissionSplitRuleEntity
            {
                Id        = Guid.NewGuid(),
                UserId    = user1.User.Id,
                Name      = "Com Split Rule 1",
                IsDefault = true,
                Split     = new List <CommissionSplit>()
                {
                    new CommissionSplit()
                    {
                        UserId     = user1.User.Id,
                        Percentage = 100
                    }
                }
            };

            var csr2 = new CommissionSplitRuleEntity
            {
                Id        = Guid.NewGuid(),
                UserId    = user2.User.Id,
                Name      = "Com Split Rule 2",
                IsDefault = true,
                Split     = new List <CommissionSplit>()
                {
                    new CommissionSplit()
                    {
                        UserId     = user2.User.Id,
                        Percentage = 100
                    }
                }
            };

            var csr3 = new CommissionSplitRuleEntity
            {
                Id        = Guid.NewGuid(),
                UserId    = user2.User.Id,
                Name      = "Com Split Rule 3",
                IsDefault = false,
                Split     = new List <CommissionSplit>()
                {
                    new CommissionSplit()
                    {
                        UserId     = user2.User.Id,
                        Percentage = 100
                    }
                }
            };

            var csrp1 = new CommissionSplitRulePolicyEntity
            {
                Id       = Guid.NewGuid(),
                PolicyId = policy2.Id,
                CommissionSplitRuleId = csr3.Id
            };

            using (var context = new DataContext(options))
            {
                context.Policy.Add(policy1);
                context.Policy.Add(policy2);
                context.Policy.Add(policy3);
                context.Policy.Add(policy4);

                context.CommissionSplitRule.Add(csr1);
                context.CommissionSplitRule.Add(csr2);
                context.CommissionSplitRule.Add(csr3);

                context.CommissionSplitRulePolicy.Add(csrp1);

                context.SaveChanges();
            }

            using (var context = new DataContext(options))
            {
                var auditService = new AuditServiceMock();
                var service      = new CommissionSplitRulePolicyService(context, null, auditService);

                //When
                var scope        = TestHelper.GetScopeOptions(user1);
                var queryOptions = new CommissionSplitRulePolicyInfoQueryOptions(scope, "", "", 0, 0);
                var rules        = await service.GetCommissionSplitRulePolicyInfoList(queryOptions);

                //Then
                Assert.Equal(3, rules.TotalItems);
                Assert.Equal(3, rules.Items.Count());

                var items  = rules.Items.ToList();
                var actual = items[0];
                Assert.Equal(policy1.Id, actual.PolicyId);
                Assert.Equal(policy1.Number, actual.PolicyNumber);
                Assert.Equal(policy1.UserId, actual.PolicyUserId);
                Assert.Equal(policy1.CompanyId, actual.PolicyCompanyId);
                Assert.Equal(client1.Client.Id, actual.PolicyClientId);
                Assert.Equal(client1.Client.FirstName, actual.PolicyClientFirstName);
                Assert.Equal(client1.Client.LastName, actual.PolicyClientLastName);
                Assert.Null(actual.CommissionSplitRuleId);
                Assert.Null(actual.CommissionSplitRuleName);
                Assert.Equal(csr1.Id, actual.DefaultCommissionSplitRuleId);
                Assert.Equal(csr1.Name, actual.DefaultCommissionSplitRuleName);

                actual = items[1];
                Assert.Equal(policy2.Id, actual.PolicyId);
                Assert.Equal(policy2.Number, actual.PolicyNumber);
                Assert.Equal(policy2.UserId, actual.PolicyUserId);
                Assert.Equal(policy2.CompanyId, actual.PolicyCompanyId);
                Assert.Equal(client2.Client.Id, actual.PolicyClientId);
                Assert.Equal(client2.Client.FirstName, actual.PolicyClientFirstName);
                Assert.Equal(client2.Client.LastName, actual.PolicyClientLastName);
                Assert.Equal(csrp1.CommissionSplitRuleId, actual.CommissionSplitRuleId);
                Assert.Equal(csr3.Name, actual.CommissionSplitRuleName);
                Assert.Equal(csr2.Id, actual.DefaultCommissionSplitRuleId);
                Assert.Equal(csr2.Name, actual.DefaultCommissionSplitRuleName);

                actual = items[2];
                Assert.Equal(policy3.Id, actual.PolicyId);
                Assert.Null(actual.CommissionSplitRuleId);
                Assert.Null(actual.CommissionSplitRuleName);
                Assert.Equal(csr2.Id, actual.DefaultCommissionSplitRuleId);
                Assert.Equal(csr2.Name, actual.DefaultCommissionSplitRuleName);

                //Check scope
                scope        = TestHelper.GetScopeOptions(user3, Scope.Organisation);
                queryOptions = new CommissionSplitRulePolicyInfoQueryOptions(scope, "", "", 0, 0);
                rules        = await service.GetCommissionSplitRulePolicyInfoList(queryOptions);

                Assert.Single(rules.Items);

                actual = rules.Items.Single();
                Assert.Equal(policy4.Id, actual.PolicyId);
                Assert.Null(actual.CommissionSplitRuleId);
                Assert.Null(actual.DefaultCommissionSplitRuleId);
            }
        }
 public bool SearchAccountByAccountNumber(PolicyEntity policy)
 {
     NavigateToPage();
     sSendKeys(txtAccountNumber, policy.AccountNumber);
     return(sClick(btnSearch));
 }
        public async Task ResolveMappingError_Pass()
        {
            var options = TestHelper.GetDbContext("ResolveMappingError_Pass");

            var user1   = TestHelper.InsertUserDetailed(options);
            var client1 = TestHelper.InsertClient(options, user1.Organisation);

            var statement = TestHelper.InsertCommissionStatement(options, user1.Organisation);

            var company1 = TestHelper.InsertCompany(options);

            var policy1 = new PolicyEntity
            {
                Id        = Guid.NewGuid(),
                CompanyId = company1.Id,
                ClientId  = client1.Client.Id,
                UserId    = user1.User.Id
            };

            var ic1 = new ImportCommission
            {
                PolicyNumber       = "123456",
                CommissionTypeCode = "gap_cover",
                AmountIncludingVAT = "22",
                VAT = "33",

                //These should get ignored as values already exist in db
                FirstName   = "Dean",
                LastName    = "van Niekerk",
                IdNumber    = "8210035032082",
                DateOfBirth = "1982-10-03",
                Initials    = "DJ"
            };

            var err1 = new CommissionErrorEntity
            {
                Id = Guid.NewGuid(),
                CommissionStatementId = statement.Id,
                Data = ic1
            };

            var err2 = new CommissionErrorEntity
            {
                Id = Guid.NewGuid(),
                CommissionStatementId = statement.Id,
                Data = new ImportCommission()
            };

            using (var context = new DataContext(options))
            {
                context.CommissionError.Add(err1);
                context.CommissionError.Add(err2);

                context.Policy.Add(policy1);

                context.SaveChanges();

                var error1 = new CommissionErrorEdit
                {
                    Id = err1.Id,
                    CommissionStatementId = statement.Id,
                    PolicyId         = policy1.Id,
                    ClientId         = policy1.ClientId,
                    CommissionTypeId = Guid.NewGuid(),
                    Data             = ic1
                };

                var auditService                     = new AuditServiceMock();
                var commissionService                = new CommissionService(context, auditService);
                var clientService                    = new ClientService(context, auditService);
                var policyService                    = new PolicyService(context, auditService);
                var commissionSplitService           = new CommissionSplitService(context, auditService);
                var commissionSplitRulePolicyService = new CommissionSplitRulePolicyService(context, commissionSplitService, auditService);
                var service = new CommissionErrorService(context, commissionService, clientService, commissionSplitService, policyService, commissionSplitRulePolicyService, auditService);

                //When
                var scope  = TestHelper.GetScopeOptions(user1);
                var result = await service.ResolveMappingError(scope, error1);

                //Then
                Assert.True(result.Success);

                var actualError = context.CommissionError.Single();

                Assert.Equal(err2.Id, actualError.Id);

                var actual = context.Commission.Single();

                Assert.Equal(error1.PolicyId, actual.PolicyId);
                Assert.Equal(error1.CommissionStatementId, actual.CommissionStatementId);
                Assert.Equal(error1.CommissionTypeId, actual.CommissionTypeId);
                Assert.Equal(22, actual.AmountIncludingVAT);
                Assert.Equal(33, actual.VAT);
                Assert.Equal(error1.Data, actual.SourceData);

                //These details should not have changed
                var actualClient = context.Client.Single();
                Assert.Equal(client1.Client.Initials, actualClient.Initials);
                Assert.Equal(client1.Client.FirstName, actualClient.FirstName);
                Assert.Equal(client1.Client.LastName, actualClient.LastName);
                Assert.Equal(client1.Client.IdNumber, actualClient.IdNumber);
                Assert.Equal(client1.Client.DateOfBirth, actualClient.DateOfBirth);
            }
        }
예제 #19
0
        public async Task GetUserEarningsTypeMonthlyCommissionData_YearMonthFilter()
        {
            var options = TestHelper.GetDbContext("GetUserEarningsTypeMonthlyCommissionData_YearMonthFilter");

            TestHelper.InsertCommissionEarningsTypes(options);

            var comTypeMonth = TestHelper.InsertCommissionType(options, Guid.NewGuid(), CommissionEarningsType.EARNINGS_TYPE_MONTHLY_ANNUITY);

            var user1   = TestHelper.InsertUserDetailed(options);
            var client1 = TestHelper.InsertClient(options, user1.Organisation);

            var now       = DateTime.Now;
            var thisMonth = now;
            var lastMonth = now.AddMonths(-1);
            var lastYear  = lastMonth.AddYears(-1);

            var statement1 = TestHelper.InsertCommissionStatement(options, user1.Organisation, null, thisMonth);
            var statement2 = TestHelper.InsertCommissionStatement(options, user1.Organisation, null, lastMonth);
            var statement3 = TestHelper.InsertCommissionStatement(options, user1.Organisation, null, lastYear);

            var policy1 = new PolicyEntity
            {
                Id        = Guid.NewGuid(),
                Number    = Guid.NewGuid().ToString(),
                CompanyId = statement1.CompanyId,
                ClientId  = client1.Client.Id,
                UserId    = user1.User.Id
            };

            //Given
            var s1_com1 = new CommissionEntity
            {
                Id                    = Guid.NewGuid(),
                PolicyId              = policy1.Id,
                UserId                = user1.User.Id,
                CommissionTypeId      = comTypeMonth.Id,
                AmountIncludingVAT    = 110,
                VAT                   = 10,
                CommissionStatementId = statement1.Id
            };

            var s2_com1 = new CommissionEntity
            {
                Id                    = Guid.NewGuid(),
                PolicyId              = policy1.Id,
                UserId                = user1.User.Id,
                CommissionTypeId      = comTypeMonth.Id,
                AmountIncludingVAT    = 220,
                VAT                   = 20,
                CommissionStatementId = statement2.Id
            };

            var s2_com2 = new CommissionEntity
            {
                Id                    = Guid.NewGuid(),
                PolicyId              = policy1.Id,
                UserId                = user1.User.Id,
                CommissionTypeId      = comTypeMonth.Id,
                AmountIncludingVAT    = 330,
                VAT                   = 30,
                CommissionStatementId = statement2.Id
            };

            var s3_com1 = new CommissionEntity
            {
                Id                    = Guid.NewGuid(),
                PolicyId              = policy1.Id,
                UserId                = user1.User.Id,
                CommissionTypeId      = comTypeMonth.Id,
                AmountIncludingVAT    = 440,
                VAT                   = 40,
                CommissionStatementId = statement3.Id
            };

            using (var context = new DataContext(options))
            {
                context.Policy.Add(policy1);

                context.Commission.Add(s1_com1);
                context.Commission.Add(s2_com1);
                context.Commission.Add(s2_com2);
                context.Commission.Add(s3_com1);

                context.SaveChanges();
            }

            using (var context = new DataContext(options))
            {
                var service = new CommissionReportService(context);

                //When
                var scope        = TestHelper.GetScopeOptions(user1);
                var queryOptions = new UserEarningsTypeMonthlyCommissionQueryOptions(scope, "", "", 0, 0);
                queryOptions.StartDate = new DateTime(lastMonth.Year, lastMonth.Month, 1);
                queryOptions.EndDate   = lastMonth.AddMonths(1).AddDays(-1);
                var items = (await service.GetUserEarningsTypeMonthlyCommissionData(queryOptions)).ToList();

                //Then
                Assert.Single(items);

                var actual = items[0];
                Assert.Equal(CommissionEarningsType.EARNINGS_TYPE_MONTHLY_ANNUITY, actual.CommissionEarningsTypeId);
                Assert.Equal(500, actual.AmountExcludingVAT); //200 + 300
            }
        }
        public async Task ResolveMappingError_Pass_UpdatePolicyAlias()
        {
            var options = TestHelper.GetDbContext("ResolveMappingError_Pass_UpdatePolicyAlias");

            var user1   = TestHelper.InsertUserDetailed(options);
            var client1 = TestHelper.InsertClient(options, user1.Organisation);

            var statement = TestHelper.InsertCommissionStatement(options, user1.Organisation);

            var company1 = TestHelper.InsertCompany(options);

            var policy1 = new PolicyEntity
            {
                Id            = Guid.NewGuid(),
                Number        = Guid.NewGuid().ToString(),
                CompanyId     = company1.Id,
                ClientId      = client1.Client.Id,
                UserId        = user1.User.Id,
                NumberAliases = new List <string>()
                {
                    "987654"
                }                                               //Existing alias
            };

            var ic1 = new ImportCommission
            {
                PolicyNumber       = "123456", // Policy number is different
                CommissionTypeCode = "gap_cover",
                AmountIncludingVAT = "22",
                VAT = "33",
            };

            var err1 = new CommissionErrorEntity
            {
                Id = Guid.NewGuid(),
                CommissionStatementId = statement.Id,
                Data = ic1
            };

            using (var context = new DataContext(options))
            {
                context.CommissionError.Add(err1);

                context.Policy.Add(policy1);

                context.SaveChanges();

                var error1 = new CommissionErrorEdit
                {
                    Id = err1.Id,
                    CommissionStatementId = statement.Id,
                    PolicyId         = policy1.Id,
                    ClientId         = policy1.ClientId,
                    CommissionTypeId = Guid.NewGuid(),
                    Data             = ic1
                };

                var auditService                     = new AuditServiceMock();
                var commissionService                = new CommissionService(context, auditService);
                var clientService                    = new ClientService(context, auditService);
                var policyService                    = new PolicyService(context, auditService);
                var commissionSplitService           = new CommissionSplitService(context, auditService);
                var commissionSplitRulePolicyService = new CommissionSplitRulePolicyService(context, commissionSplitService, auditService);
                var service = new CommissionErrorService(context, commissionService, clientService, commissionSplitService, policyService, commissionSplitRulePolicyService, auditService);

                //When
                var scope  = TestHelper.GetScopeOptions(user1);
                var result = await service.ResolveMappingError(scope, error1);

                //Then
                Assert.True(result.Success);

                var actual = context.Commission.Single();

                Assert.Equal(error1.PolicyId, actual.PolicyId);
                Assert.Equal(error1.Data, actual.SourceData);

                var actualPolicy = context.Policy.Single();
                Assert.Equal(2, actualPolicy.NumberAliases.Count());
                Assert.NotNull(actualPolicy.NumberAliases.SingleOrDefault(n => n == "123456")); //New alias
                Assert.NotNull(actualPolicy.NumberAliases.SingleOrDefault(n => n == "987654")); //Existing alias
            }
        }
예제 #21
0
        public async Task GetUserEarningsTypeMonthlyCommissionData_UserFilter()
        {
            var options = TestHelper.GetDbContext("GetUserEarningsTypeMonthlyCommissionData_UserFilter");

            TestHelper.InsertCommissionEarningsTypes(options);

            var comTypeMonth = TestHelper.InsertCommissionType(options, Guid.NewGuid(), CommissionEarningsType.EARNINGS_TYPE_MONTHLY_ANNUITY);

            var user1   = TestHelper.InsertUserDetailed(options);
            var user2   = TestHelper.InsertUserDetailed(options, user1.Organisation);
            var client1 = TestHelper.InsertClient(options, user1.Organisation);

            var statement1 = TestHelper.InsertCommissionStatement(options, user1.Organisation);

            var policy1 = new PolicyEntity
            {
                Id        = Guid.NewGuid(),
                Number    = Guid.NewGuid().ToString(),
                CompanyId = statement1.CompanyId,
                ClientId  = client1.Client.Id,
                UserId    = user1.User.Id
            };

            var policy2 = new PolicyEntity
            {
                Id        = Guid.NewGuid(),
                Number    = Guid.NewGuid().ToString(),
                CompanyId = statement1.CompanyId,
                ClientId  = client1.Client.Id,
                UserId    = user2.User.Id
            };

            //Given
            var com1 = new CommissionEntity
            {
                Id                    = Guid.NewGuid(),
                PolicyId              = policy1.Id,
                UserId                = user1.User.Id,
                CommissionTypeId      = comTypeMonth.Id,
                AmountIncludingVAT    = 110,
                VAT                   = 10,
                CommissionStatementId = statement1.Id
            };

            var com2 = new CommissionEntity
            {
                Id                    = Guid.NewGuid(),
                PolicyId              = policy2.Id,
                UserId                = user2.User.Id,
                CommissionTypeId      = comTypeMonth.Id,
                AmountIncludingVAT    = 220,
                VAT                   = 20,
                CommissionStatementId = statement1.Id
            };

            using (var context = new DataContext(options))
            {
                context.Policy.Add(policy1);
                context.Policy.Add(policy2);

                context.Commission.Add(com1);
                context.Commission.Add(com2);

                context.SaveChanges();
            }

            using (var context = new DataContext(options))
            {
                var service = new CommissionReportService(context);

                //When
                var scope        = TestHelper.GetScopeOptions(user1);
                var queryOptions = new UserEarningsTypeMonthlyCommissionQueryOptions(scope, "", "", 0, 0);
                queryOptions.UserId.Add(user2.User.Id);
                var items = (await service.GetUserEarningsTypeMonthlyCommissionData(queryOptions)).ToList();

                //Then
                Assert.Single(items);

                var actual = items[0];
                Assert.Equal(CommissionEarningsType.EARNINGS_TYPE_MONTHLY_ANNUITY, actual.CommissionEarningsTypeId);
                Assert.Equal(200, actual.AmountExcludingVAT);
            }
        }
예제 #22
0
 public async Task Create(PolicyEntity policyEntity, VehicleEntity vehicleEntity, ServiceEntity serviceEntity)
 {
     _serviceEntity.Add(serviceEntity);
     _vehicleEntity.Update(vehicleEntity);
 }
예제 #23
0
        public async Task GetUserCompanyMonthlyCommissionData_UserFilter()
        {
            var options = TestHelper.GetDbContext("GetUserCompanyMonthlyCommissionData_UserFilter");

            var companyId1 = Guid.NewGuid();
            var companyId2 = Guid.NewGuid();

            var user1   = TestHelper.InsertUserDetailed(options);
            var user2   = TestHelper.InsertUserDetailed(options, user1.Organisation);
            var client1 = TestHelper.InsertClient(options, user1.Organisation);
            var client2 = TestHelper.InsertClient(options, user1.Organisation);

            var statement1 = TestHelper.InsertCommissionStatement(options, user1.Organisation);
            var statement2 = TestHelper.InsertCommissionStatement(options, user1.Organisation);

            var user3      = TestHelper.InsertUserDetailed(options);
            var client3    = TestHelper.InsertClient(options, user3.Organisation);
            var statement3 = TestHelper.InsertCommissionStatement(options, user3.Organisation);

            var usr1_policy1 = new PolicyEntity
            {
                Id        = Guid.NewGuid(),
                Number    = Guid.NewGuid().ToString(),
                CompanyId = statement1.CompanyId,
                ClientId  = client1.Client.Id,
                UserId    = user1.User.Id
            };

            var usr2_policy1 = new PolicyEntity
            {
                Id        = Guid.NewGuid(),
                CompanyId = statement2.CompanyId,
                ClientId  = client2.Client.Id,
                UserId    = user2.User.Id
            };

            var usr3_policy1 = new PolicyEntity
            {
                Id        = Guid.NewGuid(),
                CompanyId = statement3.CompanyId,
                ClientId  = client3.Client.Id,
                UserId    = user3.User.Id
            };

            //Given
            var usr1_policy1_comm1 = new CommissionEntity
            {
                Id                    = Guid.NewGuid(),
                PolicyId              = usr1_policy1.Id,
                UserId                = user1.User.Id,
                CommissionTypeId      = Guid.NewGuid(),
                AmountIncludingVAT    = 110,
                VAT                   = 10,
                CommissionStatementId = statement1.Id
            };

            var usr2_policy1_comm1 = new CommissionEntity
            {
                Id                    = Guid.NewGuid(),
                PolicyId              = usr2_policy1.Id,
                UserId                = user2.User.Id,
                CommissionTypeId      = Guid.NewGuid(),
                AmountIncludingVAT    = 220,
                VAT                   = 20,
                CommissionStatementId = statement2.Id
            };

            var usr2_policy1_comm2 = new CommissionEntity
            {
                Id                    = Guid.NewGuid(),
                PolicyId              = usr2_policy1.Id,
                UserId                = user2.User.Id,
                CommissionTypeId      = Guid.NewGuid(),
                AmountIncludingVAT    = 330,
                VAT                   = 30,
                CommissionStatementId = statement2.Id
            };

            var usr2_policy1_comm3 = new CommissionEntity
            {
                Id                    = Guid.NewGuid(),
                PolicyId              = usr2_policy1.Id,
                UserId                = user2.User.Id,
                CommissionTypeId      = Guid.NewGuid(),
                AmountIncludingVAT    = 440,
                VAT                   = 40,
                CommissionStatementId = statement2.Id
            };

            var usr3_policy1_comm1 = new CommissionEntity
            {
                Id                    = Guid.NewGuid(),
                PolicyId              = usr3_policy1.Id,
                UserId                = user3.User.Id,
                CommissionTypeId      = Guid.NewGuid(),
                AmountIncludingVAT    = 550,
                VAT                   = 50,
                CommissionStatementId = statement3.Id
            };

            using (var context = new DataContext(options))
            {
                context.Policy.Add(usr1_policy1);
                context.Policy.Add(usr2_policy1);
                context.Policy.Add(usr3_policy1);

                context.Commission.Add(usr1_policy1_comm1);
                context.Commission.Add(usr2_policy1_comm1);
                context.Commission.Add(usr2_policy1_comm2);
                context.Commission.Add(usr2_policy1_comm3);
                context.Commission.Add(usr3_policy1_comm1);

                context.SaveChanges();
            }

            using (var context = new DataContext(options))
            {
                var service = new CommissionReportService(context);

                //When
                var scope        = TestHelper.GetScopeOptions(user1);
                var queryOptions = new UserCompanyMonthlyCommissionQueryOptions(scope, "", "", 0, 0);
                queryOptions.UserId.Add(user2.User.Id);
                var items = (await service.GetUserCompanyMonthlyCommissionData(queryOptions)).ToList();

                //Then
                Assert.Single(items);

                var actual = items[0];
                Assert.Equal(statement2.CompanyId, actual.CompanyId);
                Assert.Equal(900, actual.AmountExcludingVAT); //200 + 300 + 400
            }
        }
 public PolicyWithClaimsDomainModel(PolicyEntity policyEntity) : base(policyEntity)
 {
     LoadClaims(policyEntity.Claims);
 }
예제 #25
0
        public async Task GetPastRevenueCommissionData_Basic()
        {
            var options = TestHelper.GetDbContext("GetPastRevenueCommissionData_Basic");

            TestHelper.InsertCommissionEarningsTypes(options);

            var comTypeMonth  = TestHelper.InsertCommissionType(options, Guid.NewGuid(), CommissionEarningsType.EARNINGS_TYPE_MONTHLY_ANNUITY);
            var comTypeAnnual = TestHelper.InsertCommissionType(options, Guid.NewGuid(), CommissionEarningsType.EARNINGS_TYPE_ANNUAL_ANNUITY);

            var user1   = TestHelper.InsertUserDetailed(options);
            var user2   = TestHelper.InsertUserDetailed(options, user1.Organisation);
            var client1 = TestHelper.InsertClient(options, user1.Organisation);
            var client2 = TestHelper.InsertClient(options, user1.Organisation);

            var policyTypeId1 = Guid.NewGuid();
            var policyTypeId2 = Guid.NewGuid();

            var statement1 = TestHelper.InsertCommissionStatement(options, user1.Organisation);
            var statement2 = TestHelper.InsertCommissionStatement(options, user1.Organisation);
            var statement4 = TestHelper.InsertCommissionStatement(options, user1.Organisation, statement1.CompanyId, statement1.Date.AddMonths(-1));

            var user3      = TestHelper.InsertUserDetailed(options);
            var client3    = TestHelper.InsertClient(options, user3.Organisation);
            var statement3 = TestHelper.InsertCommissionStatement(options, user3.Organisation);

            var usr1_policy1 = new PolicyEntity
            {
                Id           = Guid.NewGuid(),
                Number       = Guid.NewGuid().ToString(),
                CompanyId    = statement1.CompanyId,
                ClientId     = client1.Client.Id,
                UserId       = user1.User.Id,
                PolicyTypeId = policyTypeId1,
            };

            var usr2_policy1 = new PolicyEntity
            {
                Id           = Guid.NewGuid(),
                CompanyId    = statement1.CompanyId,
                ClientId     = client2.Client.Id,
                UserId       = user2.User.Id,
                PolicyTypeId = policyTypeId1,
            };

            var usr2_policy2 = new PolicyEntity
            {
                Id           = Guid.NewGuid(),
                CompanyId    = statement1.CompanyId,
                ClientId     = client2.Client.Id,
                UserId       = user2.User.Id,
                PolicyTypeId = policyTypeId2,
            };

            var usr3_policy1 = new PolicyEntity
            {
                Id           = Guid.NewGuid(),
                CompanyId    = statement3.CompanyId,
                ClientId     = client3.Client.Id,
                UserId       = user3.User.Id,
                PolicyTypeId = policyTypeId1,
            };

            //Given
            var usr1_policy1_comm1 = new CommissionEntity
            {
                Id                    = Guid.NewGuid(),
                PolicyId              = usr1_policy1.Id,
                UserId                = user1.User.Id,
                CommissionTypeId      = comTypeMonth.Id,
                AmountIncludingVAT    = 110,
                VAT                   = 10,
                CommissionStatementId = statement1.Id
            };

            var usr2_policy1_comm1 = new CommissionEntity
            {
                Id                    = Guid.NewGuid(),
                PolicyId              = usr2_policy1.Id,
                UserId                = user2.User.Id,
                CommissionTypeId      = comTypeMonth.Id,
                AmountIncludingVAT    = 220,
                VAT                   = 20,
                CommissionStatementId = statement1.Id
            };

            var usr2_policy1_comm2 = new CommissionEntity
            {
                Id                    = Guid.NewGuid(),
                PolicyId              = usr2_policy1.Id,
                UserId                = user2.User.Id,
                CommissionTypeId      = comTypeMonth.Id,
                AmountIncludingVAT    = 330,
                VAT                   = 30,
                CommissionStatementId = statement1.Id
            };

            var usr2_policy1_comm3 = new CommissionEntity
            {
                Id                    = Guid.NewGuid(),
                PolicyId              = usr2_policy1.Id,
                UserId                = user2.User.Id,
                CommissionTypeId      = comTypeAnnual.Id,
                AmountIncludingVAT    = 440,
                VAT                   = 40,
                CommissionStatementId = statement1.Id
            };

            var usr2_policy1_comm4 = new CommissionEntity
            {
                Id                    = Guid.NewGuid(),
                PolicyId              = usr2_policy1.Id,
                UserId                = user2.User.Id,
                CommissionTypeId      = comTypeAnnual.Id,
                AmountIncludingVAT    = 660,
                VAT                   = 60,
                CommissionStatementId = statement4.Id
            };

            var usr2_policy2_comm5 = new CommissionEntity
            {
                Id                    = Guid.NewGuid(),
                PolicyId              = usr2_policy2.Id,
                UserId                = user2.User.Id,
                CommissionTypeId      = comTypeAnnual.Id,
                AmountIncludingVAT    = 770,
                VAT                   = 70,
                CommissionStatementId = statement4.Id
            };

            var usr3_policy1_comm1 = new CommissionEntity
            {
                Id                    = Guid.NewGuid(),
                PolicyId              = usr3_policy1.Id,
                UserId                = user3.User.Id,
                CommissionTypeId      = comTypeMonth.Id,
                AmountIncludingVAT    = 550,
                VAT                   = 50,
                CommissionStatementId = statement3.Id
            };

            using (var context = new DataContext(options))
            {
                context.Policy.Add(usr1_policy1);
                context.Policy.Add(usr2_policy1);
                context.Policy.Add(usr3_policy1);
                context.Policy.Add(usr2_policy2);

                context.Commission.Add(usr1_policy1_comm1);
                context.Commission.Add(usr2_policy1_comm1);
                context.Commission.Add(usr2_policy1_comm2);
                context.Commission.Add(usr2_policy1_comm3);
                context.Commission.Add(usr3_policy1_comm1);
                context.Commission.Add(usr2_policy1_comm4);
                context.Commission.Add(usr2_policy2_comm5);

                context.SaveChanges();
            }

            using (var context = new DataContext(options))
            {
                var service = new CommissionReportService(context);

                //When
                var scope        = TestHelper.GetScopeOptions(user1);
                var queryOptions = new PastRevenueCommissionQueryOptions(scope, "", "", 0, 0);
                var items        = (await service.GetPastRevenueCommissionData(queryOptions)).ToList();

                //Then
                Assert.Equal(4, items.Count());

                var actual = items[0];
                Assert.Equal(CommissionEarningsType.EARNINGS_TYPE_MONTHLY_ANNUITY, actual.CommissionEarningsTypeId);
                Assert.Equal(statement1.CompanyId, actual.CompanyId);
                Assert.Equal(policyTypeId1, actual.PolicyTypeId);
                Assert.Equal(statement1.DateYear, actual.DateYear);
                Assert.Equal(statement1.DateMonth, actual.DateMonth);
                Assert.Equal(600, actual.AmountExcludingVAT); //100 + 200 + 300

                actual = items[1];
                Assert.Equal(CommissionEarningsType.EARNINGS_TYPE_ANNUAL_ANNUITY, actual.CommissionEarningsTypeId);
                Assert.Equal(statement1.CompanyId, actual.CompanyId);
                Assert.Equal(policyTypeId1, actual.PolicyTypeId);
                Assert.Equal(statement1.DateYear, actual.DateYear);
                Assert.Equal(statement1.DateMonth, actual.DateMonth);
                Assert.Equal(400, actual.AmountExcludingVAT);

                actual = items[2];
                Assert.Equal(CommissionEarningsType.EARNINGS_TYPE_ANNUAL_ANNUITY, actual.CommissionEarningsTypeId);
                Assert.Equal(statement4.CompanyId, actual.CompanyId);
                Assert.Equal(policyTypeId1, actual.PolicyTypeId);
                Assert.Equal(statement4.DateYear, actual.DateYear);
                Assert.Equal(statement4.DateMonth, actual.DateMonth);
                Assert.Equal(600, actual.AmountExcludingVAT);

                actual = items[3];
                Assert.Equal(CommissionEarningsType.EARNINGS_TYPE_ANNUAL_ANNUITY, actual.CommissionEarningsTypeId);
                Assert.Equal(statement4.CompanyId, actual.CompanyId);
                Assert.Equal(policyTypeId2, actual.PolicyTypeId);
                Assert.Equal(statement4.DateYear, actual.DateYear);
                Assert.Equal(statement4.DateMonth, actual.DateMonth);
                Assert.Equal(700, actual.AmountExcludingVAT);

                //Check scope
                scope        = TestHelper.GetScopeOptions(user3);
                queryOptions = new PastRevenueCommissionQueryOptions(scope, "", "", 0, 0);
                items        = (await service.GetPastRevenueCommissionData(queryOptions)).ToList();

                Assert.Single(items);

                actual = items[0];
                Assert.Equal(CommissionEarningsType.EARNINGS_TYPE_MONTHLY_ANNUITY, actual.CommissionEarningsTypeId);
                Assert.Equal(500, actual.AmountExcludingVAT);
            }
        }
예제 #26
0
        public async Task GetPolicy_CheckScope()
        {
            var options = TestHelper.GetDbContext("GetPolicy_CheckScope");

            var org1 = new OrganisationEntity {
                Id = Guid.NewGuid(), Name = "Org 1"
            };
            var org2 = new OrganisationEntity {
                Id = Guid.NewGuid(), Name = "Org 2"
            };

            var branch1 = new BranchEntity {
                Id = Guid.NewGuid(), OrganisationId = org1.Id, Name = "Branch 1"
            };
            var branch2 = new BranchEntity {
                Id = Guid.NewGuid(), OrganisationId = org1.Id, Name = "Branch 2"
            };
            var branch3 = new BranchEntity {
                Id = Guid.NewGuid(), OrganisationId = org2.Id, Name = "Branch 3"
            };

            var user1 = new UserEntity {
                Id = Guid.NewGuid(), BranchId = branch1.Id
            };
            var user2 = new UserEntity {
                Id = Guid.NewGuid(), BranchId = branch1.Id
            };
            var user3 = new UserEntity {
                Id = Guid.NewGuid(), BranchId = branch2.Id
            };
            var user4 = new UserEntity {
                Id = Guid.NewGuid(), BranchId = branch3.Id
            };

            var client1 = new ClientEntity {
                Id = Guid.NewGuid(), OrganisationId = org1.Id
            };
            var client2 = new ClientEntity {
                Id = Guid.NewGuid(), OrganisationId = org2.Id
            };

            var policy1 = new PolicyEntity {
                Id = Guid.NewGuid(), ClientId = client1.Id, UserId = user1.Id
            };
            var policy2 = new PolicyEntity {
                Id = Guid.NewGuid(), ClientId = client1.Id, UserId = user2.Id
            };
            var policy3 = new PolicyEntity {
                Id = Guid.NewGuid(), ClientId = client1.Id, UserId = user3.Id
            };
            var policy4 = new PolicyEntity {
                Id = Guid.NewGuid(), ClientId = client2.Id, UserId = user4.Id
            };
            var policy5 = new PolicyEntity {
                Id = Guid.NewGuid(), ClientId = client1.Id, UserId = user1.Id
            };


            using (var context = new DataContext(options))
            {
                context.Organisation.Add(org1);

                context.Branch.Add(branch1);
                context.Branch.Add(branch2);

                context.Users.Add(user1);
                context.Users.Add(user2);
                context.Users.Add(user3);
                context.Users.Add(user4);

                context.Client.Add(client1);
                context.Client.Add(client2);

                context.Policy.Add(policy1);
                context.Policy.Add(policy2);
                context.Policy.Add(policy3);
                context.Policy.Add(policy4);
                context.Policy.Add(policy5);

                context.SaveChanges();
            }

            using (var context = new DataContext(options))
            {
                var auditService = new AuditServiceMock();
                var service      = new PolicyService(context, auditService);

                //When

                //In scope (org 1 -> policy 1)
                var scope  = new ScopeOptions(org1.Id, branch1.Id, user1.Id, Scope.Organisation);
                var policy = await service.GetPolicy(scope, policy1.Id);

                Assert.Equal(policy1.Id, policy.Id);

                //In scope (org 1 -> policy 3)
                scope  = new ScopeOptions(org1.Id, branch1.Id, user1.Id, Scope.Organisation);
                policy = await service.GetPolicy(scope, policy3.Id);

                Assert.Equal(policy3.Id, policy.Id);

                //Out of scope (org 2 -> policy 1)
                scope  = new ScopeOptions(org2.Id, branch3.Id, user4.Id, Scope.Organisation);
                policy = await service.GetPolicy(scope, policy1.Id);

                Assert.Null(policy);

                //In scope (branch 1 -> policy 1)
                scope  = new ScopeOptions(org1.Id, branch1.Id, user1.Id, Scope.Branch);
                policy = await service.GetPolicy(scope, policy1.Id);

                Assert.Equal(policy1.Id, policy.Id);

                //In scope (branch 1 -> policy 2)
                scope  = new ScopeOptions(org1.Id, branch1.Id, user1.Id, Scope.Branch);
                policy = await service.GetPolicy(scope, policy2.Id);

                Assert.Equal(policy2.Id, policy.Id);

                //Out of scope (branch 2 -> policy 1)
                scope  = new ScopeOptions(org1.Id, branch2.Id, user3.Id, Scope.Branch);
                policy = await service.GetPolicy(scope, policy1.Id);

                Assert.Null(policy);

                //Out of scope (branch 3 -> policy 1)
                scope  = new ScopeOptions(org2.Id, branch3.Id, user4.Id, Scope.Branch);
                policy = await service.GetPolicy(scope, policy1.Id);

                Assert.Null(policy);

                //In scope (user 1 -> policy 1)
                scope  = new ScopeOptions(org1.Id, branch1.Id, user1.Id, Scope.User);
                policy = await service.GetPolicy(scope, policy1.Id);

                Assert.Equal(policy1.Id, policy.Id);

                //Out of scope (user 2 -> policy 1)
                scope  = new ScopeOptions(org1.Id, branch1.Id, user2.Id, Scope.User);
                policy = await service.GetPolicy(scope, policy1.Id);

                Assert.Null(policy);
            }
        }
예제 #27
0
        public async Task GetCommissionLapseData_Basic()
        {
            var options = TestHelper.GetDbContext("GetCommissionLapseData_Basic");

            TestHelper.InsertCommissionEarningsTypes(options);

            var comTypeMonth = TestHelper.InsertCommissionType(options, Guid.NewGuid(), CommissionEarningsType.EARNINGS_TYPE_MONTHLY_ANNUITY);
            var company      = TestHelper.InsertCompany(options);

            var user1   = TestHelper.InsertUserDetailed(options);
            var client1 = TestHelper.InsertClient(options, user1.Organisation);

            var now          = DateTime.UtcNow;
            var lastMonth    = DateTime.UtcNow.AddMonths(-1);
            var twoMonthsAgo = DateTime.UtcNow.AddMonths(-2);

            var statement1 = TestHelper.InsertCommissionStatement(options, user1.Organisation, company.Id, now);
            var statement2 = TestHelper.InsertCommissionStatement(options, user1.Organisation, company.Id, lastMonth);
            var statement4 = TestHelper.InsertCommissionStatement(options, user1.Organisation, company.Id, twoMonthsAgo);

            var user2      = TestHelper.InsertUserDetailed(options);
            var client2    = TestHelper.InsertClient(options, user2.Organisation);
            var statement3 = TestHelper.InsertCommissionStatement(options, user2.Organisation, company.Id, lastMonth);

            var usr1_policy1 = new PolicyEntity
            {
                Id           = Guid.NewGuid(),
                Number       = Guid.NewGuid().ToString(),
                CompanyId    = company.Id,
                ClientId     = client1.Client.Id,
                UserId       = user1.User.Id,
                PolicyTypeId = Guid.NewGuid(),
            };

            var usr1_policy2 = new PolicyEntity
            {
                Id           = Guid.NewGuid(),
                Number       = Guid.NewGuid().ToString(),
                CompanyId    = company.Id,
                ClientId     = client1.Client.Id,
                UserId       = user1.User.Id,
                PolicyTypeId = Guid.NewGuid(),
            };

            var usr2_policy1 = new PolicyEntity
            {
                Id           = Guid.NewGuid(),
                CompanyId    = company.Id,
                ClientId     = client2.Client.Id,
                UserId       = user2.User.Id,
                PolicyTypeId = Guid.NewGuid(),
            };

            //This month commmission
            var usr1_policy1_comm1 = new CommissionEntity
            {
                Id                    = Guid.NewGuid(),
                PolicyId              = usr1_policy1.Id,
                UserId                = user1.User.Id,
                CommissionTypeId      = comTypeMonth.Id,
                AmountIncludingVAT    = 110,
                VAT                   = 10,
                CommissionStatementId = statement1.Id
            };

            //Last month Commission
            var usr1_policy1_comm2 = new CommissionEntity
            {
                Id                    = Guid.NewGuid(),
                PolicyId              = usr1_policy1.Id,
                UserId                = user1.User.Id,
                CommissionTypeId      = comTypeMonth.Id,
                AmountIncludingVAT    = 220,
                VAT                   = 20,
                CommissionStatementId = statement2.Id
            };

            var usr1_policy2_comm1 = new CommissionEntity
            {
                Id                    = Guid.NewGuid(),
                PolicyId              = usr1_policy2.Id,
                UserId                = user1.User.Id,
                CommissionTypeId      = comTypeMonth.Id,
                AmountIncludingVAT    = 330,
                VAT                   = 30,
                CommissionStatementId = statement2.Id
            };

            //Two months ago commission
            var usr1_policy2_comm2 = new CommissionEntity
            {
                Id                    = Guid.NewGuid(),
                PolicyId              = usr1_policy2.Id,
                UserId                = user1.User.Id,
                CommissionTypeId      = comTypeMonth.Id,
                AmountIncludingVAT    = 440,
                VAT                   = 40,
                CommissionStatementId = statement4.Id
            };

            //Last month commission - different company
            var usr2_policy1_comm1 = new CommissionEntity
            {
                Id                    = Guid.NewGuid(),
                PolicyId              = usr2_policy1.Id,
                UserId                = user2.User.Id,
                CommissionTypeId      = comTypeMonth.Id,
                AmountIncludingVAT    = 660,
                VAT                   = 60,
                CommissionStatementId = statement3.Id
            };

            using (var context = new DataContext(options))
            {
                context.Policy.Add(usr1_policy1);
                context.Policy.Add(usr1_policy2);
                context.Policy.Add(usr2_policy1);

                context.Commission.Add(usr1_policy1_comm1);
                context.Commission.Add(usr1_policy1_comm2);
                context.Commission.Add(usr1_policy2_comm1);
                context.Commission.Add(usr1_policy2_comm2);
                context.Commission.Add(usr2_policy1_comm1);

                context.SaveChanges();
            }

            using (var context = new DataContext(options))
            {
                var service = new CommissionReportService(context);

                //When
                var scope        = TestHelper.GetScopeOptions(user1);
                var queryOptions = new CommissionLapseQueryOptions(scope, "", "", 0, 0);
                var result       = await service.GetCommissionLapseData(queryOptions);

                //Then
                var items = result.Items.ToList();
                Assert.Single(items);

                var actual = items[0];
                Assert.Equal(usr1_policy2.Id, actual.PolicyId);
                Assert.Equal(client1.Client.Id, actual.ClientId);
                Assert.Equal(usr1_policy2.Number, actual.Number);
                Assert.Equal(usr1_policy2.CompanyId, actual.CompanyId);
                Assert.Equal(usr1_policy2.UserId, actual.UserId);
                Assert.Equal(usr1_policy2.Premium, actual.Premium);
                Assert.Equal(usr1_policy2.StartDate, actual.StartDate);
                Assert.Equal(usr1_policy2.PolicyTypeId, actual.PolicyTypeId);
                Assert.Equal(client1.Client.LastName, actual.ClientLastName);
                Assert.Equal(client1.Client.Initials, actual.ClientInitials);
                Assert.Equal(company.Name, actual.CompanyName);

                //Check scope
                scope        = TestHelper.GetScopeOptions(user2);
                queryOptions = new CommissionLapseQueryOptions(scope, "", "", 0, 0);
                result       = (await service.GetCommissionLapseData(queryOptions));

                items = result.Items.ToList();

                Assert.Single(items);

                actual = items[0];
                Assert.Equal(usr2_policy1.Id, actual.PolicyId);
            }
        }
예제 #28
0
        public async Task UpdatePolicy()
        {
            var options = TestHelper.GetDbContext("UpdatePolicy");

            var user1   = TestHelper.InsertUserDetailed(options);
            var client1 = TestHelper.InsertClient(options, user1.Organisation);

            var user2 = TestHelper.InsertUserDetailed(options);

            //Given
            var policyEntity1 = new PolicyEntity
            {
                Id                  = Guid.NewGuid(),
                CompanyId           = Guid.NewGuid(),
                ClientId            = client1.Client.Id,
                UserId              = user1.User.Id,
                Number              = "123465",
                StartDate           = DateTime.Now,
                Premium             = 500,
                PolicyTypeId        = Guid.NewGuid(),
                PolicyProductTypeId = Guid.NewGuid(),
                PolicyProductId     = Guid.NewGuid(),
                IsActive            = true,
            };

            using (var context = new DataContext(options))
            {
                context.Policy.Add(policyEntity1);

                context.SaveChanges();
            }

            var policy1 = new PolicyEdit
            {
                Id                  = policyEntity1.Id,
                CompanyId           = Guid.NewGuid(),
                ClientId            = client1.Client.Id,
                UserId              = user1.User.Id,
                Number              = "528547",
                StartDate           = DateTime.Now.AddDays(-10),
                Premium             = 600,
                PolicyTypeId        = Guid.NewGuid(),
                PolicyProductTypeId = Guid.NewGuid(),
                PolicyProductId     = Guid.NewGuid(),
                IsActive            = false,
            };

            using (var context = new DataContext(options))
            {
                var auditService = new AuditServiceMock();
                var service      = new PolicyService(context, auditService);

                //When
                var scopeOptions = TestHelper.GetScopeOptions(user1);
                var result       = await service.UpdatePolicy(scopeOptions, policy1);

                //Then
                Assert.True(result.Success);

                var actual = await context.Policy.FindAsync(policyEntity1.Id);

                Assert.Equal(policy1.Id, actual.Id);
                Assert.Equal(policy1.ClientId, actual.ClientId);
                Assert.Equal(policy1.CompanyId, actual.CompanyId);
                Assert.Equal(policy1.Number, actual.Number);
                Assert.Equal(policy1.StartDate, actual.StartDate);
                Assert.Equal(policy1.Premium, actual.Premium);
                Assert.Equal(policy1.PolicyTypeId, actual.PolicyTypeId);
                Assert.Equal(policy1.PolicyProductTypeId, actual.PolicyProductTypeId);
                Assert.Equal(policy1.PolicyProductId, actual.PolicyProductId);
                Assert.Equal(policy1.IsActive, actual.IsActive);


                //Out of scope
                scopeOptions = TestHelper.GetScopeOptions(user2);
                result       = await service.UpdatePolicy(scopeOptions, policy1);

                Assert.False(result.Success);
                Assert.Equal("'User' does not exist.", result.ValidationFailures.First().ErrorMessage);
            }
        }
예제 #29
0
 private string GetPolicyAction(PolicyEntity policy)
 {
     return(policy.Set ? "EditPolicySet" : "EditPolicy");
 }
예제 #30
0
        public async Task GetClientRevenueData()
        {
            var options = await CreateDatabaseSqlServer();

            var company = TestHelper.InsertCompany(options);

            var commissionType1 = TestHelper.InsertCommissionType(options, PolicyType.POLICY_TYPE_INVESTMENT, CommissionEarningsType.EARNINGS_TYPE_ANNUAL_ANNUITY);
            var commissionType2 = TestHelper.InsertCommissionType(options, PolicyType.POLICY_TYPE_INVESTMENT, CommissionEarningsType.EARNINGS_TYPE_MONTHLY_ANNUITY);
            var commissionType3 = TestHelper.InsertCommissionType(options, PolicyType.POLICY_TYPE_INVESTMENT, CommissionEarningsType.EARNINGS_TYPE_ONCE_OFF);
            var commissionType4 = TestHelper.InsertCommissionType(options, PolicyType.POLICY_TYPE_INVESTMENT, CommissionEarningsType.EARNINGS_TYPE_LIFE_FIRST_YEARS);

            var user1   = TestHelper.InsertUserDetailed(options);
            var client1 = TestHelper.InsertClient(options, user1.Organisation);

            var thisMonth = DateTime.Now.Date;
            var lastMonth = thisMonth.AddMonths(-1);

            var policy1 = new PolicyEntity
            {
                Id        = Guid.NewGuid(),
                Number    = Guid.NewGuid().ToString(),
                CompanyId = company.Id,
                ClientId  = client1.Client.Id,
                UserId    = user1.User.Id
            };

            //Statement 1 - this month
            //          ANNUAL_ANNUITY  |   MONTHLY_ANNUITY |   ONCE_OFF    |   LIFE_FIRST_YEARS
            //com1      100                 0                   0               0
            //com2      0                   200                 0               0
            //com3      0                   0                   300             0
            //com4      0                   0                   0               400

            var cs1 = new CommissionStatementEntity
            {
                Id                 = Guid.NewGuid(),
                CompanyId          = company.Id,
                AmountIncludingVAT = 0,
                VAT                = 0,
                Date               = thisMonth,
                Processed          = true,
                OrganisationId     = user1.Organisation.Id
            };

            var commission1 = new CommissionEntity
            {
                Id                    = Guid.NewGuid(),
                PolicyId              = policy1.Id,
                UserId                = policy1.UserId,
                CommissionTypeId      = commissionType1.Id,
                AmountIncludingVAT    = 110,
                VAT                   = 10,
                CommissionStatementId = cs1.Id
            };

            var commission2 = new CommissionEntity
            {
                Id                    = Guid.NewGuid(),
                PolicyId              = policy1.Id,
                UserId                = policy1.UserId,
                CommissionTypeId      = commissionType2.Id,
                AmountIncludingVAT    = 220,
                VAT                   = 20,
                CommissionStatementId = cs1.Id
            };

            var commission3 = new CommissionEntity
            {
                Id                    = Guid.NewGuid(),
                PolicyId              = policy1.Id,
                UserId                = policy1.UserId,
                CommissionTypeId      = commissionType3.Id,
                AmountIncludingVAT    = 330,
                VAT                   = 30,
                CommissionStatementId = cs1.Id
            };

            var commission4 = new CommissionEntity
            {
                Id                    = Guid.NewGuid(),
                PolicyId              = policy1.Id,
                UserId                = policy1.UserId,
                CommissionTypeId      = commissionType4.Id,
                AmountIncludingVAT    = 440,
                VAT                   = 40,
                CommissionStatementId = cs1.Id
            };

            //Statement 2 - last month
            //          ANNUAL_ANNUITY  |   MONTHLY_ANNUITY |   ONCE_OFF    |   LIFE_FIRST_YEARS
            //com5      500                 0                   0               0
            //com6      0                   600                 0               0
            //com7      0                   0                   700             0
            //com8      0                   0                   0               800

            var cs2 = new CommissionStatementEntity
            {
                Id                 = Guid.NewGuid(),
                CompanyId          = company.Id,
                AmountIncludingVAT = 0,
                VAT                = 0,
                Date               = lastMonth,
                Processed          = true,
                OrganisationId     = user1.Organisation.Id
            };

            var commission5 = new CommissionEntity
            {
                Id                    = Guid.NewGuid(),
                PolicyId              = policy1.Id,
                UserId                = policy1.UserId,
                CommissionTypeId      = commissionType1.Id,
                AmountIncludingVAT    = 500,
                VAT                   = 0,
                CommissionStatementId = cs2.Id
            };

            var commission6 = new CommissionEntity
            {
                Id                    = Guid.NewGuid(),
                PolicyId              = policy1.Id,
                UserId                = policy1.UserId,
                CommissionTypeId      = commissionType2.Id,
                AmountIncludingVAT    = 600,
                VAT                   = 0,
                CommissionStatementId = cs2.Id
            };

            var commission7 = new CommissionEntity
            {
                Id                    = Guid.NewGuid(),
                PolicyId              = policy1.Id,
                UserId                = policy1.UserId,
                CommissionTypeId      = commissionType3.Id,
                AmountIncludingVAT    = 700,
                VAT                   = 0,
                CommissionStatementId = cs2.Id
            };

            var commission8 = new CommissionEntity
            {
                Id                    = Guid.NewGuid(),
                PolicyId              = policy1.Id,
                UserId                = policy1.UserId,
                CommissionTypeId      = commissionType4.Id,
                AmountIncludingVAT    = 800,
                VAT                   = 0,
                CommissionStatementId = cs2.Id
            };

            //Statement 3 - 2 months age
            //          ANNUAL_ANNUITY  |   MONTHLY_ANNUITY |   ONCE_OFF    |   LIFE_FIRST_YEARS
            //com9      900                 0                   0               0
            //com10     0                   1000                0               0
            //com11     0                   0                   1100            0
            //com12     0                   0                   0               1200

            var cs3 = new CommissionStatementEntity
            {
                Id                 = Guid.NewGuid(),
                CompanyId          = company.Id,
                AmountIncludingVAT = 0,
                VAT                = 0,
                Date               = lastMonth.AddMonths(-1),
                Processed          = true,
                OrganisationId     = user1.Organisation.Id
            };

            var commission9 = new CommissionEntity
            {
                Id                    = Guid.NewGuid(),
                PolicyId              = policy1.Id,
                UserId                = policy1.UserId,
                CommissionTypeId      = commissionType1.Id,
                AmountIncludingVAT    = 900,
                VAT                   = 0,
                CommissionStatementId = cs3.Id
            };

            var commission10 = new CommissionEntity
            {
                Id                    = Guid.NewGuid(),
                PolicyId              = policy1.Id,
                UserId                = policy1.UserId,
                CommissionTypeId      = commissionType2.Id,
                AmountIncludingVAT    = 1000,
                VAT                   = 0,
                CommissionStatementId = cs3.Id
            };

            var commission11 = new CommissionEntity
            {
                Id                    = Guid.NewGuid(),
                PolicyId              = policy1.Id,
                UserId                = policy1.UserId,
                CommissionTypeId      = commissionType3.Id,
                AmountIncludingVAT    = 1100,
                VAT                   = 0,
                CommissionStatementId = cs3.Id
            };

            var commission12 = new CommissionEntity
            {
                Id                    = Guid.NewGuid(),
                PolicyId              = policy1.Id,
                UserId                = policy1.UserId,
                CommissionTypeId      = commissionType4.Id,
                AmountIncludingVAT    = 1200,
                VAT                   = 0,
                CommissionStatementId = cs3.Id
            };

            using (var context = new DataContext(options))
            {
                context.Policy.Add(policy1);

                context.CommissionStatement.Add(cs1);
                context.Commission.Add(commission1);
                context.Commission.Add(commission2);
                context.Commission.Add(commission3);
                context.Commission.Add(commission4);

                context.CommissionStatement.Add(cs2);
                context.Commission.Add(commission5);
                context.Commission.Add(commission6);
                context.Commission.Add(commission7);
                context.Commission.Add(commission8);

                context.CommissionStatement.Add(cs3);
                context.Commission.Add(commission9);
                context.Commission.Add(commission10);
                context.Commission.Add(commission11);
                context.Commission.Add(commission12);

                context.SaveChanges();
            }

            using (var context = new DataContext(options))
            {
                var service = new CommissionReportService(context);

                //When
                var scope        = TestHelper.GetScopeOptions(user1);
                var queryOptions = new ClientRevenueQueryOptions(scope, "", "", 0, 0, $"YearEnding={thisMonth.Year};MonthEnding={thisMonth.Month}");
                var data         = await service.GetClientRevenueData(queryOptions);

                //Then
                var results = data.Items.ToList();
                Assert.Equal(1, data.TotalItems);

                Assert.Single(results);

                var actual = results[0];
                Assert.Equal(client1.Client.Id, actual.ClientId);
                Assert.Equal(client1.Client.LastName, actual.ClientLastName);
                Assert.Equal(client1.Client.Initials, actual.ClientInitials);
                Assert.Equal(client1.Client.DateOfBirth, actual.ClientDateOfBirth);

                Assert.Equal(200, actual.MonthlyAnnuityMonth);  // com2
                Assert.Equal(125, actual.AnnualAnnuityAverage); // (100 + 500 + 900) / 12
                Assert.Equal(325, actual.TotalMonthlyEarnings); // 125 + 200

                Assert.Equal(2100, actual.OnceOff);             //300 + 700 + 1100
                Assert.Equal(2400, actual.LifeFirstYears);      //400 + 800 + 1200

                Assert.Equal(7800, actual.GrandTotal);          // add up all commission entries

                Assert.Equal(0, actual.AllocationsCount);
            }
        }
예제 #31
0
        internal static DocumentEntity ConvertToDocumentEntity(IContentItem fileInfo, IPolicyResponseObject uro)
        {
            if (fileInfo == null)
                return null;

            DocumentEntity documentEntity = new DocumentEntity();
            List<PolicySetEventEntity> policyEvents = new List<PolicySetEventEntity>();

            // Can't actually do much populating if this is null
            documentEntity.ContentType = fileInfo.Type;
            documentEntity.Name = fileInfo.Name;

            InitialiseFileEntityMetadata(documentEntity, fileInfo);

            if (fileInfo.PolicySetCollection != null)
            {
                foreach (IPolicySetResponse policySetInfo in fileInfo.PolicySetCollection)
                {
                    PolicySetEventEntity PolicySet = new PolicySetEventEntity();
                    PolicySet.EventDate = policySetInfo.Date;
                    PolicySet.PolicySetName = policySetInfo.Name;
                    List<PolicyEntity> PolicyEntities = new List<PolicyEntity>();

                    if (policySetInfo.PolicyReportCollection != null)
                    {
                        foreach (IPolicyResponse policyInfo in policySetInfo.PolicyReportCollection)
                        {
                            if (!ProEntityConverter.ShouldAudit(policyInfo))
                                continue;

                            PolicyEntity PolicyEntity = new PolicyEntity();

                            PolicyEntity.PolicyName = policyInfo.Name;
                            PolicyEntity.Triggered = policyInfo.Triggered;

                            List<ExpressionEntity> expressionList = new List<ExpressionEntity>();
                            if (policyInfo.ExpressionCollection != null)
                            {
                                foreach (IExpressionResponse expressionInfo in policyInfo.ExpressionCollection)
                                {
                                    if (!expressionInfo.Triggered)
                                        continue;

                                    ExpressionEntity expression = new ExpressionEntity();
                                    expression.ExpressionName = expressionInfo.Name;
                                    expression.ExpressionRating = expressionInfo.Rating;
                                    expression.ExpressionType = "CONDITION";
                                    expression.ExpressionTriggered = expressionInfo.Triggered;

                                    // IMPORTANT!! these not put to the audit trail as is storing personal info. bad.
                                    List<ExpressionPropertyEntity> expressionProperty = new List<ExpressionPropertyEntity>();
                                    expression.ExpressionProperties = expressionProperty.ToArray();

                                    expressionList.Add(expression);
                                }
                            }

                            if (policyInfo.Routing != null)
                            {
                                ExpressionEntity routing = new ExpressionEntity();
                                routing.ExpressionName = policyInfo.Routing.Name;
                                routing.ExpressionRating = policyInfo.Routing.Rating;
                                routing.ExpressionType = "ROUTING";
                                routing.ExpressionTriggered = true;

                                // IMPORTANT!! these not put to the audit trail as is storing personal info. bad.
                                List<ExpressionPropertyEntity> expressionProperty = new List<ExpressionPropertyEntity>();
                                routing.ExpressionProperties = expressionProperty.ToArray();

                                expressionList.Add(routing);
                            }
                            PolicyEntity.Expressions = expressionList.ToArray();

                            List<PolicyPropertyEntity> policyPropList = new List<PolicyPropertyEntity>();
                            if (policyInfo.Properties != null)
                            {
                                foreach (KeyValuePair<string, string> de in policyInfo.Properties)
                                {
                                    PolicyPropertyEntity prop = new PolicyPropertyEntity();
                                    prop.Name = de.Key;
                                    prop.PropertyValue = de.Value;
                                    policyPropList.Add(prop);
                                }
                            }
                            PolicyEntity.PolicyProperties = policyPropList.ToArray();

                            List<ActionEntity> acList = new List<ActionEntity>();
                            if (policyInfo.ActionCollection != null)
                            {
                                foreach (IPolicyResponseAction actionInfo in policyInfo.ActionCollection)
                                {
                                    ActionEntity ae = ConvertActionEntity(actionInfo);

                                    if (ae != null)
                                        acList.Add(ae);
                                }
                            }
                            PolicyEntity.Actions = acList.ToArray();
                            PolicyEntities.Add(PolicyEntity);
                        }
                    }
                    PolicySet.Policies = PolicyEntities.ToArray();
                    policyEvents.Add(PolicySet);
                }
            }
            documentEntity.DocumentEvents = policyEvents.ToArray();
            return documentEntity;
        }
 public PolicyWithClaimsDomainModel(PolicyEntity policyEntity)
     : base(policyEntity)
 {
     LoadClaims(policyEntity.Claims);
 }
 public void AddPolicy(PolicyEntity policy)
 {
     using var context = ContextFactory.CreateDbContext(ConnectionString);
     context.Policies.Add(policy);
     context.SaveChanges();
 }