public void LikePost(Guid postId, Guid profileId, DateTime dateTime)
        {
            // Try to find existing like
            var existingLikeId = new PostLikeModelId(postId, profileId);
            var existingLike   = _uniwikiContext.PostLikes.Find(existingLikeId.GetKeyValues());

            // If there is no like
            if (existingLike == null)
            {
                // Create the like
                var like = new PostLikeModel(postId, profileId, dateTime, true);

                // Save it to the DB
                _uniwikiContext.PostLikes.Add(like);
            }
            else
            {
                // If it already is liked
                if (existingLike.IsLiked)
                {
                    // Do nothing
                    return;
                }

                // Like it
                existingLike.Like();
            }
        }
Beispiel #2
0
        public int Like(PostLikeModel model)
        {
            try
            {
                var postLike = new PostLike()
                {
                    PostId  = model.PostId,
                    Status  = true,
                    LikedBy = model.UserId,
                    LikedOn = UnixTimeBaseClass.UnixTimeNow
                };

                _db.PostLikes.Add(postLike);
                _db.SaveChanges();

                return(postLike.PostLikeId);
            }
            catch (Exception ex)
            {
                JavaScriptSerializer js = new JavaScriptSerializer();
                string json             = js.Serialize(model);
                Log.Error("Post Like - Add- " + json, ex);
                throw;
            }
        }
Beispiel #3
0
        public int Unlike(PostLikeModel model)
        {
            try
            {
                var postLike = _db.PostLikes.First(x => x.PostId == model.PostId && x.LikedBy == model.UserId);

                postLike.Status        = false;
                postLike.LastUpdatedOn = UnixTimeBaseClass.UnixTimeNow;

                _db.Entry(postLike).State = EntityState.Modified;

                _db.SaveChanges();

                return(postLike.PostLikeId);
            }
            catch (Exception ex)
            {
                JavaScriptSerializer js = new JavaScriptSerializer();
                string json             = js.Serialize(model);
                Log.Error("Post Comment - Edit- " + json, ex);
                throw;
            }
        }
Beispiel #4
0
 public int Like(PostLikeModel model)
 {
     return(_postLike.Like(model));
 }