public async Task<ActionResult> Search(SearchModel model) { PIWebAPIClient client = new PIWebAPIClient("https://myserver/piwebapi"); string query = model.Option.Equals("all") ? model.Query : model.Option + ":" + model.Query; int count = model.Count.HasValue ? (int)model.Count : 10; try { dynamic result = await client.SearchAsync(query, null, "name;itemtype;webid", count); List<SearchResult> searchResults = new List<SearchResult>(); for (int i = 0; i < result.Items.Count; i++) { SearchResult searchResult = new SearchResult(); searchResult.Name = result.Items[i].Name.Value; searchResult.ItemType = result.Items[i].ItemType.Value; searchResult.WebId = result.Items[i].WebID.Value; searchResults.Add(searchResult); } return View(searchResults); } catch (Exception) { return View("Error"); throw; } finally { client.Dispose(); } }
public ActionResult Index() { SearchModel model = new SearchModel(); List<SelectListItem> options = new List<SelectListItem>(); options.Add(new SelectListItem { Text = "all", Value = "all", Selected = true }); options.Add(new SelectListItem { Text = "name", Value = "name" }); options.Add(new SelectListItem { Text = "description", Value = "description" }); options.Add(new SelectListItem { Text = "afcategories", Value = "afcategories" }); options.Add(new SelectListItem { Text = "afelementtemplate", Value = "afelementtemplate" }); options.Add(new SelectListItem { Text = "attributename", Value = "attributename" }); options.Add(new SelectListItem { Text = "attributedescription", Value = "attributedescription" }); model.Options = options; return View(model); }