public ActionResult FilterSearch(RepresentativeSearchModel searchModel) { RepresentativeService service = new RepresentativeService(); RepresentativeListModel resultModel = service.SearchForRepresentativesForParliament(searchModel); return(PartialView("_RepresentativesSearchResult", resultModel)); }
public ActionResult Index(string pCode) { var parliamentId = new ParliamentService().GetParliamentId(pCode); RepresentativeService service = new RepresentativeService(); RepresentativeListModel model = service.GetAllRepresentativesForParliament(parliamentId); return(View(model)); }
public ActionResult ManageRepresentatives() { if (SessionManager.Current.CurrentParliamentId == 0) { SessionManager.Current.CurrentParliamentId = 1; } RepresentativeService service = new RepresentativeService(); RepresentativeListModel model = service.GetAllRepresentativesForParliament(SessionManager.Current.CurrentParliamentId); return(View(model)); }
private static RepresentativeListModel SearchRepresentativesInternal(Models.Representative.RepresentativeSearchModel searchModel, ApplicationDbContext context) { var parliament = context .Parliaments .Where(x => x.ParliamentID == searchModel.ParliamentId) .Include(x => x.ParliamentHouses.Select(ph => ph.Representatives.Select(y => y.Party))) .FirstOrDefault(); if (parliament == null) { return(null); } var allRepresentativeIds = parliament.ParliamentHouses .SelectMany(x => x.Representatives) .ToList() .Where(x => searchModel.SearchName == null || (x.FirstName + " " + x.LastName).ToLowerInvariant().Contains(searchModel.SearchName.ToLowerInvariant()) || (x.LastName + " " + x.FirstName).ToLowerInvariant().Contains(searchModel.SearchName.ToLowerInvariant())) .Where(x => searchModel.SelectedParty == null || x.PartyID == searchModel.SelectedParty) .Select(x => x.RepresentativeID).ToList(); var questions = GetRepresentativeQuestionCount(context, allRepresentativeIds); var answers = GetRepresentativeAnswerCount(context, allRepresentativeIds); var result = new RepresentativeListModel { SearchModel = searchModel, ParliamentHouses = new List <ParliamentHouseModel>(), ParliamentName = parliament.Name }; foreach (var house in parliament.ParliamentHouses) { var houseModel = new ParliamentHouseModel { Name = house.Name, ParliamentHouseID = house.ParliamentHouseID, }; var representatives = new List <RepresentativeModel>(); foreach (var rep in house.Representatives.Where(x => allRepresentativeIds.Contains(x.RepresentativeID))) { var repModel = new RepresentativeModel { Representative = rep, TotalAnswers = answers.ContainsKey(rep.RepresentativeID) ? answers[rep.RepresentativeID] : 0, TotalQuestions = questions.ContainsKey(rep.RepresentativeID) ? questions[rep.RepresentativeID] : 0 }; CalculateFlagsForRepresentative(repModel); representatives.Add(repModel); } switch (searchModel.SortOrder) { case Models.Representative.SortOrder.MostQuestions: houseModel.Representatives = representatives.OrderByDescending(x => x.TotalQuestions).ToList(); break; case Models.Representative.SortOrder.MostAnswers: case Models.Representative.SortOrder.None: default: houseModel.Representatives = representatives .OrderByDescending(x => x.PercentageAnswered) .ThenByDescending(x => x.TotalQuestions) .ToList(); break; } result.ParliamentHouses.Add(houseModel); } return(result); }