Beispiel #1
0
        public ActionResult Create(Like q)

        {
            q.likes    = 1;
            q.Dislikes = 0;


            Cs.Add(q);
            Cs.Commit();
            return(RedirectToAction("Index"));
        }
        public ActionResult Create(LikesViewModel lvm, int idp)
        {
            Likes like = new Likes();

            like.IdParticipant = int.Parse(User.Identity.GetUserId());
            like.LikedDate     = DateTime.Now;

            like.IdPost = idp;
            LS.Add(like);
            LS.Commit();


            return(RedirectToAction("../Post/Details"));
        }
        public JsonResult AddLike(Guid id)
        {
            JsonCommentLikeVM jr = new JsonCommentLikeVM();
            Guid appuserID       = _appUserService.FindByUserName(HttpContext.User.Identity.Name).ID;

            if (!(_likeService.Any(x => x.AppUserID == appuserID && x.TweetID == id)))
            {
                Like like = new Like();
                like.TweetID   = id;
                like.AppUserID = appuserID;
                _likeService.Add(like);

                //Kullanıcıya gönderilecek mesaj oluşturulur.

                jr.Likes       = _likeService.GetDefault(x => x.TweetID == id).Count();
                jr.userMessage = "likes it";
                jr.isSuccess   = true;
                jr.Likes       = _likeService.GetDefault(x => x.TweetID == id && (x.Status == Core.Enum.Status.Active || x.Status == Core.Enum.Status.Updated)).Count();
                jr.Comments    = _commentService.GetDefault(x => x.TweetID == id && (x.Status == Core.Enum.Status.Active || x.Status == Core.Enum.Status.Updated)).Count();
                return(Json(jr, JsonRequestBehavior.AllowGet));
            }
            else
            {
                jr.isSuccess   = false;
                jr.userMessage = "You've liked this article before!";

                return(Json(jr, JsonRequestBehavior.AllowGet));
            }
        }
        public JsonResult AddLike(int id)
        {
            JsonLikeVM jr        = new JsonLikeVM();
            int        appUserId = _appUserService.FindByUserName(HttpContext.User.Identity.Name).Id;

            if (!(_likeService.Any(x => x.AppUserId == appUserId && x.PostId == id)))
            {
                Like like = new Like();
                like.PostId    = id;
                like.AppUserId = appUserId;
                _likeService.Add(like);

                jr.Likes       = _likeService.GetDefault(x => x.PostId == id).Count();
                jr.userMessage = "like it";
                jr.isSuccess   = true;
                jr.Likes       = _likeService.GetDefault(x => x.PostId == id && x.Status != Status.Passive).Count();
                jr.Comments    = _commentService.GetDefault(x => x.PostId == id && x.Status != Status.Passive).Count();
                return(Json(jr, JsonRequestBehavior.AllowGet));
            }
            else
            {
                jr.isSuccess   = false;
                jr.userMessage = "You've liked this post before..!";

                return(Json(jr, JsonRequestBehavior.AllowGet));
            }
        }
Beispiel #5
0
        public JsonResult AddLike(Guid id)
        {
            JsonLikeVM jr        = new JsonLikeVM();
            Guid       appuserID = _appUserService.FindByUserName(HttpContext.User.Identity.Name).ID;

            if (!(_likeService.Any(x => x.AppUserID == appuserID && x.TweetID == id)))
            {
                Like like = new Like();
                like.TweetID   = id;
                like.AppUserID = appuserID;
                _likeService.Add(like);



                jr.Likes       = _likeService.GetDefault(x => x.TweetID == id).Count();
                jr.userMessage = "like you";
                jr.isSuccess   = true;
                jr.Likes       = _likeService.GetDefault(x => x.TweetID == id && (x.Status == Core.Enum.Status.Active || x.Status == Core.Enum.Status.Updated)).Count();
                jr.Comments    = _commentService.GetDefault(x => x.TweetID == id && (x.Status == Core.Enum.Status.Active || x.Status == Core.Enum.Status.Updated)).Count();
                return(Json(jr, JsonRequestBehavior.AllowGet));
            }
            else
            {
                jr.isSuccess   = false;
                jr.userMessage = "Error!";

                return(Json(jr, JsonRequestBehavior.AllowGet));
            }
        }
        public void TestAddCaseComment()
        {
            Like like = new Like()
            {
                ObjectId   = "5d027ea59b358d247cd21a55",
                ObjectType = "comment",
                UserId     = "5d027ea59b358d247cd21a54",
                Date       = DateTime.Now
            };

            mockPostRepository.Setup(x => x.IncreaseLikeCount(It.IsAny <string>())).Returns(true);
            mockLikeRepository.Setup(x => x.Add(It.IsAny <Like>())).Returns(like);
            var  testService = new LikeService(mockLikeRepository.Object, mockPostRepository.Object, mockCommentRepository.Object);
            Like result      = testService.Add(like);

            Assert.AreEqual(like, result);
        }
Beispiel #7
0
        public ActionResult Like(int?id)
        {
            int  userId = userDb.GetByName(HttpContext.User.Identity.Name).ID;
            Like like   = new Like();

            if (!likeDb.Any(x => x.AppUserId == userId && x.ArticleID == id))
            {
                like.ArticleID = (int)id;
                like.AppUserId = userId;
                like.LikerName = userDb.GetById(userId).Nick;
                likeDb.Add(like);
            }
            else
            {
                like = likeDb.GetByExpSingle(x => x.ArticleID == id && x.AppUserId == userId);
                likeDb.Delete(like);
            }

            return(Json(likeDb.GetByExp(x => x.ArticleID == id).Count, JsonRequestBehavior.AllowGet));
        }