예제 #1
0
        public async Task <IActionResult> CreateLike(string slug)
        {
            string userId = _usersService.GetCurrentUserId();
            bool   liked  = await _likesService.HasUserLikedArticleBySlug(slug, userId);

            Like like = await _likesService.GetLikeByArticleSlugNoInclude(userId, slug);

            if (like != null)
            {
                return(StatusCodeAndDtoWrapper.BuildErrorResponse("You have already liked this article"));
            }

            ;

            if (await _likesService.CreateLikeByArticleSlug(userId, slug))
            {
                return(StatusCodeAndDtoWrapper.BuildSuccess("Article liked successfully"));
            }
            else
            {
                return(StatusCodeAndDtoWrapper.BuildErrorResponse("You have already liked this article"));
            }
        }