Exemplo n.º 1
0
        /// <summary>
        /// Return Domain instance by name or create it if it is missing
        /// </summary>
        /// <param name="domain">IDomain instance</param>
        /// <param name="name">Domain name</param>
        /// <param name="cancellationToken">Cancellation token</param>
        /// <returns>Domain Id (existing or created)</returns>
        public static async Task <string> GetOrCreateAsync(this IDomain domain, string name, CancellationToken?cancellationToken = null)
        {
            var existingDomain = domain.GetByName(name);

            if (existingDomain != null)
            {
                return(existingDomain.Id);
            }
            return(await domain.CreateAsync(new CreateDomainData {
                Name = name
            }, cancellationToken));
        }