private async Task <PersonConsent> MapFromServerAsync(PersonConsentTable source,
                                                              CancellationToken token = default(CancellationToken))
        {
            InternalContract.RequireNotNull(source, nameof(source));
            InternalContract.RequireValidated(source, nameof(source));
            var serverConsentTask = _storage.Consent.ReadAsync(source.ConsentId, token);
            var serverPersonTask  = _storage.Person.ReadAsync(source.PersonId, token);
            var serverConsent     = await serverConsentTask;
            var serverPerson      = await serverPersonTask;

            if (serverConsent == null)
            {
                throw new FulcrumNotFoundException($"Could not find consent with id {source.ConsentId}");
            }
            if (serverPerson == null)
            {
                throw new FulcrumNotFoundException($"Could not find person with id {source.PersonId}");
            }
            var target = new PersonConsent
            {
                Id              = MapperHelper.MapToType <string, Guid>(source.Id),
                ConsentId       = MapperHelper.MapToType <string, Guid>(source.ConsentId),
                PersonName      = serverPerson.Name,
                ConsentName     = serverConsent.Name,
                Etag            = source.Etag,
                PersonId        = MapperHelper.MapToType <string, Guid>(source.PersonId),
                HasGivenConsent = source.HasGivenConsent
            };

            FulcrumAssert.IsValidated(target);
            return(target);
        }
        private PersonConsentTable MapToServer(PersonConsentCreate source)
        {
            InternalContract.RequireNotNull(source, nameof(source));
            InternalContract.RequireValidated(source, nameof(source));
            var target = new PersonConsentTable
            {
                HasGivenConsent = source.HasGivenConsent,
                PersonId        = MapperHelper.MapToType <Guid, string>(source.PersonId),
                ConsentId       = MapperHelper.MapToType <Guid, string>(source.ConsentId),
            };

            FulcrumAssert.IsValidated(target);
            return(target);
        }
        private async Task CreatePersonConsentsAsync(Guid personId, bool profiling, bool marketing)
        {
            var personConsent = new PersonConsentTable
            {
                ConsentId       = _profilingConsentId,
                PersonId        = personId,
                HasGivenConsent = profiling
            };
            await _storage.PersonConsent.CreateAsync(personConsent);

            personConsent = new PersonConsentTable
            {
                ConsentId       = _marketingConsentId,
                PersonId        = personId,
                HasGivenConsent = marketing
            };
            await _storage.PersonConsent.CreateAsync(personConsent);
        }