コード例 #1
0
 protected void EnsureValidity(IValidationState validationState, string message)
 {
     if (!validationState.IsValid)
     {
         var errors = validationState.AllResultDescriptions.Select(rd => rd);
         throw new HttpException(HttpStatusCode.BadRequest, message, errors);
     }
 }
コード例 #2
0
 public AccountController(IFormsAuthentication authService,
                          IValidationService validationService,
                          IMembershipService membershipService,
                          IValidationState validationState)
 {
     this.formsAuthentication = authService;
     this.validationService   = validationService;
     this.membershipService   = membershipService;
     this.captchaValidator    = new DefaultCaptchaValidator(validationState)
     {
         // This is disabled so the functional tests do not fail.
         // In real world application this option can be managed by
         // build process.
         Enabled = false
     };
 }
コード例 #3
0
ファイル: AccountController.cs プロジェクト: sxliupeng/DDD
        public ActionResult ChangePassword(ChangePasswordViewModel model)
        {
            if (ModelState.IsValid)
            {
                IValidationState validationState = memberService.ChangePassword(HttpContext.User.Identity.Name, model.OldPassword, model.NewPassword);
                if (!validationState.IsValid)
                {
                    ModelState.MergeError(validationState);
                }
                else
                {
                    return(RedirectToAction("ChangePasswordSuccess"));
                }
            }

            return(View(model));
        }
コード例 #4
0
ファイル: AccountController.cs プロジェクト: sxliupeng/DDD
        public ActionResult LogOn(LogonViewModel model)
        {
            if (ModelState.IsValid)
            {
                IValidationState validationState = memberService.ValidatePassword(model.MemberName, model.Password);

                if (!validationState.IsValid)
                {
                    ModelState.MergeError(validationState);
                }
                else
                {
                    FormsAuthenticationService.SignIn(model.MemberName, model.RememberMe);
                    return(RedirectToAction("Index", "Home"));
                }
            }

            return(View(model));
        }
コード例 #5
0
        public ActionResult EditProfile(EditUserProfileViewModel model)
        {
            if (ModelState.IsValid)
            {
                var user = userService.GetUser(HttpContext.User.Identity.Name);
                user = Mapper.Map <EditUserProfileViewModel, Models.User>(model, user);
                IValidationState validationState = userService.UpdateUser(user);
                if (!validationState.IsValid)
                {
                    ModelState.MergeError(validationState);
                }
                else
                {
                    return(RedirectToAction("Index"));
                }
            }

            return(View(model));
        }
コード例 #6
0
ファイル: AccountController.cs プロジェクト: sxliupeng/DDD
        public ActionResult Register(RegisterViewModel model)
        {
            if (ModelState.IsValid)
            {
                Guid             memberId;
                IValidationState memberValidationState = memberService.CreateMember(model.MemberName, model.Password, out memberId);
                userService.CreateUser(new Models.User()
                {
                    Id = memberId, UserName = model.MemberName
                });
                if (!memberValidationState.IsValid)
                {
                    ModelState.MergeError(memberValidationState);
                }
                else
                {
                    FormsAuthenticationService.SignIn(model.MemberName, false);
                    return(RedirectToAction("Index", "Home"));
                }
            }

            return(View(model));
        }
コード例 #7
0
 public ServiceResponse(TEntity entity, TContract contract, IValidationState validationState)
 {
     Entity          = entity;
     Contract        = contract;
     ValidationState = validationState;
 }
コード例 #8
0
 public ValidationService(IValidationState validationState, IValidatorFactory validatorFactory)
 {
     m_validationState  = validationState;
     m_validatorFactory = validatorFactory ?? ValidatorFactoryCache.Instance;
 }
コード例 #9
0
 public ValidationService(IValidationState validationState)
     : this(validationState, null)
 {
 }
コード例 #10
0
 public RunOnceService(ICache cache, TimeSpan period, IValidationState validationState)
 {
     m_cache           = cache;
     m_period          = period;
     m_validationState = validationState;
 }
コード例 #11
0
 protected IServiceResponse <TEntity, TContract> Response <TEntity, TContract>(TEntity entity, TContract contract, IValidationState validationState)
     where TEntity : class
     where TContract : class
 {
     return(ServiceResponse <TEntity, TContract> .Create(entity, contract, validationState));
 }
コード例 #12
0
 protected IServiceResponse <TEntity, TEntity> Response <TEntity>(TEntity entity, IValidationState validationState)
     where TEntity : class
 {
     return(Response(entity, entity, validationState));
 }
コード例 #13
0
 public ViewStateValidator()
 {
     failures = new Dictionary <string, ValidationFailure>();
     State    = new ValidationState(failures);
 }
コード例 #14
0
 public DefaultCaptchaValidator(IValidationState state)
 {
     m_state = state;
     Enabled = true;
 }