// GET: Locations/Details/5 public ActionResult Details(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } Location location2 = db.Locations.Find(id); if (location2 == null) { return(HttpNotFound()); } LocationTaskView result = new LocationTaskView(); result.singleLocation = location2; result.locationTask = db.LocationTasks.Where(i => i.LocationId == id).ToList(); return(View(result)); //return View(location); }
// GET: Locations public ActionResult Index(string sortOrder, string currentFilter, string searchString, int?page) { ViewBag.CurrentSort = sortOrder; ViewBag.NameSortParm = String.IsNullOrEmpty(sortOrder) ? "name_desc" : ""; ViewBag.ZipSortParm = sortOrder == "Zip" ? "zip_desc" : "Zip"; ViewBag.EmailSortParm = sortOrder == "Email" ? "email_desc" : "Email"; if (searchString != null) { page = 1; } else { searchString = currentFilter; } ViewBag.CurrentFilter = searchString; var locations = from l in db.Locations select l; //var communities = db.Communities.Include(c => c.Location); if (!String.IsNullOrEmpty(searchString)) { locations = locations.Where(l => l.Name.ToUpper().Contains(searchString.ToUpper()) || l.Zip.ToString().Contains(searchString.ToUpper()) || l.Email.ToUpper().Contains(searchString.ToUpper())); } switch (sortOrder) { case "name_desc": locations = locations.OrderByDescending(l => l.Name); break; case "Zip": locations = locations.OrderBy(l => l.Zip); break; case "zip_desc": locations = locations.OrderByDescending(l => l.Zip); break; case "Email": locations = locations.OrderBy(l => l.Email); break; case "email_desc": locations = locations.OrderByDescending(l => l.Email); break; default: locations = locations.OrderBy(l => l.Name); break; } int pageSize = 3; int pageNumber = (page ?? 1); LocationTaskView result = new LocationTaskView(); result.location = locations.ToList(); result.pagedLocation = locations.ToPagedList(pageNumber, pageSize); result.locationTask = db.LocationTasks.ToList(); //var result2 = db.Locations.Include(i => i.LocationTasks); return(View(result)); //return View(db.Locations.ToList()); }