Ejemplo n.º 1
0
        /// <summary> 检查 <paramref name="email"/> 是否可以作为新账号的 <see cref="IAccount.Email"/>. </summary>
        /// <param name="accountManager">The <see cref="IAccountManager"/></param>
        /// <param name="email">The email address to be checked.</param>
        /// <param name="allowReuse">If an email address can be registered by multiple users.</param>
        public static EmailAvailableResult Check(IAccountManager accountManager, String email, bool allowReuse)
        {
            if (accountManager == null) throw new ArgumentNullException("accountManager");
            if (String.IsNullOrEmpty(email)) throw new ArgumentException("email is null or empty.", "email");

            if (!allowReuse)
            {
                var users = accountManager.FetchAccountsByEmail(email);
                if (users.Any())
                {
                    String errorMessage = String.Format("Email [{0}] is already registered.", email);
                    return new EmailAvailableResult(false, errorMessage, users);
                }
            }
            return new EmailAvailableResult(true, null, null);
        }