當前位置: 首頁>>代碼示例>>C#>>正文


C# User.GetValidationContainer方法代碼示例

本文整理匯總了C#中Model.User.GetValidationContainer方法的典型用法代碼示例。如果您正苦於以下問題:C# User.GetValidationContainer方法的具體用法?C# User.GetValidationContainer怎麽用?C# User.GetValidationContainer使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Model.User的用法示例。


在下文中一共展示了User.GetValidationContainer方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: SaveOrUpdate

        public IValidationContainer<User> SaveOrUpdate(User user)
        {
            var container = user.GetValidationContainer();
            if (!container.IsValid)
                return container;

            userRepository.SaveOrUpdate(user);
            _unitOfWork.Commit();

            return container;
        }
開發者ID:rodmjay,項目名稱:ScaffR-Generated,代碼行數:11,代碼來源:UserAccountService.cs

示例2: Authenticate

        protected internal virtual IValidationContainer<User> Authenticate(User account, string password,
            int failedLoginCount, TimeSpan lockoutDuration)
        {
            var container = account.GetValidationContainer();
            if (!container.IsValid)
                return container;

            var result = account.Authenticate(password, failedLoginCount, lockoutDuration);

            if (!result)
                container.ValidationErrors.Add("", new List<string>() {"Unable to authenticate user"});

            this.userRepository.SaveOrUpdate(account);
            _unitOfWork.Commit();

            Tracing.Verbose(String.Format("[UserAccountService.Authenticate] authentication outcome: {0}, {1}, {2}",
                account.Tenant, account.Username, result ? "Successful Login" : "Failed Login"));

            return container;
        }
開發者ID:rodmjay,項目名稱:ScaffR-Generated,代碼行數:20,代碼來源:UserAccountService.cs

示例3: CreateAccount

        public virtual IValidationContainer<User> CreateAccount(string tenant, string username, string password,
            string email, string firstName, string lastName, string phone, string address)
        {
            Tracing.Information(String.Format("[UserAccountService.CreateAccount] called: {0}, {1}, {2}", tenant,
                username, email));

            if (_settings.EmailIsUsername)
            {
                username = email;
            }

            if (!_settings.MultiTenant)
            {
                tenant = _settings.DefaultTenant;
            }

            if (String.IsNullOrWhiteSpace(tenant)) throw new ArgumentException("tenant");
            if (String.IsNullOrWhiteSpace(username)) throw new ArgumentException("username");
            if (String.IsNullOrWhiteSpace(password)) throw new ArgumentException("password");
            if (String.IsNullOrWhiteSpace(email)) throw new ArgumentException("email");
            if (String.IsNullOrWhiteSpace(email)) throw new ArgumentException("firstName");
            if (String.IsNullOrWhiteSpace(email)) throw new ArgumentException("lastName");
            if (String.IsNullOrWhiteSpace(email)) throw new ArgumentException("phone");
            if (String.IsNullOrWhiteSpace(email)) throw new ArgumentException("address");

            ValidatePassword(tenant, username, password);

            var validator = new EmailAddressAttribute();
            if (!validator.IsValid(email))
            {
                Tracing.Verbose(
                    String.Format("[UserAccountService.CreateAccount] Email validation failed: {0}, {1}, {2}", tenant,
                        username, email));

                throw new ValidationException("Email is invalid.");
            }

            if (UsernameExists(tenant, username))
            {
                Tracing.Verbose(String.Format("[UserAccountService.CreateAccount] Username already exists: {0}, {1}",
                    tenant, username));

                var msg = _settings.EmailIsUsername ? "Email" : "Username";
                throw new ValidationException(msg + " already in use.");
            }

            if (EmailExists(tenant, username))
            {
                Tracing.Verbose(String.Format("[UserAccountService.CreateAccount] Email already exists: {0}, {1}, {2}",
                    tenant, username, email));

                throw new ValidationException("Email already in use.");
            }

            var account = new User(tenant, username, password, email)
            {
                FirstName = firstName,
                LastName = lastName,
                Address = address,
                PhoneNumber = phone
            };

            var validation = account.GetValidationContainer();
            if (!validation.IsValid)
                return validation;

            this.userRepository.SaveOrUpdate(account);

            if (this.notificationService != null)
            {
                if (_settings.RequireAccountVerification)
                {
                    this.notificationService.SendAccountCreate(account);
                }
                else
                {
                    this.notificationService.SendAccountVerified(account);
                }
            }

            _unitOfWork.Commit();
            return validation;
        }
開發者ID:rodmjay,項目名稱:ScaffR-Generated,代碼行數:83,代碼來源:UserAccountService.cs


注:本文中的Model.User.GetValidationContainer方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。