コード例 #1
0
        /// <summary>
        /// Creates an <see cref="TenancyResult"/> indicating a failed tenancy operation, with a list of <paramref name="errors"/> if applicable.
        /// </summary>
        /// <param name="errors">An optional array of <see cref="TenancyError"/>s which caused the operation to fail.</param>
        /// <returns>An <see cref="TenancyResult"/> indicating a failed tenancy operation, with a list of <paramref name="errors"/> if applicable.</returns>
        public static TenancyResult Failed(params TenancyError[] errors)
        {
            var result = new TenancyResult {
                Succeeded = false
            };

            if (errors != null)
            {
                result._errors.AddRange(errors);
            }
            return(result);
        }
コード例 #2
0
 /// <summary>
 /// Should return <see cref="TenancyResult.Success"/> if validation is successful. This is
 /// called before saving the tenant via Create or Update.
 /// </summary>
 /// <param name="tenant">The tenant</param>
 /// <returns>A <see cref="TenancyResult"/> representing whether validation was successful.</returns>
 protected async Task<TenancyResult> ValidateTenantAsync(TTenant tenant)
 {
     var errors = new List<TenancyError>();
     foreach (var v in TenantValidators)
     {
         var result = await v.ValidateAsync(this, tenant);
         if (!result.Succeeded)
         {
             errors.AddRange(result.Errors);
         }
     }
     if (errors.Count > 0)
     {
         Logger.LogWarning(13, "Tenant {tenantId} validation failed: {errors}.", await GetTenantIdAsync(tenant), string.Join(";", errors.Select(e => e.Code)));
         return TenancyResult.Failed(errors.ToArray());
     }
     return TenancyResult.Success;
 }