コード例 #1
0
ファイル: BlogService.cs プロジェクト: SolidBrainGit/investor
        public async Task <Blog> AddBlogAsync(Blog map)
        {
            map.Author   = _userService.GetCurrentUserAsync().Result;
            map.Category = await _categoryService.GetCategoryByUrlAsync("blog");

            var response = await _postRepository.AddPostAsync <BlogEntity>(Mapper.Map <Blog, BlogEntity>(map));

            await AddTagsToBlogAsync(response.PostId, map.Tags?.Select(c => c.Name));

            map.PostId = response.PostId;
            return(map);
        }
コード例 #2
0
        public async Task <ActionResult <AddPostDtoOut> > Create([FromBody] AddPostDtoIn body)
        {
            (await new AddPostDtoInValidator().ValidateAsync(body)).AddToModelState(ModelState, null);
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var userId  = User.FindFirst(ClaimTypes.NameIdentifier)?.Value;
            var newPost = await _postRepository.AddPostAsync(userId, body.DreamId, body.Title);

            return(CreatedAtAction(nameof(GetPost), new { id = newPost.Id }, newPost));
        }
コード例 #3
0
        public async Task <News> AddNewsAsync(News map)
        {
            if (map.Title == null)
            {
                map.Title = Guid.NewGuid().ToString();
            }
            map.ModifiedOn = DateTime.Now;
            map.CreatedOn  = DateTime.Now;
            var response = await _postRepository.AddPostAsync <NewsEntity>(Mapper.Map <News, NewsEntity>(map));

            map.PostId = response.PostId;

            return(map);
        }
コード例 #4
0
        public async Task <IActionResult> CreatePost([FromForm] PostForCreationDto newPostDto)
        {
            if (newPostDto.Files != null && !Services.ImageService.ValidateImages(newPostDto.Files))
            {
                return(Conflict(new { error = "invalid file format" }));
            }
            Post post = new Post {
                Text      = newPostDto.Text,
                Title     = newPostDto.Title,
                CreatedAt = DateTime.UtcNow
            };
            var addedPostId = await _rep.AddPostAsync(post, newPostDto.Tags, newPostDto.Username, newPostDto.Files);

            return(Ok(addedPostId));
        }
コード例 #5
0
 public async Task AddPostAsync(Post user)
 {
     await _repo.AddPostAsync(user);
 }