Exemplo n.º 1
0
        /// <summary>
        /// 删除
        /// </summary>
        /// <param name="roleId"></param>
        /// <returns></returns>
        public int Delete(int roleId)
        {
            using (Entities db = new Entities())
            {
                base_roles roles = db.base_roles.First(t => t.id == roleId);
                if (roles != null)
                {
                    //删除现有角色权限
                    List <base_rolepermissions> rpList = db.base_rolepermissions.Where(t => t.roleid == roleId).ToList();

                    if (rpList.Count > 0)
                    {
                        foreach (var rp in rpList)
                        {
                            db.base_rolepermissions.Remove(rp);
                        }
                    }

                    //删除角色
                    db.base_roles.Remove(roles);
                }

                db.base_roles.Remove(roles);
                return(db.SaveChanges());
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// 新增
        /// </summary>
        /// <param name="roles"></param>
        /// <returns></returns>
        public void Insert(Role roles)
        {
            using (Entities db = new Entities())
            {
                base_roles roleEnd = new base_roles();
                roleEnd.id          = roles.ID;
                roleEnd.name        = roles.Name;
                roleEnd.issystem    = 0;
                roleEnd.seqno       = roles.SeqNo;
                roleEnd.updatedtime = DateTime.Now;
                roleEnd.createdtime = DateTime.Now;
                roleEnd.comment     = roles.Comment;
                db.base_roles.Add(roleEnd);
                db.SaveChanges();

                foreach (string permissionCode in roles.PermissionCodeArr)
                {
                    base_rolepermissions newRp = new base_rolepermissions()
                    {
                        roleid         = roleEnd.id,
                        permissioncode = permissionCode
                    };
                    db.base_rolepermissions.Add(newRp);
                }

                db.SaveChanges();
            }
        }
Exemplo n.º 3
0
 /// <summary>
 /// 查询单条数据
 /// </summary>
 /// <param name="roleId"></param>
 /// <returns></returns>
 public base_roles SelectSingle(int roleId)
 {
     using (Entities db = new Entities())
     {
         base_roles roles = db.base_roles.First(t => t.id == roleId);
         return(roles);
     }
 }
Exemplo n.º 4
0
        /// <summary>
        /// 编辑
        /// </summary>
        /// <param name="roles"></param>
        /// <returns></returns>
        public void Edit(Role roles)
        {
            using (Entities db = new Entities())
            {
                base_roles rolesEdit = db.base_roles.Find(roles.ID);
                if (rolesEdit != null)
                {
                    rolesEdit.name        = roles.Name;
                    rolesEdit.comment     = roles.Comment;
                    rolesEdit.seqno       = roles.SeqNo;
                    rolesEdit.updatedtime = DateTime.Now;

                    //删除现有角色权限
                    List <base_rolepermissions> rpList = db.base_rolepermissions.Where(t => t.roleid == roles.ID && !t.permissioncode.Contains("PHONE_")).ToList();

                    if (rpList.Count > 0)
                    {
                        foreach (var rp in rpList)
                        {
                            db.base_rolepermissions.Remove(rp);
                        }
                    }

                    //添加新角色权限
                    foreach (string permissionCode in roles.PermissionCodeArr)
                    {
                        base_rolepermissions newRp = new base_rolepermissions()
                        {
                            roleid         = rolesEdit.id,
                            permissioncode = permissionCode
                        };
                        db.base_rolepermissions.Add(newRp);
                    }
                    db.SaveChanges();
                }
            }
        }