Пример #1
0
        private async Task <bool> CreatePostBroadcastAsync(StatusPost post)
        {
            try
            {
                List <PersonAllin> people = await GetPersonInvolve(post.PostBy);

                if (people == null || people.Count == 0)
                {
                    return(false);
                }
                List <Task> tasks = new List <Task>();
                for (int i = 0; i < people.Count; i++)
                {
                    PostBroadcastPerson postBroadcast = new PostBroadcastPerson();
                    postBroadcast.PostId     = post.Id;
                    postBroadcast.ReceiverId = people[i].Person.Id;
                    postBroadcast.PostType   = PostType.StatusPost;
                    postBroadcast.KeyTime    = post.PostTimeUnix;
                    tasks.Add(Task.Run(() =>
                    {
                        _PostbroadcastPersonRepositoryM.Create(postBroadcast);
                    }));
                }
                await Task.WhenAll(tasks);

                return(true);
            }
            catch
            {
                return(false);
            }
        }
Пример #2
0
        private async Task <bool> CreatePostBroadcastAsync(JobPost jobPost)
        {
            string[]    allPersonId = null;
            List <Task> tasks       = new List <Task>();
            Task <HashSet <string> > lstPersonByAuthor = GetPersonIdInvolve(jobPost.PostBy);

            tasks.Add(lstPersonByAuthor);
            Task <HashSet <string> > lstPersonByJobFunction = null;
            Task <HashSet <string> > lstPersonBySkill       = null;
            Task <HashSet <string> > lstPersonByExperience  = null;

            if (jobPost.Privacy == (int)PostPrivacyType.All)
            {
                //must satisfy
                lstPersonByJobFunction = GetPersonJobFunction(jobPost.JobFunctionTags);
                tasks.Add(lstPersonByJobFunction);
                //must satisfy
                lstPersonBySkill = GetPersonSkill(jobPost.SkillTags);
                tasks.Add(lstPersonBySkill);
                // must satisfy
                lstPersonByExperience = GetPersonExperience(jobPost.MinExperience, jobPost.MaxExperience);
                tasks.Add(lstPersonByExperience);
            }

            //optional
            //Task<HashSet<string>> lstPersonByLocation = GetPersonLocation(jobPost.Locations);
            //tasks.Add(lstPersonByLocation);
            //optional
            //Task<HashSet<string>> lstPersonByDegree = GetPersonDegree(jobPost.Degrees);
            //tasks.Add(lstPersonByDegree);

            await Task.WhenAll(tasks);

            List <HashSet <string> > hashSetsMustSatisfy = new List <HashSet <string> >();

            if (jobPost.Privacy == (int)PostPrivacyType.All)
            {
                await Task.Run(() =>
                {
                    //must satisfy
                    hashSetsMustSatisfy.Add(lstPersonByJobFunction.Result);
                    hashSetsMustSatisfy.Add(lstPersonBySkill.Result);
                    hashSetsMustSatisfy.Add(lstPersonByExperience.Result);
                    string[] allPersonSatisfyJob = Utils.IntersectOrUnion(hashSetsMustSatisfy);

                    string[] allPersonByPost = lstPersonByAuthor.Result.ToArray();

                    //hashSetsMustSatisfy.Add(lstPersonByLocation.Result);
                    //hashSetsMustSatisfy.Add(lstPersonByDegree.Result);

                    allPersonId = allPersonSatisfyJob.Union(allPersonByPost).ToArray();
                });
            }
            else
            {
                allPersonId = lstPersonByAuthor.Result.ToArray();
            }

            try
            {
                List <Task> lastTasks = new List <Task>();
                for (int i = 0; i < allPersonId.Length; i++)
                {
                    PostBroadcastPerson postBroadcast = new PostBroadcastPerson();
                    postBroadcast.PostId     = jobPost.Id;
                    postBroadcast.ReceiverId = allPersonId[i];
                    postBroadcast.PostType   = PostType.JobPost;
                    postBroadcast.KeyTime    = jobPost.PostTimeUnix;
                    lastTasks.Add(Task.Run(() =>
                    {
                        _PostbroadcastPersonRepositoryM.Create(postBroadcast);
                    }));
                }
                await Task.WhenAll(lastTasks);

                return(true);
            }
            catch
            {
                return(false);
            }
        }
Пример #3
0
        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);
        }
Пример #4
0
 public async Task<bool> HidePost(PostBroadcastPerson post)
 {
     return await m_PostbroadcastPersonRepositoryM.HidePost(post);
 }