// GET: ExpenseCategory public ActionResult Index(int?page, string query = null) { var expenseCategories = _expenseCategoryRepository.GetAllFromDatabaseEnumerable().ToList().MapToViews().OrderBy(o => o.Name); // paging var pageSize = 5; var pageNumber = page ?? 1; // if no page was specified in the querystring, default to the first page (1) var onePageOfExpenseCategories = expenseCategories.ToPagedList(pageNumber, pageSize); // will only contain 5 items max because of the pageSize //searching if (!string.IsNullOrEmpty(query)) { int i; var expenseCategorySearched = _expenseCategoryRepository.GetAllFromDatabaseEnumerable() .Where(e => e.Name.ToLower().Contains(query.ToLower()) || e.Account.Equals(int.TryParse(query, out i) ? i : (int?)null)) .ToList() .MapToViews(); onePageOfExpenseCategories = expenseCategorySearched.ToPagedList(pageNumber, pageSize); } ViewBag.onePageOfExpenseCategories = onePageOfExpenseCategories; return(View(onePageOfExpenseCategories)); }
private void FillDropDownValuesForExpenseCategory() { var selectItems = new List <SelectListItem>(); var listItem = new SelectListItem(); listItem.Text = "-- Select Category --"; listItem.Value = ""; selectItems.Add(listItem); selectItems.AddRange(_expenseCategoryRepository.GetAllFromDatabaseEnumerable().ToList().MapToListExpenseCategories()); // remove category that is calculated by program itself selectItems.Remove(selectItems.Where(i => i.Value == "1").Single()); // allowance selectItems.Remove(selectItems.Where(i => i.Value == "10").Single()); // private car transportation ViewBag.Categories = selectItems; }