コード例 #1
0
        /// <summary>
        /// 编辑一个菜单
        /// </summary>
        public bool Edit(SMMENUTB entity)
        {  /*
            * 不操作 原有 现有
            * 增加   原没 现有
            * 删除   原有 现没
            */
            var editEntity = LoadEntities(m => m.ID == entity.ID).FirstOrDefault();

            if (editEntity == null)
            {
                return(false);
            }

            //层级
            var result = LoadEntities(x => x.ID == entity.PARENTID).Select(x => x.MENULEVEL).FirstOrDefault();
            int level  = result == null ? 1 : (int)result + 1;

            editEntity.MENULEVEL = level;

            List <int> addSysOperationId    = new List <int>();
            List <int> deleteSysOperationId = new List <int>();

            DataOfDiffrent.GetDiffrent(entity.SysOperationId.GetIdSort(), entity.SysOperationIdOld.GetIdSort(), ref addSysOperationId, ref deleteSysOperationId);
            if (addSysOperationId != null && addSysOperationId.Count() > 0)
            {
                foreach (var item in addSysOperationId)
                {
                    SMFUNCTB sys = this.GetCurrentDbSession.ISMFUNCTBRepository.LoadEntities(x => x.FUNC_ID == item).FirstOrDefault(); //new SMFUNCTB { FUNC_ID = item };
                    editEntity.SMFUNCTB.Add(new MenuFunc()
                    {
                        Func = sys,
                        Menu = entity,
                    });
                }
            }
            if (deleteSysOperationId != null && deleteSysOperationId.Count() > 0)
            {
                List <SMFUNCTB> listEntity = new List <SMFUNCTB>();
                foreach (var item in deleteSysOperationId)
                {
                    SMFUNCTB sys = this.GetCurrentDbSession.ISMFUNCTBRepository.LoadEntities(x => x.FUNC_ID == item).FirstOrDefault(); //new SMFUNCTB { FUNC_ID = item };
                    listEntity.Add(sys);
                }
                foreach (SMFUNCTB item in listEntity)
                {
                    editEntity.SMFUNCTB.Remove(new MenuFunc()
                    {
                        FuncId = item.FUNC_ID,
                        Func   = item,
                        MenuId = entity.ID,
                        Menu   = entity,
                    });//查询数据库
                }
            }

            return(EditEntity(editEntity));
        }
コード例 #2
0
        public bool Edit(SMROLETB model)
        {
            var entity = LoadEntities(r => r.ROLE_ID == model.ROLE_ID).FirstOrDefault();

            entity.SysPersonId    = model.SysPersonId;
            entity.SysPersonIdOld = model.SysPersonIdOld;
            entity.REMARK         = model.REMARK;
            entity.ROLE_NAME      = model.ROLE_NAME;
            entity.STATUS         = model.STATUS;
            entity.UPDATE_TIME    = DateTime.Now;
            entity.UPDATE_USER    = model.UPDATE_USER;

            List <int> addSysPersonId    = new List <int>();
            List <int> deleteSysPersonId = new List <int>();

            DataOfDiffrent.GetDiffrent(entity.SysPersonId.GetIdSort(), entity.SysPersonIdOld.GetIdSort(),
                                       ref addSysPersonId, ref deleteSysPersonId);

            if (addSysPersonId != null && addSysPersonId.Count() > 0)
            {
                foreach (var item in addSysPersonId)
                {
                    SMUSERTB sys = this.GetCurrentDbSession.ISMUSERTBRepository.LoadEntities(u => u.USER_ID == item)
                                   .FirstOrDefault();
                    entity.SMUSERTB2.Add(new UserRole()
                    {
                        User = sys,
                        Role = entity,
                    });
                }
            }

            if (deleteSysPersonId != null && deleteSysPersonId.Count() > 0)
            {
                List <SMUSERTB> listEntity = new List <SMUSERTB>();
                foreach (var item in deleteSysPersonId)
                {
                    SMUSERTB sys = this.GetCurrentDbSession.ISMUSERTBRepository.LoadEntities(u => u.USER_ID == item)
                                   .FirstOrDefault();
                    listEntity.Add(sys);
                }

                foreach (SMUSERTB item in listEntity)
                {
                    entity.SMUSERTB2.Remove(new UserRole()
                    {
                        UserId = item.USER_ID,
                        User   = item,
                        RoleId = entity.ROLE_ID,
                        Role   = entity,
                    }); //查询数据库
                }
            }

            return(EditEntity(entity));
        }