Ejemplo n.º 1
0
        public async Task <IActionResult> AddLike(int id)
        {
            var user = await _userManager.GetUserAsync(HttpContext.User);

            var comm = await db.Comments.FirstOrDefaultAsync(c => c.Id == id);

            Likes like = new Likes
            {
                CommentsId = comm.Id,
                User       = user,
                Comments   = comm
            };

            var find = likesRepository.FindLike(user, comm);

            if (find == null)
            {
                likesRepository.AddLike(like, comm);
            }
            else
            {
                likesRepository.RemoveLike(find, comm);
            }

            return(RedirectToAction("CommentsList", new { id = comm.CarLotId }));
        }