private async Task <bool> UpdateLikes(FeedLike feedlike) { if (feedlike.FeedType == my8Enum.PostType.StatusPost) { if (string.IsNullOrWhiteSpace(feedlike.FeedId)) { return(false); } if (feedlike.Liked) { return(await _statusPostRepository.Like(feedlike.FeedId)); } else { return(await _statusPostRepository.UnLike(feedlike.FeedId)); } } else if (feedlike.FeedType == my8Enum.PostType.JobPost) { if (string.IsNullOrWhiteSpace(feedlike.FeedId)) { return(false); } if (feedlike.Liked) { return(await _jobPostRepository.Like(feedlike.FeedId)); } else { return(await _jobPostRepository.UnLike(feedlike.FeedId)); } } return(false); }
public async Task <IActionResult> CreateFeedLike(int feedId) { var user = await this._userManager.GetUserAsync(User); if (user == null) { return(Unauthorized()); } var message = string.Empty; if (this._feedRepositry.IsLike(feedId, user.Email)) { message = "Already like!"; } else { var feedLike = new FeedLike(); feedLike.FeedLikeFeedId = feedId; feedLike.FeedLikeCreatedUser = user.Email; feedLike.FeedLikeCreatedDateTime = DateTime.Now; feedLike.FeedLikeValidFlag = true; this._feedRepositry.CreateFeedLike(feedLike); this._feedService.IsTop(feedId); } return(Ok(message)); }
public async Task <IActionResult> Like([FromBody] FeedLike feedlike) { if (feedlike == null) { return(ToResponse(false)); } string personId = _currentProcess.CurrentAccount.Account.PersonId; feedlike.Author = AutoMapper.Mapper.Map <Author>(_currentProcess.CurrentAccount.Account); feedlike.PersonId = personId; //var result = await _httpClient.SendRequestAsync<ResponseActionJsonModel>(Request, _clientConfig, "/feedlike/create", HttpMethod.Post,feedlike); //return ToResponse(result); return(await PostAsync(Request, "/feedlike/create", null, feedlike)); }
public async Task ToggleLikeForPostAsync(int feedPostId, string userUUID, CancellationToken ct = default) { FeedPost post = await _context.FeedPosts .AsNoTracking() .Include(fp => fp.Likes) .FirstOrDefaultAsync(fp => fp.PostId == feedPostId, ct); if (post == null) { return; } FeedLike like = post.Likes.FirstOrDefault(fl => fl.UserUUID == userUUID); if (await HasUserLikedPostAsync(userUUID, feedPostId)) { like.IsLiked = false; post.PostLikeCount -= 1; _context.Update(like); _context.Update(post); } else { if (like == null) { FeedLike newLike = new FeedLike { PostId = feedPostId, UserUUID = userUUID, IsLiked = true }; await _context.FeedPostLikes.AddAsync(newLike); post.PostLikeCount += 1; _context.Update(post); } else { like.IsLiked = !like.IsLiked; _context.Update(like); post.PostLikeCount = like.IsLiked ? (post.PostLikeCount += 1) : (post.PostLikeCount -= 1); } } await _context.SaveChangesAsync(); }
public async Task <IActionResult> Create([FromBody] FeedLike model) { Notification notify = await m_FeedLikeBusiness.Like(model); return(ToResponse(notify)); }
public static string GenerateNotifyCodeCount(FeedLike feedlike) { return(GenerateNotifyCodeCount(feedlike.FeedId, (int)feedlike.FeedType, (int)NotifyType.Like, feedlike.Author.AuthorTypeId)); }
public void CreateFeedLike(FeedLike feedLike) { this._context.FeedLike.Add(feedLike); this._context.SaveChanges(); }
public async Task <Notification> Like(FeedLike feedlike) { if (CheckIsNotLogin()) { return(null); } if (feedlike == null || feedlike.Feed == null) { return(null); } feedlike.LikedTimeUnix = Utils.GetUnixTime(); string[] receiversId = null; if (feedlike.Feed.PostingAs == ActionAsType.Person) { receiversId = new string[] { feedlike.Feed.PersonId }; } else if (feedlike.Feed.PostingAs == ActionAsType.Page) { //Get list page's admin } else if (feedlike.Feed.PostingAs == ActionAsType.Community) { //get list community's admin } FeedLike exist = await _feedLikeRepositoryM.Get(feedlike); if (exist == null) { await _feedLikeRepositoryM.Create(feedlike); } else { feedlike.Id = exist.Id; await _feedLikeRepositoryM.Update(feedlike); } if (!string.IsNullOrWhiteSpace(feedlike.Id)) { await _postBroadcastPersonRepository.Like(feedlike.BroadCastId, feedlike.Liked); string code = Utils.GenerateNotifyCodeCount(feedlike); long countOthersCommentator = await _notifyRepository.CountOthers(code, feedlike.Author.AuthorId, feedlike.PersonId); Notification notify = new Notification { AuthorId = feedlike.Author.AuthorId, AuthorType = (AuthorType)feedlike.Author.AuthorTypeId, AuthorDisplayName = feedlike.Author.DisplayName, NotifyType = NotifyType.Like, NotifyTimeUnix = feedlike.LikedTimeUnix, CommentId = null, FeedType = feedlike.FeedType, FeedId = feedlike.FeedId, ReceiversId = receiversId, TargetId = feedlike.Feed.PostBy.AuthorId, TargetType = (NotificationTargetType)feedlike.Feed.PostingAs, OthersCount = countOthersCommentator }; string codeExist = Utils.GenerateNotifyCodeExist(notify); Notification existNotifi = await _notifyRepository.GetByCodeExist(codeExist); notify.CodeCount = code; notify.CodeExist = codeExist; if (existNotifi == null) { notify.Id = await _notifyRepository.Create(notify); } else { notify.Id = existNotifi.Id; await _notifyRepository.Update(notify); } await UpdateLikes(feedlike); return(notify); } return(null); }
public async Task <bool> HasUserLikedPostAsync(string userUUID, int feedPostId, CancellationToken ct = default) { FeedLike like = await _context.FeedPostLikes.AsNoTracking().FirstOrDefaultAsync(fpl => fpl.UserUUID == userUUID && fpl.PostId == feedPostId && fpl.IsLiked); return(like != null); }