コード例 #1
0
        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);
        }
コード例 #2
0
        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);
            }
        }
コード例 #3
0
        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));
        }
コード例 #4
0
 public Task CreatePost(Post post)
 {
     return(_postsRepository.CreatePost(post));
 }
コード例 #5
0
ファイル: PostsService.cs プロジェクト: smp-org/smp
 public async Task CreatePost(Post post)
 => await _postsRepository.CreatePost(post);