Ejemplo n.º 1
0
        public async Task <ActionResult <BlogInfoDto> > CreateBlogInfoAsync([FromBody] BlogForAddDto request)
        {
            var blogForAdd = await _jobsRepository.CreateBlogInfoAsync(request);

            var blogDto = _mapper.Map <BlogInfoDto>(blogForAdd);

            return(CreatedAtRoute("GetBlogInfoAsync",
                                  new { id = blogForAdd.Id },
                                  blogDto));
        }
Ejemplo n.º 2
0
        public async Task <BlogInfo> CreateBlogInfoAsync(BlogForAddDto blogDto)
        {
            var blogInfo = _mapper.Map <BlogInfo>(blogDto);

            blogInfo.Id         = Guid.NewGuid();
            blogInfo.Dr         = false;
            blogInfo.UpdateTime = DateTime.Now;
            await _context.BlogInfos.AddAsync(blogInfo);

            await _context.SaveChangesAsync();

            return(blogInfo);
        }
Ejemplo n.º 3
0
        public async Task <IActionResult> AddBlog(int id, BlogForAddDto blogForAddDto)
        {
            // if user is not authorized => return 400 NotAuthorized
            if (id != int.Parse(User.FindFirst(ClaimTypes.NameIdentifier).Value))
            {
                return(Unauthorized());
            }

            var blogToAdd = _mapper.Map <Blog>(blogForAddDto);

            blogToAdd.UserId = id;

            _repo.Add(blogToAdd);

            // if blog adding to db is successfull => return http response status 200 Ok with blog info
            if (await _repo.SaveAll())
            {
                return(Ok(blogToAdd));
            }

            throw new Exception($"Adding blog failed");
        }