AllowWrite If Empty

AllowWrite If Empty

Old forum URL:

Norman.Mann posted on Tuesday, June 22, 2010


I have an Id field in my BO that will potentially be used by used by other applications (e.g. SharePoint Business Data Catalog) as a primary key. The idea is to provide a key value that is set 'by hand' and easy to remember (a little bit like CustomerId 'ALFKI').

When a new instance of the BO is created I want all users to be able to fill this field. Once the field has a value only a certain group of people (e.g. Administrators) are allowed to change the field value because this would obviously have an impact on other applications.

What would be a good way to accomplish this ?



RobKraft replied on Tuesday, June 22, 2010

We overwrite CanWriteProperty in the BO with something like this:

        public override bool CanWriteProperty(string propertyName)
            bool canWrite = base.CanWriteProperty(propertyName); //Call base.CanWriteProperty before referencing specific methods in this B.O. to prevent object instantiation when unnecessary
            if (canWrite == true)
                switch (propertyName)
                    case "OurPropertyName":
                        if (!IsNew)
                            return false;
            return canWrite;

RockfordLhotka replied on Tuesday, June 22, 2010

Rob is right for 2.1-3.8. In CSLA 4 you can create an authorization rule that does what you need - examining the state of the object to decide whether to return true or false.

Copyright (c) Marimer LLC