How to use overloaded static properties

How to use overloaded static properties

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


esteban404 posted on Tuesday, December 09, 2008

I'm writing a 3.0.4 WinForm project and have one of those use cases where sometimes the object is editable by everyone, sometimes it's not. It all depends on a status in the order and the user's credentials.

I've created an overload like this:
public static bool CanEditObject(string status)
{
if (CanEditObject())
{
// These roles can edit even if not status 'I'
if (ApplicationContext.User.IsInRole("Quality")
|| ApplicationContext.User.IsInRole("Admin")
|| ApplicationContext.User.IsInRole("Eng"))
return true;
else
{
// Must be in Status 'I' for this user to edit
if (status.ToUpper().Equals("I") && ApplicationContext.User.IsInRole("Prod"))
{
return true;
}
else
return false;
}
}
else
return false;
}

When the objects are read from the db, I'm also retrieving the status value into the object. Within the above overload, I can check it and deny/grant access to the object. This seems to fly in the face of friendly design as there's nothing to let the user know they cannot edit the record until they attempt to do so.

Is this the correct approach and just add a field to the object for use in the UI to colorize the row? (GridViews) I should call this to set the field when fetched, probably. I've read all the posts on authorization rules and this is a type rule AFAIK and they will only work with one order at a time in the app, but there is the potential for dozens of records each could be editable.

My first CSLA project in a long while. I'm rusty.

Thanks,
_E

Copyright (c) Marimer LLC