private async Task <NewArticles> GetNewArticlesAsync(IEnumerable <Article> entities) { var @return = new NewArticles() { HasMore = true }; var groupedArticles = entities.OrderByDescending(o => o.Date).GroupBy(g => g.Date); foreach (var group in groupedArticles) { var postDate = group.FirstOrDefault().Date; if (await articles.AnyWithDate(postDate)) { @return.HasMore = false; break; } @return.Articles.AddRange(group); } return(@return); }
public HomeIndexViewModel(Entities.Country country, List <Entities.Battle> activeBattles, List <EventModel> events, ICongressCandidateService congressCandidateService, List <ArticleDom> newestArticles, List <ArticleDom> popularArticles, List <ArticleDom> adminArticles) { var lastVoting = country.GetLastCongressCandidateVoting(); CountryID = country.ID; LastDayChange = GameHelper.LastDayChangeRealTime; foreach (var e in events) { Events.Add(new CountryVotingEventViewModel(e as CountryVotingEventModel)); } if (lastVoting.Is(VotingStatusEnum.Ongoing)) { IsCongressVotingDay = true; if (SessionHelper.CurrentEntity.Is(EntityTypeEnum.Citizen)) { CanVote = congressCandidateService.CanVote(SessionHelper.LoggedCitizen, lastVoting); } } var presidentVoting = country.PresidentVotings.Last(); if (presidentVoting.VotingStatusID == (int)VotingStatusEnum.Ongoing) { IsPresidentElectionDay = true; var entity = SessionHelper.CurrentEntity; if (entity.Citizen != null) { var citizen = entity.Citizen; if (presidentVoting.PresidentVotes.Any(v => v.CitizenID == citizen.ID) == false) { CanVoteInPresidentElections = true; } } } if (SessionHelper.CurrentEntity.GetEntityType() == EntityTypeEnum.Citizen) { var citizen = SessionHelper.LoggedCitizen; var partyPresidentVoting = citizen.PartyMember?.Party?.PartyPresidentVotings?.Last(); if (partyPresidentVoting != null && partyPresidentVoting.VotingStatusID == (int)VotingStatusEnum.Ongoing) { IsPartyPresidentElectionDay = true; if (partyPresidentVoting.PartyPresidentVotes.Any(v => v.CitizenID == citizen.ID) == false) { CanVoteInPartyPresidentElections = true; } CitizenPartyID = partyPresidentVoting.PartyID; } } foreach (var battle in activeBattles) { ActiveBattles.Add(new HomeActiveBattleViewModel(battle)); } addProductsAndQualities(); addCurrencies(); foreach (var newArt in newestArticles) { NewArticles.Add(new HomeArticleSpotlightViewModel(newArt)); } foreach (var popularArt in popularArticles) { PopularArticles.Add(new HomeArticleSpotlightViewModel(popularArt)); } foreach (var adminArt in adminArticles) { AdminArticles.Add(new HomeArticleSpotlightViewModel(adminArt)); } DisplayDebug = SessionHelper.LoggedCitizen.GetPlayerType() >= PlayerTypeEnum.Admin; }