public void AddPost(CreatePostDTO post) { var newPost = _mapper.Map <CreatePostDTO, Post>(post); _repository.Add(newPost); _repository.Save(); }
public async Task PublishPost(CreatePostDTO createPostDTO) { var user = await _userService.GetUserIfValid(createPostDTO.NameAndPassword); _missioContext.Posts.Add(new Post(user, createPostDTO.Message, _timeService.GetCurrentTime(), createPostDTO.Picture)); _missioContext.SaveChanges(); }
public async Task <IActionResult> CreatePost(CreatePostDTO createPostDTO) { var userId = GetUserId(); // Does User exist? if (await UserExists(userId) != true) { return(Unauthorized()); } var thread = await _Repo.Threads.FirstOrDefaultAsync(x => x.Id == createPostDTO.ThreadId); var newPost = new Post { Content = JsonSerializer.Serialize(createPostDTO.Content), CreatedOn = DateTime.Now, ThreadFK = thread.Id, Thread = thread, AuthorId = int.Parse(userId) }; thread.LastUpdated = DateTime.Now; _Repo.Add(newPost); _Repo.Update(thread); await _Repo.SaveChangesAsync(); return(await GetPosts(createPostDTO.ThreadId)); }
public PostDTO CreatePost(CreatePostDTO postDTO) { var post = postDTO.ToPost(); if (EnumerableExtensions.Any(postDTO.Tags)) { foreach (var tagId in postDTO.Tags) { var postTags = new PostTags() { Post = post, TagId = tagId }; post.PostTags.Add(postTags); } } if (postDTO.PostId != 0) { ++post.PostNum; _database.Posts.Add(post); } else { _database.Posts.Add(post); _database.Save(); post.PostId = post.Id; _database.Posts.Update(post); } _database.Save(); return(post.ToPostDTO()); }
public IActionResult Post([FromBody] CreatePostDTO createPostDTO) { var result = new ResultModel(1); return(Wrapper(ref result, () => { result = _memberApplication.CreatePost(createPostDTO); }, true)); }
public async Task <IActionResult> PutPost(int id, [FromBody] CreatePostDTO postDTO) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } await postsService.UpdatePostAsync(id, postDTO); return(Ok()); }
public async Task PublishPost_GivenPost_PublishesPost() { var missioContext = Utils.MakeMissioContext(); var grecoUser = missioContext.Users.First(x => x.UserName == "Francisco Greco"); var createPostDTO = new CreatePostDTO(new NameAndPassword("Francisco Greco", "ElPass"), "A new message", null); var postsController = MakePostsController(missioContext); await postsController.PublishPost(createPostDTO); Assert.IsTrue(missioContext.Posts.Any(x => x.Author == grecoUser && x.Message == "A new message" && x.PublishedDate == new DateTime(2018, 9, 2))); }
public async Task <Post> CreatePostAsync(CreatePostDTO postDTO) { var post = mapper.Map <Post>(postDTO); post.DatePosted = DateTime.Now; context.Posts.Add(post); await context.SaveChangesAsync(); return(post); }
public async Task <ActionResult <Post> > PostPost([FromBody] CreatePostDTO postDTO) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var post = await postsService.CreatePostAsync(postDTO); return(CreatedAtAction("GetPost", new { id = post.ID }, post)); }
public static Post ToPost(this CreatePostDTO postDTO) { return(new Post() { PostId = postDTO.PostId, PostNum = postDTO.PostNum, UpVotes = postDTO.UpVotes, DownVotes = postDTO.DownVotes, Text = postDTO.Text, Title = postDTO.Title, Viewed = postDTO.Viewed, DateOfPublish = postDTO.DateOfPublish, UserId = postDTO.UserId }); }
public async Task UpdatePostAsync(int id, CreatePostDTO postDTO) { var post = await context.Posts.FindAsync(id); if (post == null) { throw new NotFoundException(ErrorCode.ResourceNotFound, "post was not found"); } post.Annotation = postDTO.Annotation; post.Content = postDTO.Content; post.Title = postDTO.Title; post.DateRefreshed = DateTime.Now; context.Entry(post).State = EntityState.Modified; await context.SaveChangesAsync(); }
public async Task <IActionResult> Create([FromBody] CreatePostDTO post) { var userId = User.FindFirst(ClaimTypes.Name)?.Value; // User who created this post var user = await _userService.GetUser(userId); _postService.Create(new Post { PostTitle = post.PostTitle, PostContent = post.PostContent, UserId = userId, UserName = user.UserName }); return(Ok()); }
public Post CreatePost(IEnumerable <Claim> claims, CreatePostDTO postDTO) { var user = _accountService.GetUserByClaims(claims); var team = _teamService.Get(user.MemberOf.Id); var whiteboard = team.Whiteboard; var post = new Post { PostedBy = user, Content = postDTO.Content, Created = DateTime.Now, PostedOn = whiteboard }; _context.Posts.Add(post); _context.SaveChanges(); return(post); }
public async Task <ActionResult <BoardDTO> > PostThread(string boardName, [FromBody] CreatePostDTO thread) { var result = new ThreadValidator().Validate(thread); if (!result.IsValid) { return(BadRequest(result.Errors)); } if (!User.Identity.IsAuthenticated) { await CreateUser(); } var threadPost = new PostDTO() { Content = thread.Content, Image = thread.Image }; threadPost.UserIdentifier = User.FindFirst(ClaimTypes.NameIdentifier).Value; threadPost = _imageService.SaveImage(threadPost); return(await _postService.PostThread(boardName, threadPost)); }
public async Task <bool> Create([FromBody] CreatePostDTO req) { CreatePostCommand command = new CreatePostCommand(req.Title, req.Content, req.BlogId); return(await _bus.SendCommandAsync(command)); }
public IActionResult CreatePost(CreatePostDTO postDTO) { return(Ok(_postService.CreatePost(postDTO))); }
/// <summary> /// 发帖 /// </summary> /// <param name="createPostDTO"></param> /// <returns></returns> public ResultModel CreatePost(CreatePostDTO createPostDTO) { var postCommand = _mapper.Map <PostCommand>(createPostDTO); return(_memberService.Post(postCommand)); }
public async Task <ActionResult> PublishPost(CreatePostDTO createPostDTO) { await _postsService.PublishPost(createPostDTO); return(Ok()); }
public async Task <ActionResult <BoardDTO> > PostPost(string boardName, int threadId, [FromBody] CreatePostDTO post) { var result = new PostValidator().Validate(post); if (!result.IsValid) { return(BadRequest(result.Errors)); } if (!User.Identity.IsAuthenticated) { await CreateUser(); } var postPost = new PostDTO() { Content = post.Content, Image = post.Image }; postPost.UserIdentifier = User.FindFirst(ClaimTypes.NameIdentifier).Value; postPost.ThreadId = threadId; if (!string.IsNullOrEmpty(postPost.Image)) { if (await _imageService.IsImageUniqueToThread(postPost.Image, boardName, threadId)) { postPost = _imageService.SaveImage(postPost); } else { return(BadRequest("Duplicate Image Detected")); } } return(await _postService.PostPost(boardName, threadId, postPost)); }
public IActionResult Post(CreatePostDTO postDTO) { var post = _whiteboardService.CreatePost(User.Claims, postDTO); return(Ok(post.Id)); }
//TODO: Display message if post fails /// <inheritdoc /> public async Task PublishPost(CreatePostDTO post) { await _httpClient.PostAsJsonAsync("api/posts", post); }
public static async Task PostPost(Dispatcher <IAction> dispatch, HttpClient http, string boardName, int thread, CreatePostDTO post) { var uri = new UriBuilder(RoutePaths.Api + boardName + "/" + thread).Uri; var response = await HttpHelper.PerformHttpRequest(uri, http, dispatch, HttpMethod.Post, true, post); switch (response.StatusCode) { case HttpStatusCode.OK: var board = Json.Deserialize <BoardDTO>(await response.Content.ReadAsStringAsync()); dispatch(new GetPostsAction { Board = board }); break; case HttpStatusCode.BadRequest: dispatch(new SetErrorMessage() { Message = await response.Content.ReadAsStringAsync() }); break; default: dispatch(new SetErrorMessage() { Message = "Whoops! Something went wrong. Please try again later." }); break; } }