コード例 #1
0
        public IActionResult GetAll()
        {
            var result = _likeService.GetAll();

            if (result.Succcess)
            {
                return(Ok(result));
            }

            return(BadRequest(result));
        }
コード例 #2
0
        public void Like(int authorId, int commentId)
        {
            var           existingLikes = likeService.GetAll(commentId);
            LikeViewModel viewModel     = new LikeViewModel();

            viewModel.AuthorId  = authorId;
            viewModel.CommentId = commentId;
            var existingLike = existingLikes.FirstOrDefault(x => x.AuthorId == authorId);

            if (existingLike == null)
            {
                likeService.Add(viewModel);
                var likes = likeService.GetAll(commentId);
                Clients.All.SendAsync("ReceiveLike", viewModel.CommentId, likes.Count());
            }
            else
            {
                likeService.Delete(existingLike.Id);
                var likes = likeService.GetAll(commentId);
                Clients.All.SendAsync("ReceiveLike", viewModel.CommentId, likes.Count());
            }
        }
コード例 #3
0
 public IActionResult GetAll()
 {
     try
     {
         var likes = _likeService.GetAll();
         var model = _mapper.Map <IList <LikeViewModel> >(likes);
         _log.LogInformation("All Likes have been got successfully ", $"all Likes have been got");
         return(Ok(model));
     }
     catch (Exception ex)
     {
         _log.LogError("Error occured while getting Likes", "", $"{ex.Message}");
         return(null);
     }
 }
コード例 #4
0
        public IActionResult DeleteComment(int id)
        {
            var likes = likeService.GetAll(id);

            foreach (var like in likes)
            {
                if (like.CommentId == id)
                {
                    likeService.Delete(like.Id);
                }
            }

            commentaryService.Delete(id);
            return(NoContent());
        }
コード例 #5
0
        public async Task <ActionResult> Delete(string id)
        {
            User user = await _userManager.FindByIdAsync(id);

            var deletedNews = new List <NewsViewModel>();
            var news        = newsService.GetAll();

            foreach (var authorNews in news)
            {
                if (authorNews.AuthorId == Convert.ToInt32(id))
                {
                    newsService.Delete(authorNews.Id);
                    foreach (var rating in authorNews.Ratings)
                    {
                        ratingService.Delete(rating.Id);
                    }

                    foreach (var comment in authorNews.Commentaries)
                    {
                        foreach (var like in comment.Likes)
                        {
                            likeService.Delete(like.Id);
                        }
                        commentaryService.Delete(comment.Id);
                    }
                }
            }

            var ratings = ratingService.GetAll();

            foreach (var rating in ratings)
            {
                if (rating.UserId == Convert.ToInt32(id))
                {
                    ratingService.Delete(rating.Id);
                }
            }

            var commentaries = commentaryService.GetAll();

            foreach (var comment in commentaries)
            {
                if (comment.AuthorId == Convert.ToInt32(id))
                {
                    var likes = likeService.GetAll(comment.Id);
                    if (likes != null)
                    {
                        foreach (var like in likes)
                        {
                            likeService.Delete(like.Id);
                        }
                    }

                    commentaryService.Delete(comment.Id);
                }
                else
                {
                    var likes = likeService.GetAll(comment.Id);
                    foreach (var like in likes)
                    {
                        if (like.AuthorId == Convert.ToInt32(id))
                        {
                            likeService.Delete(like.Id);
                        }
                    }
                }
            }
            if (user != null)
            {
                IdentityResult result = await _userManager.DeleteAsync(user);
            }
            return(RedirectToAction("Index"));
        }
コード例 #6
0
        public ActionResult <IEnumerable <Like> > GetAll()
        {
            var likes = _service.GetAll();

            return(Ok(likes));
        }