public async Task <IActionResult> Post([FromBody] Post post) { post.CreatedByUserId = GetUserId(); await _posts.CreatePost(post); return(Ok("Complete")); }
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")); }
public IActionResult Post([FromBody] Post post) { try { _postManager.CreatePost(post); return(Ok()); } catch (ArgumentException ex) { return(BadRequest(ex)); } }
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); }
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()); }
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())); }
public async Task <IActionResult> Post([FromBody] Post post) { await _posts.CreatePost(post); return(Ok("Complete")); }