Example #1
0
        public ActionResult AddGoodsCategory(GoodsCategoryModel model)
        {
            JsonModel jm = new JsonModel();

            //如果表单模型验证成功
            if (ModelState.IsValid)
            {
                IGoodsCategoryBLL goodsCategoryTypeBll = BLLFactory <IGoodsCategoryBLL> .GetBLL("GoodsCategoryBLL");

                T_GoodsCategory goodsCategory = new T_GoodsCategory()
                {
                    Name   = model.Name,
                    ShopId = GetCurrentShopId().Value
                };
                // 保存
                goodsCategoryTypeBll.Save(goodsCategory);

                //日志记录
                jm.Content = PropertyUtils.ModelToJsonString(model);
            }
            else
            {
                // 保存异常日志
                jm.Msg = ConstantParam.JSON_RESULT_MODEL_CHECK_ERROR;
            }
            return(Json(jm, JsonRequestBehavior.AllowGet));
        }
Example #2
0
        public ApiResultModel AddGoodsCategory(GoodsCategoryInfoModel model)
        {
            ApiResultModel resultModel = new ApiResultModel();

            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");

                    if (goodsBLL.Exist(m => m.Name == model.Name && m.ShopId == model.ShopId))
                    {
                        resultModel.Msg = "该商品类别已经存在";
                    }
                    else
                    {
                        //商品分类实例化
                        T_GoodsCategory goods = new T_GoodsCategory()
                        {
                            Name   = model.Name,
                            ShopId = model.ShopId
                        };
                        //保存商品分类

                        goodsBLL.Save(goods);
                    }
                }
                else
                {
                    resultModel.Msg = APIMessage.NO_USER;
                }
            }
            catch
            {
                resultModel.Msg = APIMessage.REQUEST_EXCEPTION;
            }

            return(resultModel);
        }