Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Which layer is the best to add a new method?
Message
De
13/05/2015 12:57:20
 
 
Information générale
Forum:
ASP.NET
Catégorie:
Conception classe
Versions des environnements
Environment:
C# 4.0
OS:
Windows 7
Network:
Windows 2003 Server
Database:
MS SQL Server
Application:
Web
Divers
Thread ID:
01619738
Message ID:
01619745
Vues:
34
This message has been marked as a message which has helped to the initial question of the thread.
>>>Hi everybody,
>>>
>>>I am having a dilemma of the best implementation and wondering if you can make suggestions.
>>>
>>>In our database several tables have salespoint and operator columns (or similar named columns). These columns need to be populated with the currently logged operator and salespoint when a row is added or updated.
>>>
>>>For each of the table a model class is generated using Reverse POCO generator.
>>>
>>>For manipulations with the model class we use repository classes which are based on the RepositoryBase class which uses generics.
>>>
>>>Then we use adapter class (which is not based on anything) and then the API Controller class that also uses ViewModel (and not directly the model).
>>>
>>>So, I'd like to introduce a method that can update the operator and salespoint columns using OperatorSession static class.
>>>
>>>Currently I'm doing it in the API Controller class in each case when it's required (e.g. duplicating code).
>>>
>>>I am wondering what would be a best way to introduce such a generic method based on what I described.
>>>
>>>Thanks in advance for the suggestions.
>>
>>Hard to say without more detail. Presumably the 'current operator' information is available in the web api request. If so one option might be to add a message handler to populate the fields. Depends on how easy it is to know which routes/requests need the information.
>>
>>See: http://www.asp.net/web-api/overview/advanced/http-message-handlers
>
>Looks like a very complex approach to me by quickly scanning that page.
>
>Also, I found that OperatorSession is not always a valid object. In some cases it's null. I can not figure the difference yet when the object contains valid information and then the same static class is null.
>
>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).....
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform