public List <PoliticalPartyViewModel> GetAll(bool inactive = false)
 {
     return(_politicalPartyRepository.GetAll(inactive).ToList()
            .Select(party => new PoliticalPartyViewModel(party)) as List <PoliticalPartyViewModel>);
 }
Beispiel #2
0
        // GET: PoliticalParty
        public ActionResult Index(string sortOrder, string searchString, string currentFilter, int?page)
        {
            ViewBag.CurrentSort    = sortOrder;
            ViewBag.NameSortParm   = String.IsNullOrEmpty(sortOrder) ? "Name" : "";
            ViewBag.CodeSortParm   = String.IsNullOrEmpty(sortOrder) ? "Code" : "";
            ViewBag.StatusSortParm = String.IsNullOrEmpty(sortOrder) ? "Status" : "";
            ViewBag.DateSortParm   = sortOrder == "Date" ? "date_desc" : "Date";

            if (searchString != null)
            {
                searchString = searchString.ToLower();
                page         = 1;
            }
            else
            {
                searchString = currentFilter;
            }
            ViewBag.CurrentFilter = searchString;

            var politicalPartyList = _politicalPartyRepository.GetAll().ToList();

            if (!String.IsNullOrEmpty(searchString))
            {
                politicalPartyList = new List <PoliticalParty>(politicalPartyList.Where(r => r.Name.ToLower().Contains(searchString) ||
                                                                                        r.Code.ToString().ToLower().Contains(searchString) ||
                                                                                        r.Status.ToString().ToLower().Contains(searchString) ||
                                                                                        r.DateCreated.ToString().ToLower().Contains(searchString)));
            }
            switch (sortOrder)
            {
            case "Name":
                politicalPartyList = new List <PoliticalParty>(politicalPartyList.OrderBy(s => s.Name));
                break;

            case "Code":
                politicalPartyList = new List <PoliticalParty>(politicalPartyList.OrderBy(s => s.Code));
                break;

            case "Status":
                politicalPartyList = new List <PoliticalParty>(politicalPartyList.OrderBy(s => s.Status));
                break;

            case "Date":
                politicalPartyList = new List <PoliticalParty>(politicalPartyList.OrderBy(s => s.DateCreated));
                break;

            case "date_desc":
                politicalPartyList = new List <PoliticalParty>(politicalPartyList.OrderByDescending(s => s.DateCreated));
                break;

            default:
                politicalPartyList = new List <PoliticalParty>(politicalPartyList.OrderBy(s => s.Name));
                break;
            }

            ViewBag.AlertMessage = TempData["Msg"] ?? "";
            ViewBag.AlertType    = TempData["Alrt"] ?? "";

            int pageSize   = 30;
            int pageNumber = (page ?? 1);

            return(View(politicalPartyList.ToPagedList(pageNumber, pageSize)));
        }