Exemplo n.º 1
0
        public ActionResult Edit(int id)
        {
            ShopModel shopModel = new ShopModel();
            Shop shopBaseInfo = shopModel.GetShop(id);
            UserModel userModel = new UserModel();
            UserInfo userInfo = userModel.GetUserInfo(User.Identity.Name);
            if(userInfo.UserGradeCategory.GradeLevel != 9 && shopBaseInfo.CreateBy != userInfo.Id)
                return Redirect("/");
            List<V_ShopDisheWithCategory> shopDisheWithCategory = shopModel.GetShopDishesWithCategory(id).OrderByDescending(r => r.DisheCategoryOrder).ToList();

            var shopCategories = shopModel.GetShopCategories();

            SelectList shopCategoryList = new SelectList(shopCategories, "Id", "Value");
            List<SelectListItem> shopCategorySelectList = shopCategoryList.ToList();

            for(int i = 0; i < shopCategorySelectList.Count; i++)
                if(shopCategorySelectList[i].Value == shopBaseInfo.CategoryId.ToString())
                {
                    shopCategorySelectList[i].Selected = true;
                    break;
                }
            ViewBag.ShopCategorySelectList = shopCategorySelectList;

            BaseDataModel baseDataModel = new BaseDataModel();
            var cityDistricts = baseDataModel.GetLocationsByParentId(214);
            ViewBag.CityDistrictSelectList = (new SelectList(cityDistricts, "Id", "Value")).ToList();

            List<ServiceArea> shopServiceAraes = shopModel.GetShopServiceAreas(id).ToList()
                .Select(r => new ServiceArea() { Id = r.AreaId, ParentId = r.ParentId, Value = r.ServiceArea, AreaType = r.AreaType }).ToList();
            ViewBag.ServiceAreaSelectList = shopServiceAraes;

            ViewBag.ShopDisheCategoryList = shopDisheWithCategory.GroupBy(r => new { r.CategoryId, r.CategoryValue })
                .Select(r => new SelectListItem() { Value = r.Key.CategoryId.ToString(), Text = r.Key.CategoryValue }).ToList();

            ViewBag.ShopLogo = Url.Content(shopImagePath + shopBaseInfo.Logo);
            ViewBag.OffsetTime = offsetTime;
            return View(new ShopDetailEditorModel(shopBaseInfo, shopDisheWithCategory));
        }
Exemplo n.º 2
0
        public ActionResult Detail(int id, int p = 1)
        {
            id = 173;
            ShopModel shopModel = new ShopModel();
            V_ShopDetail shopInfo = shopModel.GetShopDetail(id);

            if (shopInfo == null)
                return RedirectToAction("HttpError404", "Error");

            /*ShopRankingAttribute rankAttr = shopModel.GetShopRankingAttribute(id);
            rankAttr.Visits += 1;
            shopModel.Save();*/

            ViewData["ShowShopPhone"] = true;

            var shopComments = shopModel.GetShopCommentsWithUserInfo(id);
            var shopServiceAreas = shopModel.GetShopServiceAreas(id);
            var shopDishes = shopModel.GetShopDishesWithCategory(id);

            ViewBag.UserFavoriteThisShop = false;
            ViewBag.UserId = -1;
            if(User.Identity.IsAuthenticated)
            {
                UserModel userModel = new UserModel();
                UserInfo userInfo = userModel.GetUserInfo(User.Identity.Name);
                ViewBag.UserId = userInfo.Id;
                ViewBag.UserName = userInfo.Name;
                UserFavoriteShop userFavoriteShop = userModel.GetUserFavoriteShop(id, userInfo.Id);
                if(userFavoriteShop != null)
                    ViewBag.UserFavoriteThisShop = true;
            }

            ViewBag.Id = id;
            Session["ShopDetailPhone"] = shopInfo.PhoneNumber;

            int pageSize = 5;
            int shopCommentsCount = shopComments.Count();
            ViewBag.ShopCommentsCount = shopCommentsCount;
            Paging.ToPaging(p, shopCommentsCount, this, pageSize);

            return View(new ShopDetailModel(shopInfo, shopServiceAreas, shopDishes, shopComments.Skip((p - 1) * pageSize).Take(pageSize)));
        }