Пример #1
0
        public ActionResult DeleteGoodsCategory(int id)
        {
            JsonModel         jm = new JsonModel();
            IGoodsCategoryBLL goodsCategoryBll = BLLFactory <IGoodsCategoryBLL> .GetBLL("GoodsCategoryBLL");

            //获取要删除的类别
            T_GoodsCategory goodsCategory = goodsCategoryBll.GetEntity(m => m.Id == id);

            if (goodsCategory == null)
            {
                jm.Msg = "该类别不存在";
            }
            else if (goodsCategory.ShopSales.Count() > 0)
            {
                jm.Msg = "已有该类型的商品,无法删除";
            }
            else
            {
                if (goodsCategoryBll.Delete(goodsCategory))
                {
                    //操作日志
                    jm.Content = "删除商品类别 " + goodsCategory.Name;
                }
                else
                {
                    jm.Msg = "删除失败";
                }
            }
            return(Json(jm, JsonRequestBehavior.AllowGet));
        }
Пример #2
0
        public ApiResultModel DelGoodsCategory(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);

                    if (model.Id.HasValue)
                    {
                        IGoodsCategoryBLL goodsBLL = BLLFactory <IGoodsCategoryBLL> .GetBLL("GoodsCategoryBLL");

                        var goodsCategory = goodsBLL.GetEntity(g => g.Id == model.Id.Value);

                        if (goodsCategory == null)
                        {
                            resultModel.Msg = "该商品分类不存在";
                        }
                        else if (goodsCategory.ShopSales.Count() > 0)
                        {
                            resultModel.Msg = "已有该商品分类的商品,无法删除";
                        }
                        else
                        {
                            goodsBLL.Delete(goodsCategory);
                        }
                    }
                }
                else
                {
                    resultModel.Msg = APIMessage.NO_USER;
                }
            }
            catch
            {
                resultModel.Msg = APIMessage.REQUEST_EXCEPTION;
            }

            return(resultModel);
        }