public async Task <IActionResult> Post([FromBody] Models.Account Account)
        {
            var profile = await accountRepository.Profiles
                          .SingleOrDefaultAsync(x => x.ProfileID == Account.ProfileID);

            if (profile == null)
            {
                return(BadRequest($"Cannot add account to Profile ({Account.ProfileID}). Profile is in an invalid state."));
            }

            accountRepository.Accounts.Add(Account);
            await accountRepository.SaveChangesAsync();

            return(Created("{id:guid}", Account));
        }
        public async Task Handle(ProfileUpdatedIntegrationEvent @event)
        {
            var profile = await accountRepository.Profiles.SingleOrDefaultAsync(x => x.ProfileID == @event.ProfileID);

            if (@event.KYCStatus == "ACTIVE")
            {
                profile.AccountCreationEnabled = true;
            }
            else
            {
                profile.AccountCreationEnabled = false;
            }

            accountRepository.Profiles.Attach(profile);

            await accountRepository.SaveChangesAsync();
        }
        public async Task Handle(ProfileCreatedIntegrationEvent @event)
        {
            bool newProfile = false;

            var profile = await accountRepository.Profiles.SingleOrDefaultAsync(x => x.ProfileID == @event.ProfileID);

            if (profile == null)
            {
                newProfile = true;

                profile = new Models.Profile
                {
                    ProfileID = @event.ProfileID
                };
            }

            if (@event.KYCStatus == "ACTIVE")
            {
                profile.AccountCreationEnabled = true;
            }
            else
            {
                profile.AccountCreationEnabled = false;
            }

            if (newProfile)
            {
                accountRepository.Profiles.Add(profile);
            }
            else
            {
                accountRepository.Profiles.Attach(profile);
            }

            await accountRepository.SaveChangesAsync();
        }