public async Task <IActionResult> Post([FromBody] Post post)
        {
            post.CreatedByUserId = GetUserId();

            await _posts.CreatePost(post);

            return(Ok("Complete"));
        }
Beispiel #2
0
        public async Task <IActionResult> ConfirmCreatePost(CreatePostViewModel post)
        {
            var postDto = Mapper.Map <PostDto>(post);

            postDto.User = User.CreateUserDto();

            await _postManager.CreatePost(postDto);

            return(RedirectToAction("Index", "Home"));
        }
Beispiel #3
0
 public IActionResult Post([FromBody] Post post)
 {
     try
     {
         _postManager.CreatePost(post);
         return(Ok());
     }
     catch (ArgumentException ex)
     {
         return(BadRequest(ex));
     }
 }
Beispiel #4
0
        private void addNewPost(int userId)
        {
            PostDTO post = new PostDTO();

            Console.WriteLine("Enter Title: ");
            post.Title = Console.ReadLine();
            Console.WriteLine("Enter Text: ");
            post.Body       = Console.ReadLine();
            post.Likes      = 0;
            post.Comments   = new List <CommentDTO>();
            post.InsertTime = DateTime.UtcNow;
            post.UpdateTime = DateTime.UtcNow;
            post.UserID     = userId;
            _postManager.CreatePost(post);
        }
Beispiel #5
0
        public IHttpActionResult CreatePost(CreatePostDto post)
        {
            if (string.IsNullOrWhiteSpace(post.Content))
            {
                return(BadRequest("Content is required"));
            }
            var token = Request.Headers.GetValues("x-auth-token").First();

            Post createdPost = _postManager.CreatePost(post, _tokenManager.GetUser(token));

            if (createdPost != null)
            {
                return(Ok());
            }
            return(InternalServerError());
        }
Beispiel #6
0
        public IActionResult Post([FromBody] PostModel postModel, string category)
        {
            if (category != null)
            {
                var categoryName = nameof(postModel.Category);
                postModel.Category = category;
                ModelState.ClearError(categoryName);
            }

            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var postToCreate = PostMapper.PostModelToPost(postModel);

            return(Ok(_postManager.CreatePost(postToCreate).ToString()));
        }
Beispiel #7
0
        public async Task <IActionResult> Post([FromBody] Post post)
        {
            await _posts.CreatePost(post);

            return(Ok("Complete"));
        }