public IHttpActionResult Search(string keyword) { var stopwatch = new Stopwatch(); stopwatch.Start(); var finder = new ProductFinder(); finder.AddProductStore(new JumboProductStore()); finder.AddProductStore(new PlusProductStore()); finder.AddProductStore(new AHProductStore()); var model = new SearchResults(); model.SearchTerm = keyword; model.Supermarkets = finder .Find(keyword) .GroupBy(p => p.Supermarket) .Select(s => new Supermarket { Name = s.Key, Products = s.ToList() }); stopwatch.Stop(); model.Duration = $"{stopwatch.Elapsed.Seconds} seconds and {stopwatch.Elapsed.Milliseconds} milliseconds"; return(Ok(model)); }
public ActionResult Search(string product) { try { var stopwatch = new Stopwatch(); stopwatch.Start(); var finder = new ProductFinder(); finder.AddProductStore(new JumboProductStore()); finder.AddProductStore(new PlusProductStore()); finder.AddProductStore(new AHProductStore()); var model = new SearchViewModel(); model.SearchTerm = product; model.Products = finder.Find(product).OrderBy(p => p.Price); stopwatch.Stop(); model.SearchDuration = $"{stopwatch.Elapsed.Seconds} seconds and {stopwatch.Elapsed.Milliseconds} milliseconds"; return(View(model)); } catch (System.Exception ex) { var model = new ErrorModel { Exception = ex.ToString(), Message = ex.Message, Stacktrace = ex.StackTrace }; return(RedirectToAction("Index", "Error", model)); } }