>>Say, in Accounts API controller I have this code:
>>
>>
>>private void SetOperatorAndSalespoint(Accounts account)
>> {
>> account.Operator = OperatorSession.OpCode;
>> account.Salespoint = SysManagerConstants.SYSMANAGER_SALESPOINT_NAME;
>> account.DateTime = DateTime.Now;
>> }
>>
>>which is called when account is updated and it works fine. But when the same code is called from the Invoices API controller when invoice is updated, the OperatorSession is null. I also believe it used to work and got broken quite recently but I am not sure where to start investigating.
>
>So where does the 'OperatorSession' come from ?
>IAC, a message handler in the pipeline is not difficult to implement and looks to me like a good place for the above code (always assuming that it is possible to identify incoming requests which require the addition).....
With the help of my colleague we figured out why the OperatorSession was null in one case and not null in another. We do have Authentication attribute. I was thinking it's an MVC attribute but it's apparently something developed internally for this application. If that attribute is set, the OperatorSession is eventually not null. If the class doesn't have that attribute, the property of the class is null.
I removed the Authentication attribute from the class level for Invoices controller as I call the same controller from two different areas right now (Customer Accounts and Guests) and I was thinking it needs to have different rights depending on the caller. But that doesn't seem to work, so I put the original code for the attribute back in and it resolved this problem.
It didn't, of course, resolve the problem of the thread as how to use one generic method of updating properties that may exist only for some classes. I will look closer at your suggestion and also try to discuss this problem in our group.
If it's not broken, fix it until it is.
My Blog