MonoX support board

Start the conversation, ask questions and share tips and solutions with fellow developers.

Non-registered users can only browse through our support boards. Please register now if you want to post your questions. It takes a second and it is completely free. Alternatively, you can log in without registration using your credentials at major sites such as Google, Microsoft Live, OpenId, Facebook, LinkedIn or Yahoo.

Programmicaly add rules ?  (Mono Support )

Viewed 13708 time(s), 6 post(s) 5/2/2012 4:53:03 PMby shawndg
shawndg

shawndg

5/2/2012 4:53:03 PM
Hi Guys,

I want to add rules during registration and so far I did try setting it in the web config but that did not work.. maybe because my rule is custom..

The following code, does not work but I think it is close.

//add default isband rule to band profiles..

IEnumerable<MonoSoftware.MonoX.API.Role> Rules = new IEnumerable<MonoSoftware.MonoX.API.Role>();
Rules = SecurityUtility.UserRoleIds(userId);

MonoSoftware.MonoX.API.RoleAdapter ruleadb = MonoSoftware.MonoX.API.RoleAdapter.GetInstance();
ruleadb.ChangeUserRoles(userId, Rules);

any help ?

thanks
This content has not been rated yet. 
1871 Reputation 252 Total posts
pajo

pajo

5/3/2012 6:50:26 AM
Hi shawndg,

If you're trying to add new roles to the user, you should try this

var userRoles = MonoSoftware.MonoX.API.RoleAdapter.GetInstance().GetUserRoles(userId).ToList();
 
userRoles.Add(MonoSoftware.MonoX.API.RoleAdapter.GetInstance().First(role => role.Name == "YourRole"));
 
MonoSoftware.MonoX.API.RoleAdapter.GetInstance().ChangeUserRoles(userId, userRoles);
This content has not been rated yet. 
629 Reputation 83 Total posts
shawndg

shawndg

5/3/2012 5:14:05 PM
The code does not work.. =/

Error 19 'MonoSoftware.MonoX.API.RoleAdapter' does not contain a definition for 'First' and no extension method 'First' accepting a first argument of type 'MonoSoftware.MonoX.API.RoleAdapter' could be found (are you missing a using directive or an assembly reference?) C:\#PittsburghSceneProd\CustomParts\BandRegister\MembershipEditor.ascx.cs 119 76 Portal
Error 18 'System.Linq.IQueryable<MonoSoftware.MonoX.API.Role>' does not contain a definition for 'ToList' and no extension method 'ToList' accepting a first argument of type 'System.Linq.IQueryable<MonoSoftware.MonoX.API.Role>' could be found (are you missing a using directive or an assembly reference?) C:\#PittsburghSceneProd\CustomParts\BandRegister\MembershipEditor.ascx.cs 118 99 Portal


Note im using .net 4.0 and the latest MonoX
This content has not been rated yet. 
1871 Reputation 252 Total posts
shawndg

shawndg

5/3/2012 5:16:27 PM
Missing..

using System.Linq;

my bad..
This content has not been rated yet. 
1871 Reputation 252 Total posts
shawndg

shawndg

5/3/2012 5:45:41 PM
still no dice.. =/

//add default isband rule to band profiles..
var userRoles = MonoSoftware.MonoX.API.RoleAdapter.GetInstance().GetUserRoles(userId).ToList();
userRoles.Add(MonoSoftware.MonoX.API.RoleAdapter.GetInstance().First(role => role.Name == "isband"));
MonoSoftware.MonoX.API.RoleAdapter.GetInstance().ChangeUserRoles(userId, userRoles);

{"Object reference not set to an instance of an object."}
happens on line ..
userRoles.Add(MonoSoftware.MonoX.API.RoleAdapter.GetInstance().First(role => role.Name == "isband"));


This content has not been rated yet. 
1871 Reputation 252 Total posts
imarusic

imarusic

5/10/2012 12:05:32 PM
Hi shawdg,

Did you try with DefaultUserRoles property in web.config? By setting that property newly registered user should be added in role(s) defined by that property.

Have you checked that your role exist in database?

Regards.
This content has not been rated yet. 
3016 Reputation 428 Total posts