Beispiel #1
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));
        }