Ejemplo n.º 1
0
        public string CreateAnswer(PostAnswerBm bm, string appUserId)
        {
            var user = this.userService.GetUserByAppId(appUserId);

            if (user == null)
            {
                return(null);
            }

            Post postEntity = this.forumService.GetPostById(bm.Id);

            if (postEntity == null)
            {
                return(null);
            }

            Post originalPost = null;

            if (postEntity.IsQuestion)
            {
                originalPost = postEntity;
            }
            else
            {
                originalPost = postEntity.Original;
            }

            var answer = new Post()
            {
                Author     = user,
                AuthorId   = user.Id,
                Categories = originalPost.Categories,
                Tags       = originalPost.Tags,
                Content    = bm.Content,
                Parent     = postEntity,
                ParentId   = postEntity.Id,
                OriginalId = originalPost.Id,
                Original   = originalPost
            };

            originalPost.ModifiedOn = answer.CreatedOn;
            postEntity.Children.Add(answer);

            bool isAdded = this.forumService.AddPost(answer);

            if (!isAdded)
            {
                return(null);
            }

            var webLink = originalPost.WebLink();

            return(webLink);
        }
Ejemplo n.º 2
0
        public ActionResult SetAnswer(PostAnswerBm bm)
        {
            if (string.IsNullOrWhiteSpace(bm.Content) || bm.Id < 1)
            {
                this.Response.StatusCode = 400;
                return this.View("_Custom400BadRequestError");
            }

            string webTitleLink = this.forumManager.CreateAnswer(bm, this.GetAppUserId);

            if (string.IsNullOrWhiteSpace(webTitleLink))
            {
                this.Response.StatusCode = 400;
                return this.View("_Custom400BadRequestError");
            }

            return this.RedirectToAction("Post", new {title = webTitleLink });
        }