is it possible to pass an object to the bo's save method

is it possible to pass an object to the bo's save method

Old forum URL: forums.lhotka.net/forums/t/1332.aspx


dstarkey posted on Tuesday, September 26, 2006

for example, i would like to implement something like the following.  But get the error no overridable method exists and I do not know how to implement this logic.  The role object need to be passed to the CanAdd and CanEdit.  This works when using the CanGet because I pass in the object as part of the static method.

public override EmployeeEM Save(Role rl)

{

// origEmp is used to call pending changes with only props that have changed.

if (!IsNew) // only retrieve this original if the record exists !

origEmp = EmployeeEM.GetEmployeeByEmpno(this.LocNo, this.EmpNo);

if (IsNew && !CanAddObject(rl))

throw new System.Security.SecurityException(

"User not authorized to add an Employee Record!");

else if (!CanEditObject(rl))

throw new System.Security.SecurityException(

"User not authorized to update an Employee Record!");

return base.Save();

}

thanks for your help, stuck on this.

ajj3085 replied on Tuesday, September 26, 2006

I think if you change override to new you'll get the behavior your want.  I don't think its a good idea though.

Why are you passing a role into the save method?  Seems an odd thing to do..

dstarkey replied on Tuesday, September 26, 2006

I am doing it in order to make my bo's more efficient.  It just so happens that the application I am working on would have over 30000 roles, a userID, and the Location and Division which would grant that user access to the site.  Rather than hard code each role, or even populate this section I pass in the role requested through the role object.  for example: userId 38322, location 8765 division 1.  Since the userId roles was populated in the identity object in the same format I can simply send the userId, and the requested location and division and compare them to the allowed roles maintained in the identity object.  I knew of know other way to do this.  This way instead of 30000 entries in each "Canxxxx" method, I have very few.  for example:

public static bool CanAddObject(Role rl)

{

bool result = false;

if (Csla.ApplicationContext.User.IsInRole(rl.RockyRole + ":Worksite Manager"))
result =
true;

if (Csla.ApplicationContext.User.IsInRole(rl.RockyRole + ":Internal Employee"))
result =
true;

return result;

}

I know it could be improved, but couldnt figure out a different solution.  Then I had to figure out a way to make the role available through the insert and save methods.  Once again, I had a difficult time with this, and finally made an extra property called currentRole (which i set in the ui, just before the update) and am able to check this property from within  the bo.  Any suggestions or alternate solutions are greatly appreciated.

 

ajj3085 replied on Tuesday, September 26, 2006

Yikes..

Hmm... is it possible to create your own principal class and perhaps implement the build of the exact role name in the IsInRole method?

It seems to me that the logic for determining the role name should be encapsulated in a class, which would free you of having to pass around a role class.  Perhaps this class can collaborate with your custom principal object as well.

I really recommend thinking about how you could do that... because these kinds of changes will also leave you with some pain down the line, making it harder to keep current with the newest versions of Csla, if that is something you think you would like to do.

Andy

Copyright (c) Marimer LLC