示例#1
0
        private string UpdateLike(int newsID)
        {
            bool isSuccess   = false;
            var  newsHistory = KLLikeHistory.GetAll().Where(h => h.NewsID == newsID && h.AuthorID == GetAuthor(currentUser.UserId)).SingleOrDefault();

            if (newsHistory == null)
            {
                newsHistory            = new KLLikeHistory();
                newsHistory.NewsID     = newsID;
                newsHistory.AuthorID   = GetAuthor(currentUser.UserId);
                newsHistory.CreateDate = DateTime.Now;
                newsHistory.Save();
                var news = KLNews.GetAll().Where(n => n.NewsID == newsID).SingleOrDefault();
                news.LikeCount += 1;
                isSuccess       = news.Save();
            }
            else
            {
                KLLikeHistory.Delete(newsHistory.LikeID);
                var news = KLNews.GetAll().Where(n => n.NewsID == newsID).SingleOrDefault();
                news.LikeCount -= 1;
                isSuccess       = news.Save();
            }
            return(isSuccess ? "success" : "fail");
        }
示例#2
0
        protected bool CheckLiked(int newsID)
        {
            try
            {
                List <KLLikeHistory> lstLiked = KLLikeHistory.GetAll().Where(l => l.AuthorID == GetAuthor(currentUser.UserId)).ToList();
                foreach (var item in lstLiked)
                {
                    if (newsID == item.NewsID)
                    {
                        return(true);
                    }
                }
                return(false);
            }
            catch (Exception ex)
            {
                return(false);

                log.Error(ex.Message);
            }
        }