コード例 #1
0
        public IActionResult GetSingleUnapprovedMeme([FromRoute] int id)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }
            try
            {
                var meme    = _memeService.GetSingleUnapprovedById(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 }));
            }
        }