Пример #1
0
        /// <summary>
        /// 删除部门信息
        /// </summary>
        /// <param name="list"></param>
        /// <param name="CompanyID"></param>
        /// <returns></returns>
        public int Delete(IEnumerable <string> list)
        {
            string key = string.Format(CacheKey.JOOSHOW_SYSDEPART_CACHE, this.CompanyID);

            using (TransactionScope ts = new TransactionScope())
            {
                int line = 0;

                List <SysDepartEntity> listSource = GetList();
                listSource = listSource.IsNull() ? new List <SysDepartEntity>() : listSource;

                foreach (string item in list)
                {
                    SysDepartEntity parent     = listSource.FirstOrDefault(a => a.SnNum == item);
                    int             rightValue = parent.Right;
                    int             leftValue  = parent.Left;

                    SysDepartEntity delDepart = new SysDepartEntity();
                    delDepart.IsDelete = (int)EIsDelete.Deleted;
                    delDepart.IncludeIsDelete(true);
                    delDepart.Where(a => a.Left >= leftValue)
                    .And(a => a.Right <= rightValue)
                    .And(a => a.CompanyID == this.CompanyID)
                    ;
                    line += this.SysDepart.Update(delDepart);

                    List <SysDepartEntity> listNodes = listSource.Where(a => a.Left > leftValue).ToList();
                    if (!listNodes.IsNullOrEmpty())
                    {
                        foreach (SysDepartEntity depart in listNodes)
                        {
                            depart.Left = depart.Left - (rightValue - leftValue + 1);
                            depart.IncludeLeft(true);
                            depart.Where(a => a.SnNum == depart.SnNum).And(a => a.CompanyID == this.CompanyID);
                            line += this.SysDepart.Update(depart);
                        }
                    }

                    listNodes = listSource.Where(a => a.Right > rightValue).ToList();
                    if (!listNodes.IsNullOrEmpty())
                    {
                        foreach (SysDepartEntity depart in listNodes)
                        {
                            depart.Right = depart.Right - (rightValue - leftValue + 1);
                            depart.IncludeRight(true);
                            depart.Where(a => a.SnNum == depart.SnNum).And(a => a.CompanyID == this.CompanyID);
                            line += this.SysDepart.Update(depart);
                        }
                    }
                }
                ts.Complete();
                if (line > 0)
                {
                    CacheHelper.Remove(key);
                }
                return(line);
            }
        }
Пример #2
0
        /// <summary>
        /// 删除部门
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public int DeleteDepart(int id)
        {
            int             line   = 0;
            SysDepartEntity entity = GetDepartEntity(id);

            if (entity.IsNotNull())
            {
                entity.IncludeIsDelete(true);
                entity.IsDelete = (int)EIsDelete.Deleted;
                entity.Where(a => a.ID == id);
                line = this.SysDepart.Update(entity);
                if (line > 0)
                {
                    CacheHelper.Remove(CacheKey.JOOSHOW_SYSDEPART_CACHE);
                }
            }
            return(line);
        }