// GET: Note public ViewResult Index(string sortOrder, string searchString) { // Sort function using viewbag ViewBag.NameSort = String.IsNullOrEmpty(sortOrder) ? "message_desc" : ""; ViewBag.DateSort = sortOrder == "Date" ? "date_desc" : "Date"; var notes = from n in _context.Notes select n; if (!String.IsNullOrEmpty(searchString)) { notes = notes.Where(n => n.Message.Contains(searchString)); } switch (sortOrder) { case "message_desc": notes = notes.OrderByDescending(n => n.Message); break; case "Date": notes = notes.OrderBy(n => n.Date); break; case "date_desc": notes = notes.OrderByDescending(n => n.Date); break; default: notes = notes.OrderBy(n => n.Message); break; } var weatherService = new OpenWeatherMapService(); var notelist = notes.ToList(); foreach (var note in notelist) { weatherService.FindMaxTemp(note); } return(View(notes.ToList())); }