コード例 #1
0
        public IActionResult GetSingleApprovedMeme([FromRoute] int id)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }
            try
            {
                var meme    = _memeService.GetSingleApprovedById(id);
                var memeDto = _mapper.Map <MemeDto>(meme);
                memeDto.Likes      = _memeService.GetRate(meme.Id);
                memeDto.Author     = _mapper.Map <AuthorDto>(_memeService.GetMemeAuthor(meme.Id));
                memeDto.ActiveDown =
                    _memeService.IsActiveDown((int)meme.Id, Int32.Parse(this.User.FindFirst(ClaimTypes.Name).Value));
                memeDto.ActiveUp =
                    _memeService.IsActiveUp((int)meme.Id, Int32.Parse(this.User.FindFirst(ClaimTypes.Name).Value));

                return(Ok(memeDto));
            }
            catch (AppException ex)
            {
                // return error message if there was an exception
                return(BadRequest(new { message = ex.Message }));
            }
        }
コード例 #2
0
 public IActionResult CreateComment([FromBody] CreateCommentDto createCommDto)
 {
     try
     {
         User loggedUser = _memeService.GetLoggedUser(this.User.FindFirst(ClaimTypes.Name).Value);
         if (loggedUser == null)
         {
             return(BadRequest(new { message = "Użytkownik nie jest zalogowany" }));
         }
         if (String.IsNullOrEmpty(createCommDto.Content))
         {
             return(BadRequest(new { message = "Nie można dodać pustego komentarza" }));
         }
         // save
         var meme = _memeService.GetSingleApprovedById(createCommDto.MemeId);
         _commService.Create(createCommDto.Content, meme, loggedUser);
         return(Ok());
     }
     catch (AppException ex)
     {
         // return error message if there was an exception
         return(BadRequest(new { message = ex.Message }));
     }
 }