예제 #1
0
        /// <summary>
        /// 添加部门
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        public int Add(SysDepartEntity entity)
        {
            entity.DepartNum  = entity.DepartNum.IsEmpty() ? DateTime.Now.ToString("yyyyMMddHHmmss") + (new Random(DateTime.Now.Millisecond)).Next(1000, 9999) : entity.DepartNum;
            entity.ChildCount = 0;
            SysDepartEntity parent = GetSingle(entity.ParentNum);

            if (parent.IsNotNull())
            {
                entity.Depth = parent.Depth + 1;
                parent.ChildCount++;
                parent.IncludeDepth(true)
                .IncludeChildCount(true)
                .Where <SysDepartEntity>("DepartNum", ECondition.Eth);
                this.SysDepart.Update(parent);
            }
            entity.IncludeDepartNum(true)
            .IncludeDepartName(true)
            .IncludeChildCount(true)
            .IncludeParentNum(true)
            .IncludeDepth(true)
            .IncludeIsDelete(true)
            .IncludeCreateTime(true)
            ;
            int line = this.SysDepart.Add(entity);

            if (line > 0)
            {
                CacheHelper.Remove(CacheKey.JOOSHOW_SYSDEPART_CACHE);
            }
            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);
        }