Ejemplo n.º 1
0
        /// <summary>
        /// 根据角色id查询一条角色信息
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public static SysRole GetSysRoleById(int id)
        {
            SysRole   sr  = null;
            string    sql = "SELECT * FROM [dbo].[SysRole] where id = " + id;
            DataTable dt  = DBHelperSQL.Query(sql).Tables[0];

            foreach (DataRow dr in dt.Rows)
            {
                sr              = new SysRole();
                sr.Id           = Convert.ToInt32(dr["id"]);
                sr.RoleName     = dr["RoleName"].ToString();
                sr.RoleDesc     = dr["RoleDesc"].ToString();
                sr.CreatingTime = Convert.ToDateTime(dr["creatingTime"]);
                sr.DepartmentId = Convert.ToInt32(dr["departmentId"]);
                sr.Status       = Convert.ToInt32(dr["Status"]);
                sr.IsPayOrder   = Convert.ToInt32(dr["isPayOrder"]);
            }
            return(sr);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 查询所有的系统角色
        /// </summary>
        /// <returns></returns>
        public static List <SysRole> GetAllSysRole()
        {
            List <SysRole> list = new List <SysRole>();
            string         sql  = "SELECT * FROM [dbo].[SysRole] where id <> 1 order by creatingTime desc";
            DataTable      dt   = DBHelperSQL.Query(sql).Tables[0];

            foreach (DataRow dr in dt.Rows)
            {
                SysRole sr = new SysRole();
                sr.Id           = Convert.ToInt32(dr["id"]);
                sr.RoleName     = dr["RoleName"].ToString();
                sr.RoleDesc     = dr["RoleDesc"].ToString();
                sr.CreatingTime = Convert.ToDateTime(dr["creatingTime"]);
                sr.DepartmentId = Convert.ToInt32(dr["departmentId"]);
                sr.Status       = Convert.ToInt32(dr["Status"]);
                sr.IsPayOrder   = Convert.ToInt32(dr["isPayOrder"]);
                list.Add(sr);
            }
            return(list);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// 创建一个人员
        /// </summary>
        /// <param name="validationErrors">返回的错误信息</param>
        /// <param name="db">数据库上下文</param>
        /// <param name="entity">一个人员</param>
        /// <returns></returns>
        public bool Create(ref ValidationErrors validationErrors, SysEntities db, SysPerson entity)
        {
            int count = 1;
            if (CheckName(entity.Name))
            {
                validationErrors.Add("用户名已被占用,请换一个新的用户名");
                return false;
            }
            foreach (string item in entity.SysRoleId.GetIdSort())
            {
                SysRole sys = new SysRole { Id = item };
                db.SysRole.Attach(sys);
                entity.SysRole.Add(sys);
                count++;
            }

            repository.Create(db, entity);
            if (count == repository.Save(db))
            {
                return true;
            }
            else
            {
                validationErrors.Add("创建出错了");
            }
            return false;
        }
Ejemplo n.º 4
0
        /// <summary>
        /// 编辑一个人员
        /// </summary>
        /// <param name="validationErrors">返回的错误信息</param>
        /// <param name="db">数据上下文</param>
        /// <param name="entity">一个人员</param>
        /// <returns>是否编辑成功</returns>
        public bool Edit(ref ValidationErrors validationErrors, SysEntities db, SysPerson entity)
        {
            /*
                           * 不操作 原有 现有
                           * 增加   原没 现有
                           * 删除   原有 现没
                           */
            if (entity == null)
            {
                return false;
            }
            if (CheckName(entity))
            {
                validationErrors.Add("用户名已被占用,请换一个新的用户名");
                return false;
            }

            int count = 1;
            SysPerson editEntity = repository.Edit(db, entity);

            List<string> addSysRoleId = new List<string>();
            List<string> deleteSysRoleId = new List<string>();
            DataOfDiffrent.GetDiffrent(entity.SysRoleId.GetIdSort(), entity.SysRoleIdOld.GetIdSort(), ref addSysRoleId, ref deleteSysRoleId);
            if (addSysRoleId != null && addSysRoleId.Count() > 0)
            {
                foreach (var item in addSysRoleId)
                {
                    SysRole sys = new SysRole { Id = item };
                    db.SysRole.Attach(sys);
                    editEntity.SysRole.Add(sys);
                    count++;
                }
            }
            if (deleteSysRoleId != null && deleteSysRoleId.Count() > 0)
            {
                List<SysRole> listEntity = new List<SysRole>();
                foreach (var item in deleteSysRoleId)
                {
                    SysRole sys = new SysRole { Id = item };
                    listEntity.Add(sys);
                    db.SysRole.Attach(sys);
                }
                foreach (SysRole item in listEntity)
                {
                    editEntity.SysRole.Remove(item);//查询数据库
                    count++;
                }
            }

            if (count == repository.Save(db))
            {
                return true;
            }
            else
            {
                validationErrors.Add("编辑人员出错了");
            }
            return false;
        }
Ejemplo n.º 5
0
 /// <summary>
 /// 编辑一个角色对象
 /// </summary>
 /// <param name="db">实体数据</param>
 /// <param name="entity">将要编辑的一个角色对象</param>
 public SysRole Edit(SysEntities db, SysRole entity)
 {
     db.SysRole.Attach(entity);
     db.ObjectStateManager.ChangeObjectState(entity, EntityState.Modified);
     return(entity);
 }