Пример #1
0
        public ActionResult List()
        {
            List <GoodsModel> modelList = new List <GoodsModel>();

            foreach (var item in _goodsBLL.GetAllNoDeteledGoods())
            {
                GoodsModel gm = new GoodsModel(item);
                gm.PicturePath = _goodsImagesBLL.GetPictureByGoodsId(item.Id).ImagePath;
                gm.IsRecommend = _recommendBLL.IsRecommend(gm.Id);
                modelList.Add(gm);
            }
            ViewData["GoodsList"] = modelList;
            return(View());
        }
Пример #2
0
        public ActionResult GetGoodsList(string categoryCode)
        {
            // 先取出当前vip等级会员折扣
            Member member   = _memberBLL.GetMemberByOpenId(System.Web.HttpContext.Current.Session["member"].ToString());
            double discount = _rulesBLL.GetDiscountByVIP(member.Vip);

            List <GoodsModel> goodsList = new List <GoodsModel>();

            // 判断传递进来的categoryCode 是否为空

            // 如果为空 则搜索出所有没有标记为删除的Goods对象

            if (categoryCode == null)
            {
                // 得到所有Goods对象之后  遍历  构造出 GoodsModel list
                foreach (var item in _goodsBLL.GetAllNoDeteledGoods())
                {
                    GoodsModel gm = new GoodsModel(item);
                    gm.PicturePath = _goodsImagesBLL.GetPictureByGoodsId(gm.Id).ImagePath;
                    gm.Discount    = discount;
                    goodsList.Add(gm);
                }
            }
            else
            {
                // 如果传进来的categoryCode 不为空

                // 则要根据这个categoryCode 找到对应的Category对象

                // 然后通过找到的category对象 得到  GoodsCategoryList

                Category             category          = _categoryBLL.GetCategoryByCategoryNo(categoryCode);
                List <GoodsCategory> goodsCategoryList = _goodsCategoryBLL.GetGoodsCategoryListByCategoryId(category.Id).ToList();

                // 最后再构造 GoodModelList
                foreach (var item in goodsCategoryList)
                {
                    GoodsModel gm = new GoodsModel(_goodsBLL.GetGoodsById(item.GoodsId));
                    gm.PicturePath = _goodsImagesBLL.GetPictureByGoodsId(item.GoodsId).ImagePath;
                    gm.Discount    = discount;
                    goodsList.Add(gm);
                }
            }

            // 由于这个方法需要与前端传递 List对象

            // 所以要将等到的 GoodsModel List 序列化为 json字符串 传递到前端

            string jsonResult = string.Empty;

            try
            {
                // 序列化
                jsonResult = ObjToJson <List <GoodsModel> >(goodsList);
            }
            catch (Exception ex)
            {
                LogHelper.Log.Write(ex.Message);
                LogHelper.Log.Write(ex.StackTrace);
                throw;
            }

            return(Content(jsonResult));
        }