Ejemplo n.º 1
0
        public JsonResult Like(int id, string value)
        {
            bool              success           = false;
            Like              like              = new Like();
            Article           article           = new Article();
            ArticleRepository articleRepository = new ArticleRepository();
            LikeRepository    likeRepository    = new LikeRepository();

            article = articleRepository.GetById(id);
            List <Like> likeList  = new List <Like>();
            string      type      = AuthenticationManager.LoggedUser.GetType().BaseType.ToString();
            int         start     = type.LastIndexOf(".") + 1;
            int         positions = type.Length - start;

            type = type.Substring(start, positions);
            if (value == "Like")
            {
                like.ArticleID = id;
                like.UserID    = AuthenticationManager.LoggedUser.Id;

                like.UserType = type;
                likeRepository.Save(like);
                success = true;
            }
            if (value == "UnLike")
            {
                like = likeRepository.GetAll(filter: l => l.ArticleID == id && l.UserID == AuthenticationManager.LoggedUser.Id && l.UserType == type).FirstOrDefault();
                likeRepository.Delete(like);
                success = true;
            }
            return(Json(success, JsonRequestBehavior.AllowGet));
        }
Ejemplo n.º 2
0
        public void LikePost(int postId, int userId)
        {
            var like = new Like
            {
                UserId = userId,
                PostId = postId
            };

            _likeRepository.Save(like);
        }
        public JsonResult Like(int id, string value)
        {
            bool success = false;
            Like like = new Like();
            Article article = new Article();
            ArticleRepository articleRepository = new ArticleRepository();
            LikeRepository likeRepository = new LikeRepository();
            article = articleRepository.GetById(id);
            List<Like> likeList = new List<Like>();
            string type = AuthenticationManager.LoggedUser.GetType().BaseType.ToString();
            int start = type.LastIndexOf(".") + 1;
            int positions = type.Length - start;
            type = type.Substring(start, positions);
            if (value == "Like")
            {
                like.ArticleID = id;
                like.UserID = AuthenticationManager.LoggedUser.Id;

                like.UserType = type;
                likeRepository.Save(like);
                success = true;
            }
            if (value == "UnLike")
            {
                like = likeRepository.GetAll(filter: l => l.ArticleID == id && l.UserID == AuthenticationManager.LoggedUser.Id && l.UserType == type).FirstOrDefault();
                likeRepository.Delete(like);
                success = true;
            }
            return Json(success, JsonRequestBehavior.AllowGet);
        }