当前位置: 首页>>代码示例>>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;未经允许,请勿转载。