Exemplo n.º 1
0
        public ApiPageResultModel GetGoodsCategoryList([FromUri] GoodsCategorySearchModel model)
        {
            ApiPageResultModel resultModel = new ApiPageResultModel();

            try
            {
                //获取当前用户
                IShopUserBLL userBll = BLLFactory <IShopUserBLL> .GetBLL("ShopUserBLL");

                T_ShopUser user = userBll.GetEntity(u => u.Id == model.UserId && u.DelFlag == ConstantParam.DEL_FLAG_DEFAULT);

                //如果业主存在
                if (user != null)
                {
                    //如果验证Token不通过或已过期
                    if (DateTime.Now > user.TokenInvalidTime || model.Token != user.Token)
                    {
                        resultModel.Msg = APIMessage.TOKEN_INVALID;
                        return(resultModel);
                    }
                    //更新最近登录时间和Token失效时间
                    user.LatelyLoginTime  = DateTime.Now;
                    user.TokenInvalidTime = DateTime.Now.AddDays(Convert.ToInt32(PropertyUtils.GetConfigParamValue("TokenInvalid")));
                    userBll.Update(user);

                    IGoodsCategoryBLL goodsBLL = BLLFactory <IGoodsCategoryBLL> .GetBLL("GoodsCategoryBLL");

                    Expression <Func <T_GoodsCategory, bool> > where = g => g.ShopId == model.ShopId;
                    // 获取商家的商品分类
                    var list = goodsBLL.GetPageList(where, model.PageIndex).Select(
                        g => new
                    {
                        Id    = g.Id,
                        Name  = g.Name,
                        Count = g.ShopSales.Count()
                    }).ToList();

                    resultModel.result = list;
                    resultModel.Total  = goodsBLL.Count(g => g.ShopId == model.ShopId);
                }
                else
                {
                    resultModel.Msg = APIMessage.NO_USER;
                }
            }
            catch
            {
                resultModel.Msg = APIMessage.REQUEST_EXCEPTION;
            }

            return(resultModel);
        }
Exemplo n.º 2
0
        public ActionResult GoodsCategoryList(GoodsCategoryModel model)
        {
            IGoodsCategoryBLL goodsCategoryBll = BLLFactory <IGoodsCategoryBLL> .GetBLL("GoodsCategoryBLL");

            var shopId = GetCurrentShopId().Value;

            Expression <Func <T_GoodsCategory, bool> > where = u => (string.IsNullOrEmpty(model.Name) ? true : u.Name.Contains(model.Name)) && u.ShopId == shopId;
            //查询条件
            //排序
            var sortModel = this.SettingSorting("Id", false);

            //将查询到的数据赋值传到页面
            model.DataList = goodsCategoryBll.GetPageList(where, sortModel.SortName, sortModel.IsAsc, model.PageIndex) as PagedList <T_GoodsCategory>;
            return(View(model));
        }