public ActionResult Index(bool?isBack) { if (isBack != null && isBack.Value == true && Session["doc_sc"] != null) { int ItemsCount = (int)Session["doc_ic"]; int?p = (int?)Session["doc_p"]; return(Index(null, ItemsCount, p)); } DocumentsSortCriteria sortCriteria = new DocumentsSortCriteria() { SortDirection = SortDirection.Descending, SortType = DocumentSortType.CreateDate }; DocumentsViewModel viewModel = new DocumentsViewModel() { DocumentSearchModel = new DocumentSearchViewModel() { SortCriteria = sortCriteria, SearchCriteria = new DocumentsSearchCriteria() { ItemsCount = 10 }, IsSearchPerformed = false, Categories = _dictRepository.GetCategories().ToList(), Senders = _dictRepository.GetSenders().OrderBy(s => s.LastName).ThenBy(s => s.FirstName).ToList(), Types2 = _dictRepository.GetTypes2().ToList() } }; return(View(viewModel)); }
public static List <DocumentDetails> SortDocuments(this List <DocumentDetails> list, DocumentsSortCriteria sortCriteria) { IQueryable <DocumentDetails> result = list.AsQueryable <DocumentDetails>(); switch (sortCriteria.SortType) { case DocumentSortType.DocumentNumber: result = result.OrderBy(s => s.InfoTypeOne.DocumentNumber); break; case DocumentSortType.CaseNumber: result = result.OrderBy(s => s.InfoTypeOne.CaseNumber); break; case DocumentSortType.Date: result = result.OrderBy(s => s.InfoTypeOne.Date); break; case DocumentSortType.Category: //jesli Category ID jest null, sortowanie nic nie zwraca, wiec najpierw dodaje te z nullami, a potem sortuje te ktore maja wartosci List <DocumentDetails> tmpC = result.Where(c => c.InfoTypeOne.CategoryID == null).ToList(); tmpC.AddRange(result.Where(c => c.InfoTypeOne.CategoryID != null).OrderBy(s => s.InfoTypeOne.Category.Name)); result = tmpC.AsQueryable <DocumentDetails>(); break; case DocumentSortType.Type: List <DocumentDetails> tmpT = result.Where(c => c.InfoTypeOne.TypeID == null).ToList(); tmpT.AddRange(result.Where(c => c.InfoTypeOne.TypeID != null).OrderBy(s => s.InfoTypeOne.Type.Name)); result = tmpT.AsQueryable <DocumentDetails>(); break; //case DocumentSortType.Sender: // List<DocumentDetails> tmpS = result.Where(c => c.InfoTypeTwo.SenderID == null).ToList(); // tmpS.AddRange(result.Where(c => c.InfoTypeTwo.SenderID != null).OrderBy(s => s.InfoTypeTwo.Sender.FullName)); // result = tmpS.AsQueryable<DocumentDetails>(); // break; case DocumentSortType.Description: result = result.OrderBy(s => s.InfoTypeTwo.Description); break; case DocumentSortType.CreateDate: result = result.OrderBy(s => s.Document.CreateDate); break; default: break; } if (sortCriteria.SortDirection == SortDirection.Descending) { result = result.Reverse(); } return(result.ToList()); }
public ActionResult Index(FormCollection formValues, int ItemsCount, int?p) { int?page = p; int itemsOnPage = ItemsCount; if (formValues == null) { formValues = new FormCollection(); } DocumentsSearchCriteria searchCriteria = new DocumentsSearchCriteria(); if (!TryUpdateModel <DocumentsSearchCriteria>(searchCriteria, formValues.AllKeys)) { searchCriteria = Session["doc_sc"] as DocumentsSearchCriteria; } if (searchCriteria == null) { searchCriteria = new DocumentsSearchCriteria(); } DocumentsSortCriteria sortCriteria = new DocumentsSortCriteria(); if (!TryUpdateModel <DocumentsSortCriteria>(sortCriteria, formValues.AllKeys)) { sortCriteria = Session["doc_soc"] as DocumentsSortCriteria; } if (sortCriteria == null) { sortCriteria = new DocumentsSortCriteria(); } DocumentsViewModel viewModel = new DocumentsViewModel() { DocumentSearchModel = new DocumentSearchViewModel() { SearchCriteria = searchCriteria, SortCriteria = sortCriteria, SearchResults = new PaginatedList <DocumentDetails>(_repository.SearchDocuments(searchCriteria).SortDocuments(sortCriteria).AsQueryable <DocumentDetails>(), page ?? 0, itemsOnPage), IsSearchPerformed = true, Categories = _dictRepository.GetCategories().ToList(), Senders = _dictRepository.GetSenders().ToList(), Types2 = _dictRepository.GetTypes2().ToList() } }; Session["doc_sc"] = searchCriteria; Session["doc_soc"] = sortCriteria; Session["doc_ic"] = ItemsCount; Session["doc_p"] = p; if (searchCriteria.CategoryID.HasValue) { viewModel.DocumentSearchModel.Types = _dictRepository.GetTypes(searchCriteria.CategoryID.Value).ToList(); } return(View(viewModel)); }