public IEnumerable <PostFeed> LikeOrUnlikeSelfPost(int postFeedId, int userWhoLikedId) { try { var currentPost = _postFeedRepository.GetPostFeedById(postFeedId); currentPost.IsSelfSupported = !currentPost.IsSelfSupported; currentPost.NoOfSupports = (currentPost.IsSelfSupported) ? currentPost.NoOfSupports + 1 : currentPost.NoOfSupports - 1; _postFeedRepository.UpdateItem(currentPost); var postFeedLikeInLocal = _postFeedRepository.GetPostFeedLikeByContactId(userWhoLikedId, currentPost.PostFeedID); if (postFeedLikeInLocal == null) { _postFeedRepository.UpdateItem(new PostFeedLike { ContactID = userWhoLikedId, PostFeedID = currentPost.PostFeedID }); } else { _postFeedRepository.DeleteTable(postFeedLikeInLocal); } _cachedPostFeeds = _postFeedRepository.GetAllPostsFromLocal(); return(_cachedPostFeeds); } catch (SQLite.SQLiteException) { return(_cachedPostFeeds); } }
public IEnumerable <PostFeed> LikeOrUnlikeSelfPost(int postFeedId, int userWhoLikedId) { try { var currentPost = _postFeedRepository.GetPostFeedById(postFeedId); currentPost.IsSelfSupported = !currentPost.IsSelfSupported; currentPost.NoOfSupports = (currentPost.IsSelfSupported) ? currentPost.NoOfSupports + 1 : currentPost.NoOfSupports - 1; _postFeedRepository.UpdateItem(currentPost); var postFeedLikeInLocal = _postFeedRepository.GetPostFeedLikeByContactId(userWhoLikedId, currentPost.PostFeedID); var supporterFromLocal = _contactRepository.GetContactByRemoteId(userWhoLikedId); if (postFeedLikeInLocal == null) { _postFeedRepository.UpdateItem(new PostFeedLike { ContactID = userWhoLikedId, PostFeedID = currentPost.PostFeedID, ContactPhotoURL = supporterFromLocal.PhotoURL ?? string.Empty, FirstName = supporterFromLocal?.FirstName ?? string.Empty, LastName = supporterFromLocal?.LastName ?? string.Empty }); } else { _postFeedRepository.DeleteTable(postFeedLikeInLocal); } _cachedPostFeeds = _postFeedRepository.GetAllPostsFromLocal().Where(p => p.PostFeedLevel < 1); return(_cachedPostFeeds); } catch (SQLite.SQLiteException) { return(_cachedPostFeeds); } }