public async Task <int> Send(SendPostRequest request) { Post postEntity = _mapper.Map <Post>(request); var postOwnerFeed = await _feedsRepository.GetOneAsync((feed) => feed.RelatedToUser == request.OwnerId); _feedsRepository.AddToFeed(ref postEntity, ref postOwnerFeed); _postsRepository.CreatePost(ref postEntity); await _postsRepository.SaveChangesAsync(); return(postEntity.PostId); }
public async Task <int> CreatePost(PostsDTO postsDTO) { try { int resultId = await _postsRepository.CreatePost(_mappingService._mapper.Map <Posts>(postsDTO)); LogInformation($"Successfully created a new Post : PostID {postsDTO.PostId}, Title {postsDTO.Title} :"); return(resultId); } catch (Exception ex) { LogError($"Failed to create a new post : PostID {postsDTO.PostId}, Title {postsDTO.Title} :", ex); return(1); } }
public async Task <IActionResult> CreatePost(NewPostRequestModel requestModel) { if (ModelState.IsValid) { var currentUser = GetCurrentUser(); var command = new CreatePostCommand(requestModel.Title, requestModel.Abstract, requestModel.Content, HttpContext.Connection?.RemoteIpAddress?.ToString() ?? "127.0.0.1", currentUser, Enumerable.Empty <string>().ToList().AsReadOnly(), true); await _postsRepository.CreatePost(command); return(RedirectToAction("Index", "Home")); } return(View(requestModel)); }
public Task CreatePost(Post post) { return(_postsRepository.CreatePost(post)); }
public async Task CreatePost(Post post) => await _postsRepository.CreatePost(post);