public JsonResult DelShopSales(int id) { JsonModel Jm = new JsonModel(); try { //促销BLL IShopSaleBLL SaleBLL = BLLFactory <IShopSaleBLL> .GetBLL("ShopSaleBLL"); T_ShopSale ShopSale = SaleBLL.GetEntity(a => a.Id == id); //图片集合 List <string> Path = new List <string>(); //缩略图集合 List <string> ThumPath = new List <string>(); if (!string.IsNullOrEmpty(ShopSale.ImgPath) && !string.IsNullOrEmpty(ShopSale.ImgThumbnail)) { Path = ShopSale.ImgPath.Split(new char[] { ';' }).ToList(); ThumPath = ShopSale.ImgThumbnail.Split(new char[] { ';' }).ToList(); } //删除文件 for (int i = 0; i < ThumPath.Count; i++) { if (!string.IsNullOrEmpty(Path[i].Trim())) { //删除缩略图 DelFile(ThumPath[i]); //删除图片 //DelFile(Path[i]); } } if (ShopSale.OrderDetails.Count > 0) { Jm.Msg = "该商品已被订购,无法删除"; } else { //执行删除 SaleBLL.Delete(ShopSale); } } catch { Jm.Msg = "删除失败"; } return(Json(Jm, JsonRequestBehavior.AllowGet)); }
public ApiResultModel DelGoods(GoodsInfoModel 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) { IShopSaleBLL shopSaleBll = BLLFactory <IShopSaleBLL> .GetBLL("ShopSaleBLL"); var goods = shopSaleBll.GetEntity(g => g.Id == model.Id.Value); if (goods == null) { resultModel.Msg = "该商品不存在"; } else { if (goods.OrderDetails.Count > 0) { resultModel.Msg = "该商品已被订购,无法删除"; } else { var imagePath = goods.ImgPath; var imgThumbnail = goods.ImgThumbnail; shopSaleBll.Delete(goods); if (!string.IsNullOrWhiteSpace(imagePath)) { if (imagePath.Contains(";")) { foreach (var path in imagePath.Split(';')) { DelFile(path); } } else { DelFile(imagePath); } } if (!string.IsNullOrWhiteSpace(imgThumbnail)) { if (imgThumbnail.Contains(";")) { foreach (var path in imgThumbnail.Split(';')) { DelFile(path); } } else { DelFile(imgThumbnail); } } } } } } else { resultModel.Msg = APIMessage.NO_USER; } } catch { resultModel.Msg = APIMessage.REQUEST_EXCEPTION; } return(resultModel); }