Exemplo n.º 1
0
        public ActionResult AddFavoriteShop(int shopId)
        {
            if(!User.Identity.IsAuthenticated)
                return Json(new { type = 2 }, JsonRequestBehavior.AllowGet);

            try
            {
                ShopModel shopModel = new ShopModel();
                UserModel userModel = new UserModel();
                UserInfo userInfo = userModel.GetUserInfo(User.Identity.Name);

                if(userModel.GetUserFavoriteShop(shopId, userInfo.Id) != null)
                    return Json(new { type = 1 }, JsonRequestBehavior.AllowGet);

                UserFavoriteShop favShop = new UserFavoriteShop();
                favShop.UserId = userInfo.Id;
                favShop.ShopId = shopId;
                favShop.CreateTime = DateTime.Now;
                userModel.Add(favShop);
            }
            catch(Exception ex)
            {
                return Json(new { type = 0, data = ex.Message }, JsonRequestBehavior.AllowGet);
            }

            return Json(new { type = 1 }, JsonRequestBehavior.AllowGet);
        }
Exemplo n.º 2
0
        public ActionResult CancelFavoriteShop(int shopId)
        {
            try
            {
                UserModel userModel = new UserModel();
                UserInfo userInfo = userModel.GetUserInfo(User.Identity.Name);
                UserFavoriteShop favShop = userModel.GetUserFavoriteShop(shopId, userInfo.Id);
                userModel.Delete(favShop);
            }
            catch(Exception ex)
            {
                return Json(new { type = 0, data = ex.Message }, JsonRequestBehavior.AllowGet);
            }

            return Json(new { type = 1 }, JsonRequestBehavior.AllowGet);
        }
Exemplo n.º 3
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)));
        }