Exemplo n.º 1
0
        private dynamic DeletePost(DeletePostCommand deletePostCommand)
        {
            _commandInvokerFactory.Handle <DeletePostCommand, CommandResult>(deletePostCommand);
            string returnURL = Request.Headers.Referrer;

            return(Response.AsRedirect(returnURL));
        }
Exemplo n.º 2
0
        private dynamic ChangePassword(ChangePasswordCommand command)
        {
            var commandResult = _commandInvokerFactory.Handle <ChangePasswordCommand, CommandResult>(command);

            if (commandResult.Success)
            {
                AddMessage("密码已经被成功修改", "success");

                return(View["ChangePassword"]);
            }

            AddMessage("修改密码过程中发生问题", "warning");

            return(View["ChangePassword"]);
        }
Exemplo n.º 3
0
        private dynamic CreateNewPost(NewPostCommand command)
        {
            var commandResult = _commandInvokerFactory.Handle <NewPostCommand, CommandResult>(command);

            if (commandResult.Success)
            {
                AddMessage("Post was successfully added", "info");

                return(this.Context.GetRedirect("/admin/posts"));
            }

            AddMessage("Something went wrong while saving new post", "warn");

            return(View["New", command]);
        }
Exemplo n.º 4
0
        public dynamic ReturnAddComment(dynamic p)
        {
            var postModel = _viewFactory.Get <BlogPostDetailsBindingModel, BlogPostDetailsViewModel>(new BlogPostDetailsBindingModel {
                Permalink = p.titleslug
            });

            if (postModel != null)
            {
                var newCommentCommand = this.BindAndValidate <NewCommentCommand>();
                if (!ModelValidationResult.IsValid)
                {
                    return(HttpStatusCode.UnprocessableEntity);
                }
                newCommentCommand.SpamShield = this.Bind <SpamShield>();
                newCommentCommand.IPAddress  = Request.UserHostAddress;
                newCommentCommand.PostId     = postModel.BlogPost.Id;
                var result = _commandInvokerFactory.Handle <NewCommentCommand, CommandResult>(newCommentCommand);
                if (result.Success)
                {
                    var url = string.Format(
                        "{0}#comment_{1}",
                        postModel.BlogPost.GetLink(),
                        newCommentCommand.Id
                        );
                    return(Response.AsRedirect(url));
                }
            }
            return(HttpStatusCode.NotFound);
        }
Exemplo n.º 5
0
        public dynamic LoginUser(LoginCommand loginCommand)
        {
            var commandResult = _commandInvoker.Handle <LoginCommand, LoginCommandResult>(loginCommand);

            if (commandResult.Success)
            {
                var cookie   = FormsAuthentication.CreateAuthCookie(commandResult.Author.Id);
                var response = Context.GetRedirect(loginCommand.ReturnUrl ?? "/admin");
                response.AddCookie(cookie);
                return(response);
            }

            return(View["LoginPage", commandResult.GetErrors()]);
        }
Exemplo n.º 6
0
        private dynamic ChangePassword(ChangePasswordCommand command)
        {
            var commandResult = _commandInvokerFactory.Handle <ChangePasswordCommand, ITmeze.Core.Commands.CommandResult>(command);

            if (commandResult.Success)
            {
                AddMessage("Password was changed", "info");

                return(this.Context.GetRedirect("/admin"));
            }

            AddMessage("There was a problem saving password", "error");

            return(View["ChangePassword"]);
        }
Exemplo n.º 7
0
        public dynamic LoginUser(LoginCommand loginCommand)
        {
            if (!ModelValidationResult.IsValid)
            {
                return(View["LoginPage", new[] { "请正确输入Email和密码" }]);
            }

            var commandResult = _commandInvoker.Handle <LoginCommand, LoginCommandResult>(loginCommand);

            if (commandResult.Success)
            {
                var cookie   = FormsAuthentication.CreateAuthCookie(commandResult.Author.Id);
                var response = Context.GetRedirect(loginCommand.ReturnUrl ?? "/mz-admin");
                return(response.WithCookie(cookie));
            }

            return(View["LoginPage", commandResult.GetErrors()]);
        }
Exemplo n.º 8
0
        /// <summary>
        /// 检查是否已存在后台管理账号
        /// </summary>
        /// <returns>存在返回true,不存在返回false</returns>
        private bool CheckAccount(ICommandInvokerFactory commandInvokerFactory)
        {
            var commandResult = commandInvokerFactory.Handle <UserRegisterCheckCommand, CommandResult>(new UserRegisterCheckCommand());

            return(commandResult.IsSuccess);
        }
Exemplo n.º 9
0
        private dynamic DeleteJob(DeleteJobCommand command)
        {
            var commandResult = commandInvokerFactory.Handle <DeleteJobCommand, CommandResult>(command);

            return(Response.AsJson(new { success = commandResult.Success, message = commandResult.GetErrors() }));
        }