public async Task <IActionResult> Insert([FromBody] CommissionEdit commission)
        {
            var scope = AuthenticationService.GetScope(User);

            var result = await CommissionService.InsertCommission(scope, commission);

            if (!result.Success)
            {
                return(BadRequest(result.ValidationFailures));
            }

            return(Ok(result));
        }
        public async Task InsertCommission()
        {
            var options = TestHelper.GetDbContext("InsertCommission");

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

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

            var user3 = TestHelper.InsertUserDetailed(options);

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

            //Given
            var commission1 = new CommissionEdit
            {
                Id                    = Guid.NewGuid(),
                PolicyId              = policy1.Id,
                UserId                = policy1.UserId,
                CommissionTypeId      = Guid.NewGuid(),
                AmountIncludingVAT    = 99,
                VAT                   = 14,
                CommissionStatementId = Guid.NewGuid(),
                SourceData            = new Model.Commission.Model.ImportCommission.ImportCommission()
                {
                    PolicyNumber       = "123",
                    AmountIncludingVAT = "50",
                    VAT = "10"
                }
            };

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

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

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

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

                var actual = await context.Commission.FindAsync(((CommissionEdit)result.Tag).Id);

                Assert.Equal(commission1.Id, actual.Id);
                Assert.Equal(commission1.PolicyId, actual.PolicyId);
                Assert.Equal(commission1.CommissionTypeId, actual.CommissionTypeId);
                Assert.Equal(commission1.AmountIncludingVAT, actual.AmountIncludingVAT);
                Assert.Equal(commission1.VAT, actual.VAT);
                Assert.Equal(commission1.CommissionStatementId, actual.CommissionStatementId);
                Assert.Equal(commission1.SourceData, actual.SourceData);

                //Out of scope
                scopeOptions = TestHelper.GetScopeOptions(user2, Scope.User);
                result       = await service.InsertCommission(scopeOptions, commission1);

                Assert.False(result.Success);

                scopeOptions = TestHelper.GetScopeOptions(user3, Scope.Organisation);
                result       = await service.InsertCommission(scopeOptions, commission1);

                Assert.False(result.Success);
            }
        }