public ActionResult Shop(int?pageIndex)
        {
            var goodIds = ShopingServices.LoadEntities(s => s.UserInfoId == CurrentLoginUser.Id && s.DelFlag == normal);

            if (pageIndex == null || pageIndex <= 0)
            {
                pageIndex = 1;
            }

            List <Shops> list = new List <Shops>();

            int total = 0;

            if (goodIds != null)
            {
                foreach (var item in goodIds)
                {
                    Shops shop   = new Shops();
                    int   goodid = item.GoodsId;
                    Goods good   = GoodsServices.LoadPageEntities((int)pageIndex, 5, out total, u => u.Id == goodid
                                                                  , u => u.Id, true).FirstOrDefault();

                    shop.ShopId = item.Id;
                    shop.Goods  = good;
                    list.Add(shop);
                }
            }

            ViewData["allGoods"]  = list;
            ViewData["pageIndex"] = pageIndex;
            ViewData["Count"]     = total;
            return(View());
        }
Example #2
0
        public ActionResult AddShouCang(int userId, int goodId)
        {
            var good = GoodsServices.LoadEntities(u => u.Id == goodId).FirstOrDefault();

            if (good == null)
            {
                return(Content("数据有误"));
            }

            Shoping shop = new Shoping();

            shop.GoodsId    = good.Id;
            shop.UserInfoId = userId;
            shop.DelFlag    = normal;
            shop.SubTime    = DateTime.Now;

            try
            {
                ShopingServices.Add(shop);
                return(Content("加入收藏成功"));
            }
            catch (Exception)
            {
                return(Content("错误,请重试"));
            }
        }
        public ActionResult DeleteShop(int id)
        {
            Shoping shop = ShopingServices.LoadEntities(s => s.Id == id).FirstOrDefault();

            if (shop == null)
            {
                return(Content("数据错误,请刷新本页面"));
            }
            shop.DelFlag = delete;

            try
            {
                ShopingServices.Update(shop);
                return(Content("ok"));
            }
            catch (Exception)
            {
                return(Content("数据库错误,请联系管理员"));

                throw;
            }
        }