Beispiel #1
0
 public JsonResult TweetLikeUnlikeAction([FromBody] TweetLikesModel tweetLikesModel)
 {
     try
     {
         if (tweetLikesModel.liked == "like")
         {
             var likeStatus = _tweetService.LikeTweet(tweetLikesModel);
             if (likeStatus)
             {
                 return(new JsonResult("Tweet liked successfully"));
             }
         }
         else
         {
             var unlikeStatus = _tweetService.UnLike(tweetLikesModel);
             if (unlikeStatus)
             {
                 return(new JsonResult("Tweet unliked successfully"));
             }
         }
     }
     catch (Exception)
     {
         throw;
     }
     return(new JsonResult("Tweet not liked successfully"));
 }
Beispiel #2
0
        public void shouldUnLike()
        {
            TweetLikesModel tweetLikesModel = new TweetLikesModel();

            tweetLikesModel.tweetId  = "";
            tweetLikesModel.userId   = "";
            tweetLikesModel.username = "";
            var result = _tweetService.UnLike(tweetLikesModel);

            Assert.IsTrue(result);
        }
        public bool UnLike(TweetLikesModel tweetLike)
        {
            bool isDeleted = false;

            try
            {
                isDeleted = _likesRepository.Delete(tweetLike);
            }
            catch (Exception ex)
            {
                string msg = ex.Message;
                isDeleted = false;
            }
            return(isDeleted);
        }
        public bool Delete(TweetLikesModel unlike)
        {
            bool isDeleted = false;

            try
            {
                var data = _tweetLikeData.DeleteOne(x => x.likeId.Equals(unlike.likeId) & x.tweetId.Equals(unlike.tweetId) & x.userId.Equals(unlike.userId));
                isDeleted = true;
            }
            catch (Exception)
            {
                throw;
            }
            return(isDeleted);
        }
        public bool Create(TweetLikesModel like)
        {
            bool isCreated = false;

            try
            {
                _tweetLikeData.InsertOne(like);
                isCreated = true;
            }
            catch (Exception)
            {
                throw;
            }
            return(isCreated);
        }
        public bool LikeTweet(TweetLikesModel tweetLike)
        {
            bool isLiked = false;

            try
            {
                tweetLike.createdAt = DateTime.Now;
                isLiked             = _likesRepository.Create(tweetLike);
            }
            catch (Exception ex)
            {
                string msg = ex.Message;
                isLiked = false;
            }
            return(isLiked);
        }