Example #1
0
        public JsonResult suggest(string q, double lat, double lng, int searchCount, double maxDistance, bool withBasicRest = true)
        {
            //just for JSON result
            //searchCount = 20;
            //====================
            try
            {
                Stopwatch stop = Stopwatch.StartNew();
                IEnumerable<WebApp.Models.RestaurantModel> restaurants = new List<WebApp.Models.RestaurantModel>();
                List<RestaurantModel> returnList = new List<RestaurantModel>();

                IList<BaseSearchableEnabledItem> searchableItems = string.IsNullOrEmpty(q) ?
                    m_serviceLayer.SearchNearest(null, new Location() { Latitude = lat, Longitude = lng }, searchCount, maxDistance) :
                    m_serviceLayer.Search(null, new Location() { Latitude = lat, Longitude = lng }, searchCount, q, maxDistance);
                if (searchableItems != null)
                {
                    if (q != "")
                    {
                        restaurants = searchableItems.OfType<RestaurantBasicData>().Select(rest => rest.ToRestaurantModel()); // with menu
                        restaurants = restaurants.findDishesInRestList(q);
                    }
                    else
                    {
                        restaurants = searchableItems.OfType<RestaurantBasicData>().Select(rest => rest.ToRestaurantModel(false)); //// without menu
                        //restaurants = searchableItems.OfType<RestaurantBasicData>().Select(rest => rest.ToRestaurantModel()); //// with menu
                    }

                    returnList = restaurants.ToList();

                    if (withBasicRest)
                    {
                        //Load Basic product restaurant
                        RestaurantBasicData basicRest = m_serviceLayer.GetRestaurantBasicById("52cbed8e3720e811740b9193");
                        RestaurantModel basicProductRest = basicRest.ToRestaurantModel(false);
                        if (basicProductRest != null) returnList.Insert(0, basicProductRest);
                    }

                    log.InfoFormat("[suggest] q={0}, searchableItems={1}, restaurants={2}, exeTime={3}", q, searchableItems, returnList, stop.ElapsedMilliseconds);
                }
                m_serviceLayer.SaveUserActivity(new PageViewActivity("suggest") { ActivityLocation = new Location(lat, lng) });
                return Json(returnList, JsonRequestBehavior.AllowGet);
            }
            catch (Exception ex)
            {
                log.ErrorFormat("[suggest] q={0}, exception={1}.", q, ex);
                return Json(null, JsonRequestBehavior.AllowGet);
                //throw;
            }
        }
Example #2
0
        public JsonResult suggest(string q, double lat, double lng, int searchCount, double maxDistance)
        {
            try
            {
                Stopwatch stop = Stopwatch.StartNew();
                IEnumerable<WebApp.Models.RestaurantModel> restaurants = new List<WebApp.Models.RestaurantModel>();

                IList<BaseSearchableEnabledItem> searchableItems = string.IsNullOrEmpty(q) ?
                    m_serviceLayer.SearchNearest(null, new Location() { Latitude = lat, Longitude = lng }, searchCount, maxDistance) :
                    m_serviceLayer.Search(null, new Location() { Latitude = lat, Longitude = lng }, searchCount, q, maxDistance);
                if (searchableItems != null)
                {
                    if (q != "")
                    {
                        restaurants = searchableItems.OfType<RestaurantBasicData>().Select(rest => rest.ToRestaurantModel()); // with menu
                        restaurants = restaurants.findDishesInRestList(q);
                    }
                    else
                    {
                        restaurants = searchableItems.OfType<RestaurantBasicData>().Select(rest => rest.ToRestaurantModel(false)); //// without menu
                    }

                    log.InfoFormat("[suggest] q={0}, searchableItems={1}, restaurants={2}, exeTime={3}", q, searchableItems, restaurants, stop.ElapsedMilliseconds);
                }
                m_serviceLayer.SaveUserActivity(new PageViewActivity("suggest") { ActivityLocation = new Location(lat, lng)});
                return Json(restaurants, JsonRequestBehavior.AllowGet);
            }
            catch (Exception ex)
            {
                log.ErrorFormat("[suggest] q={0}, exception={1}.", q, ex);
                return Json(null, JsonRequestBehavior.AllowGet);
                //throw;
            }
        }