Example #1
0
        public ActionResult Search(string shopName, int categoryId = 0, int p = 1, string s = "default")
        {
            ViewBag.ShopSearchName = shopName;
            ShopModel shopModel = new ShopModel();
            string serviceAreaId = "0";//默认宁波大学
            string serviceAreaName = "";
            UserModel.GetUserDefaultAreaSetting(ref serviceAreaId, ref serviceAreaName);

            var shops = shopModel.GetShopsList(shopName, int.Parse(serviceAreaId));
            List<V_UserFavoriteShopForList> favoriteShops = new List<V_UserFavoriteShopForList>();
            if(User.Identity.IsAuthenticated)
            {
                UserModel userModel = new UserModel();
                UserInfo userInfo = userModel.GetUserInfo(User.Identity.Name);
                favoriteShops = shopModel.GetFavoriteShopsList(userInfo.Id).ToList();
            }

            var shopCategories = shopModel.GetShopCategoryStatistic(shops);

            ViewBag.TotalShopsCount = shops.Count();

            if(categoryId != 0)
            {
                shops = shops.Where(r => r.CategoryId == categoryId);
                ViewBag.ShopsCount = shops.Count();
            }
            else
                ViewBag.ShopsCount = ViewBag.TotalShopsCount;

            ViewBag.CategoryId = categoryId;

            switch(s.ToLower())
            {
                case "grade":
                    shops = shops.OrderByDescending(r => r.Stars);
                    break;
                case "price":
                    shops = shops.OrderBy(r => r.UpSendPrice);
                    break;
                case "speed":
                    shops = shops.OrderBy(r => r.DeliveryTime);
                    break;
                case "paymoney":
                    shops = shops.OrderBy(r => r.AveragePayMoney);
                    break;
            }
            ViewBag.SortBy = s;

            int pageSize = Request.Browser.IsMobileDevice ? 15 : 25;
            Paging.ToPaging(p, ViewBag.ShopsCount, this, pageSize);
            shops = shops.Skip((p - 1) * pageSize).Take(pageSize);
            return View(new ShopsListModel(shopCategories, shops, favoriteShops));
        }