public async Task <CreatedResult> CreateTenant([FromBody] TenantCreateDataRepresentation data, string id)
        {
            (await _tenantStore.GetByCode(data.Code))
            .ThrowInvalidDataExceptionIfNotNull("Invalid tenant");     // already exists

            var ownerId = User.GetId();

            var tenantId = await _tenantStore.Create(
                ownerId,
                TrustDefaults.KnownHomeResourceId,
                data
                .ThrowInvalidDataExceptionIfNull("Invalid tenant create data")
                .FromRepresentation(),
                Permission.FullControl | Permission.Owner,
                CallerCollectionRights.Tenant);


            //////////////////////////
            // Add user to tenant
            // ==================
            //

            await _tenantStore.IncludeUser(
                tenantId,
                ownerId,
                Permission.Get | Permission.Owner,
                CallerCollectionRights.Tenant);

            return(ownerId
                   .MakeUserTenantUri(tenantId, Url)
                   .MakeCreated());
        }
        /// <summary>
        ///     Reverse map with validation across-the-wire representation into in-memory representation
        /// </summary>
        public static TenantCreateData FromRepresentation(this TenantCreateDataRepresentation tenant)
        {
            return(new TenantCreateData
            {
                Name = tenant.Name
                       .ThrowInvalidDataExceptionIfNullOrWhiteSpace("A tenant requires a name"),

                // TODO: perhaps the code needs validation as per a subdomain for SaaS business
                Code = tenant.Code,
                Description = tenant.Description
            });
        }