/// <summary> /// 根据产品类别删除删除 /// </summary> /// <param name="cateNum"></param> /// <returns></returns> public int Delete(IEnumerable <string> list) { string Key = string.Format(CacheKey.JOOSHOW_PRODUCTCATEGORY_CACHE, this.CompanyID); using (TransactionScope ts = new TransactionScope()) { int line = 0; List <ProductCategoryEntity> listSource = GetList(); listSource = listSource.IsNull() ? new List <ProductCategoryEntity>() : listSource; foreach (string item in list) { ProductCategoryEntity parent = listSource.FirstOrDefault(a => a.SnNum == item); int rightValue = parent.Right; int leftValue = parent.Left; ProductCategoryEntity delCategory = new ProductCategoryEntity(); delCategory.IsDelete = (int)EIsDelete.Deleted; delCategory.IncludeIsDelete(true); delCategory.Where(a => a.Left >= leftValue) .And(a => a.Right <= rightValue) .And(a => a.CompanyID == this.CompanyID) ; line += this.ProductCategory.Update(delCategory); List <ProductCategoryEntity> listNodes = listSource.Where(a => a.Left > leftValue).ToList(); if (!listNodes.IsNullOrEmpty()) { foreach (ProductCategoryEntity cate in listNodes) { cate.Left = cate.Left - (rightValue - leftValue + 1); cate.IncludeLeft(true); cate.Where(a => a.SnNum == cate.SnNum).And(a => a.CompanyID == this.CompanyID); line += this.ProductCategory.Update(cate); } } listNodes = listSource.Where(a => a.Right > rightValue).ToList(); if (!listNodes.IsNullOrEmpty()) { foreach (ProductCategoryEntity cate in listNodes) { cate.Right = cate.Right - (rightValue - leftValue + 1); cate.IncludeRight(true); cate.Where(a => a.SnNum == cate.SnNum).And(a => a.CompanyID == this.CompanyID); line += this.ProductCategory.Update(cate); } } } if (line > 0) { CacheHelper.Remove(Key); } ts.Complete(); return(line); } }
/// <summary> /// 根据产品类别删除删除 /// </summary> /// <param name="cateNum"></param> /// <returns></returns> public int Delete(string cateNum) { ProductCategoryEntity entity = new ProductCategoryEntity(); entity.Where(a => a.CateNum == cateNum); entity.IsDelete = (int)EIsDelete.Deleted; entity.IncludeIsDelete(true); int line = this.ProductCategory.Update(entity); if (line > 0) { CacheHelper.Remove(CacheKey.JOOSHOW_PRODUCTCATEGORY_CACHE); } return(line); }
/// <summary> /// 批量删除产品类型 /// </summary> /// <param name="list"></param> /// <returns></returns> public int DelBat(List <string> list) { using (TransactionScope ts = new TransactionScope()) { int line = 0; foreach (string cateNum in list) { ProductCategoryEntity entity = new ProductCategoryEntity(); entity.Where(a => a.CateNum == cateNum); entity.IsDelete = (int)EIsDelete.Deleted; entity.IncludeIsDelete(true); line += this.ProductCategory.Update(entity); } ts.Complete(); if (line > 0) { CacheHelper.Remove(CacheKey.JOOSHOW_PRODUCTCATEGORY_CACHE); } return(line); } }