Ejemplo n.º 1
0
        public IActionResult CreateThread([FromBody] ThreadDTO thread)
        {
            if (thread?.Post == null || string.IsNullOrWhiteSpace(thread.Post.Content) && string.IsNullOrWhiteSpace(thread.Post.Image))
            {
                return(BadRequest(new { message = "Post was empty" }));
            }

            using (_work.BeginTransaction())
            {
                try
                {
                    var returnThread = _work.ThreadRepository.CreateThread(thread);
                    _work.Save();

                    thread.Post.ThreadId = returnThread.Id;
                    thread.Post.IsOp     = true;

                    var board = PostHelper.CreatePost(_work, _env, this.Request, thread.Post);
                    _work.Save();
                    _work.CommitTransaction();

                    return(Json(board));
                }
                catch (PostException e)
                {
                    _work.RollbackTransaction();
                    return(BadRequest(new { message = e.Message }));
                }
                catch
                {
                    _work.RollbackTransaction();
                    return(BadRequest());
                }
            }
        }
Ejemplo n.º 2
0
        public IActionResult CreatePost(int threadId, [FromBody] PostDTO post)
        {
            post.ThreadId = threadId;
            post.IsOp     = false;

            BoardDTO board;

            try
            {
                board = PostHelper.CreatePost(_work, _env, this.Request, post);
            }
            catch (PostException e)
            {
                return(BadRequest(new { message = e.Message }));
            }

            return(Json(board));
        }