Ejemplo n.º 1
0
 public void ChangeLike(int pAccountId, int pPostId)
 {
     var result = _db.Votes.Where(x => x.AccountId == pAccountId).Where(x => x.PostId == pPostId).SingleOrDefault();
     var post = _db.Posts.Find(pPostId);
     if(SessionHelper.GetSession(Constant.SESSION_USER) == null)
     {
         var Object = new Vote();
         Object.AccountId = pAccountId;
         Object.PostId = pPostId;
         Object.Like = true;
         Object.IsActive = true;
         new VotesModel().Create(Object);
         post.Like = post.Like + 1;
     }
     else
     {
         if (result.Like == true)
         {
             post.Like = post.Like - 1;
             result.Like = false;
         }
         else
         {
             post.Like = post.Like + 1;
             result.Like = true;
         }
         _db.SaveChanges();
     }
 }
Ejemplo n.º 2
0
 public bool Create(Vote pNewVote)
 {
     try
     {
         _db.Votes.Add(pNewVote);
         _db.SaveChanges();
         return true;
     }
     catch
     {
         return false;
     }
 }