public async Task <bool> InitBroadcast() { if (CheckIsNotLogin()) { return(false); } string personId = _process.PersonId; List <Task> tasks = new List <Task>(); Task <IEnumerable <Page> > getFollowingPagesTask = _personRepositoryN.GetFollowingPage(personId); Task <IEnumerable <Community> > getCommunityTask = _personRepositoryN.GetJoiningCommunitys(personId); await Task.WhenAll(getFollowingPagesTask, getCommunityTask); List <Author> authors = new List <Author>(); if (getFollowingPagesTask.Result != null) { authors.AddRange(Mapper.Map <List <Author> >(getFollowingPagesTask.Result)); } if (getCommunityTask.Result != null) { authors.AddRange(Mapper.Map <List <Author> >(getCommunityTask.Result)); } bool result = false; if (authors != null) { LastPostBroadCast lastPost = null; PostBroadcastPerson postBroadcastPerson = null; for (int i = 0; i < authors.Count; i++) { if (authors[i] == null) { continue; } lastPost = null; switch (authors[i].AuthorTypeId) { case (int)my8Enum.AuthorType.Page: lastPost = await _lastPostBroadCastRepository.GetByPageId(authors[i].AuthorId, personId); break; case (int)my8Enum.AuthorType.Community: lastPost = await _lastPostBroadCastRepository.GetByCommunityId(authors[i].AuthorId, personId); break; default: break; } long lastPostTimeUnix = 0; if (lastPost != null) { lastPostTimeUnix = lastPost.LastPostTimeToPerson; } Task <List <StatusPost> > getstatusPostsTask = _statusPostRepository.GetByAuthorPerson(authors[i].AuthorId, 0, Utils.LIMIT_FEED, lastPostTimeUnix); Task <List <JobPost> > getJobPostTask = _jobPostRepository.GetByAuthorPerson(authors[i].AuthorId, 0, Utils.LIMIT_FEED, lastPostTimeUnix); await Task.WhenAll(getstatusPostsTask, getJobPostTask); List <Feed> feeds = new List <Feed>(); if (getstatusPostsTask.Result != null) { feeds.AddRange(Mapper.Map <List <Feed> >(getstatusPostsTask.Result)); } if (getJobPostTask.Result != null) { feeds.AddRange(Mapper.Map <List <Feed> >(getJobPostTask.Result)); } for (int j = 0; j < feeds.Count; j++) { postBroadcastPerson = new PostBroadcastPerson { PostId = feeds[j].Id, KeyTime = feeds[j].PostTimeUnix, Like = false, PostType = (PostType)feeds[j].PostType, ReceiverId = personId }; result = await _PostbroadcastPersonRepositoryM.Create(postBroadcastPerson); } Feed lastFeed = feeds.OrderByDescending(p => p.PostTimeUnix).FirstOrDefault(); if (lastFeed != null) { if (lastPost == null) { lastPost = new LastPostBroadCast { AuthorId = lastFeed.PostBy.AuthorId, LastPostIdToPerson = lastFeed.Id, LastPostTimeToPerson = lastFeed.PostTimeUnix, PersonId = personId, AuthorType = (my8Enum.AuthorType)lastFeed.PostBy.AuthorTypeId }; await _lastPostBroadCastRepository.Create(lastPost); } else { lastPost.LastPostIdToPerson = lastFeed.Id; lastPost.LastPostTimeToPerson = lastFeed.PostTimeUnix; lastPost.AuthorId = lastFeed.PostBy.AuthorId; await _lastPostBroadCastRepository.Update(lastPost); } } } } return(result); }
public async Task <bool> Update(LastPostBroadCast lastpostbroadcast) { return(await m_LastPostBroadCastRepositoryM.Update(lastpostbroadcast)); }