Exemple #1
0
        public ActionResult AutocompleteSearch(string term)
        {
            try
            {
                if (string.IsNullOrEmpty(term))
                {
                    return(Json(new { value = "" }, JsonRequestBehavior.AllowGet));
                }
                IEnumerable <LotDTO> lots = lotService.FindByName(term);
                if (lots == null)
                {
                    return(Json(new { value = "Can’t find anything" }, JsonRequestBehavior.AllowGet));
                }
                IEnumerable <string> lotNames = lots.Select(l => l.Name).Distinct();
                var models = lotNames.Where(a => a.Contains(term))
                             .Select(a => new { value = a })
                             .Distinct();

                return(Json(models, JsonRequestBehavior.AllowGet));
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                throw;
            }
        }