public async Task <IActionResult> Update(Guid commissionId, [FromBody] CommissionEdit commission)
        {
            commission.Id = commissionId;

            var scope = AuthenticationService.GetScope(User);

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

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

            return(Ok(result));
        }
        private void btnSave_Click(object sender, EventArgs e)
        {
            var unitOfWork        = new UnitOfWork(_context);
            var commissionService = new CommissionService(unitOfWork, unitOfWork);

            if (CommissionName == "")
            {
                MessageBox.Show("Enter name!");
                return;
            }

            try
            {
                if (_commission == null)
                {
                    _commission   = commissionService.CreateCommission(CommissionName, ProfileId, PresidentId);
                    _commissionId = _commission.Id;
                    unitOfWork.Commit();
                    MessageBox.Show("Successfully added commission!");
                    Close();
                }
                else
                {
                    _commission.Name = CommissionName;
                    var selectedPresident = (Member)cmbxPresident.SelectedItem;
                    commissionService.SetPresident(_commission.Id, selectedPresident);
                    commissionService.UpdateCommission(_commission);
                    unitOfWork.Commit();
                    MessageBox.Show("Successfully update commission!");
                    Close();
                }
            }
            catch (Exception)
            {
                MessageBox.Show("Something was wrong!");
                unitOfWork.Rollback();
            }
        }
        public async Task UpdateCommission()
        {
            var options = TestHelper.GetDbContext("UpdateCommission");

            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
            };

            var commission = new CommissionEntity
            {
                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.Commission.Add(commission);

                context.SaveChanges();
            }

            var commission1 = new CommissionEdit
            {
                Id                    = commission.Id,
                PolicyId              = policy1.Id,
                UserId                = policy1.UserId,
                CommissionTypeId      = Guid.NewGuid(),
                AmountIncludingVAT    = 109,
                VAT                   = 15,
                CommissionStatementId = commission.CommissionStatementId,
                SourceData            = new Model.Commission.Model.ImportCommission.ImportCommission()
                {
                    PolicyNumber       = "123",
                    AmountIncludingVAT = "55",
                    VAT = "11"
                }
            };

            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.UpdateCommission(scopeOptions, commission1);

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

                var actual = await context.Commission.FindAsync(commission.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.UpdateCommission(scopeOptions, commission1);

                Assert.False(result.Success);

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

                Assert.False(result.Success);
            }
        }