public ActionResult <object> Select() { try { var test = _teamsService.DoNothing(); var items = _teamsService.GetAll(); if (items.ToList().Count > 0) { var toSerialize = new MessageHelpers <TeamsViewModel>() { Status = 200, Data = new List <TeamsViewModel>(items) }; return(JsonConvert.SerializeObject(toSerialize)); } else { var toSerialize = new MessageHelpers <TeamsViewModel>() { Status = 404, Data = null }; return(JsonConvert.SerializeObject(toSerialize)); } } catch { var toSerialize = new MessageHelpers <TeamsViewModel>() { Status = 502, Data = null }; return(JsonConvert.SerializeObject(toSerialize)); } }
public ActionResult List() { TeamsService teamsService = new TeamsService(); TeamsListVM model = new TeamsListVM(); TryUpdateModel(model); model.Teams = teamsService.GetAll(); if (!String.IsNullOrEmpty(model.Search)) { model.Teams = model.Teams.Where(t => t.Name.ToLower().Contains(model.Search.ToLower())).ToList(); } switch (model.SortOrder) { case "name_desc": model.Teams = model.Teams.OrderByDescending(t => t.Name).ToList(); break; case "name_asc": default: model.Teams = model.Teams.OrderBy(t => t.Name).ToList(); break; } return View(model); }