/// <summary> /// Descarga los objetos completamente /// </summary> protected virtual void Dispose(bool disposing) { if (disposing) { // free managed resources if (bgWorker != null) { bgWorker.Dispose(); bgWorker = null; } if (!Equals(repositorio, null)) { repositorio.Dispose(); } } }
public ActionResult Index(int id, String sortOrder, String searchString, String currentFilter, int?page) { ViewData["Categorias"] = catRepo.GetAll().ToList <Categoria>(); ViewBag.CurrentSort = sortOrder; ViewBag.NameSortParm = String.IsNullOrEmpty(sortOrder) ? "name_desc" : ""; ViewBag.DateSortParm = sortOrder == "Date" ? "date_desc" : "Date"; if (searchString != null) { page = 1; } else { searchString = currentFilter; } ViewBag.CurrentFilter = searchString; List <Post> posts = new List <Post>(); if (id != 0) { posts = postRepos.Get(p => p.Categoria.id == id).ToList <Post>(); } else { posts = postRepos.GetAll().ToList <Post>();; } if (!String.IsNullOrEmpty(searchString)) { posts = posts.Where(p => p.Autor.Contains(searchString) || p.Texto_1.Contains(searchString)).ToList <Post>(); } switch (sortOrder) { case "name_desc": posts = posts.OrderByDescending(p => p.Autor).ToList <Post>(); break; case "Date": posts = posts.OrderBy(p => p.Data_cadastro).ToList <Post>(); break; case "date_desc": posts.OrderByDescending(p => p.Data_cadastro); break; default: posts = posts.OrderBy(p => p.Autor).ToList <Post>(); break; } postRepos.Dispose(); catRepo.Dispose(); int pageSize = 6; int pageNumber = (page ?? 1); return(View(posts.ToPagedList(pageNumber, pageSize))); }