コード例 #1
0
        public ActionResult CreatePost(CreatePostModel model, string subName = null)
        {
            SubWrapped sub = null;

            if (!string.IsNullOrEmpty(subName))
            {
                sub = _subWrapper.Wrap(_subDao.GetSubByName(subName), _userContext.CurrentUser);
                if (sub == null) throw new HttpException(404, "sub not found");
            }

            model.Sub = sub;

            var response = _commandBus.Send<CreatePost, CreatePostResponse>(new CreatePost
            {
                CreatedByUserId = _userContext.CurrentUser.Id,
                IpAddress = Request.UserHostAddress,
                Title = model.Title,
                Url = model.Url,
                Content = model.Content,
                PostType = model.PostType,
                SubName = model.SubName,
                NotifyReplies = model.NotifyReplies
            });

            if (!string.IsNullOrEmpty(response.Error))
            {
                ModelState.AddModelError(string.Empty, response.Error);
                return View(model);
            }

            if (!response.PostId.HasValue)
            {
                // TODO: log
                ModelState.AddModelError(string.Empty, "Unknown error creating post.");
                return View(model);
            }

            // todo: success message

            return Redirect(Url.Post(model.SubName, response.PostId.Value, response.Title));
        }
コード例 #2
0
        public ActionResult CreatePost(CreatePostModel model)
        {
            var response = _commandBus.Send<CreatePost, CreatePostResponse>(new CreatePost
            {
                CreatedByUserId = _userContext.CurrentUser.Id,
                IpAddress = Request.UserHostAddress,
                Title = model.Title,
                Url = model.Url,
                Content = model.Content,
                PostType = model.PostType,
                SubName = model.SubName,
                NotifyReplies = model.NotifyReplies
            });

            if (!string.IsNullOrEmpty(response.Error))
            {
                ModelState.AddModelError(string.Empty, response.Error);
                return View(model);
            }

            if (!response.PostId.HasValue)
            {
                // TODO: log
                ModelState.AddModelError(string.Empty, "Unknown error creating post.");
                return View(model);
            }

            // todo: success message

            return Redirect(Url.Post(model.SubName, response.PostId.Value, response.Title));
        }