Beispiel #1
0
        public JsonResult DeleteShop(int id)
        {
            JsonModel jm      = new JsonModel();
            IShopBLL  ShopBll = BLLFactory <IShopBLL> .GetBLL("ShopBLL");

            // 根据指定id值获取实体对象
            var shopInfo = ShopBll.GetEntity(s => s.Id == id);

            if (shopInfo != null)
            {
                //删除门店
                if (ShopBll.Delete(shopInfo))
                {
                    // 删除门店图片
                    if (!string.IsNullOrEmpty(shopInfo.ImgPath))
                    {
                        //删除文件图片
                        string[] imgPaths = shopInfo.ImgPath.Split(';');
                        foreach (var imgPath in imgPaths)
                        {
                            if (!string.IsNullOrEmpty(imgPath))
                            {
                                FileInfo f = new FileInfo(Server.MapPath(imgPath));
                                if (f.Exists)
                                {
                                    f.Delete();
                                }
                            }
                        }
                    }

                    // 删除门店缩略图片
                    if (!string.IsNullOrEmpty(shopInfo.ImgThumbnail))
                    {
                        //删除文件图片
                        string[] imgThumbnailPaths = shopInfo.ImgThumbnail.Split(';');
                        foreach (var imgPath in imgThumbnailPaths)
                        {
                            if (!string.IsNullOrEmpty(imgPath))
                            {
                                FileInfo f = new FileInfo(Server.MapPath(imgPath));
                                if (f.Exists)
                                {
                                    f.Delete();
                                }
                            }
                        }
                    }

                    jm.Content = "删除门店 " + shopInfo.ShopName;
                }
                else
                {
                    jm.Msg = "删除失败";
                }
            }
            else
            {
                jm.Msg = "该门店不存在";
            }
            return(Json(jm, JsonRequestBehavior.AllowGet));
        }