views:

58

answers:

2

I writing an MVC app and I'm really struggling to keep my controllers lean and limit the number of actions.

For example, here is a look at my ReportController actions: OpenCall
ClosedCall
ServiceLevelAgreement
Barrier
Resolution
Repair
Failure
Inventory
CustomerLocation

These are all my different reports. Should I be making a controller for each one?

Here is a look at my ServiceCallController actions: New
Create
Reopen
UpdateETA
UpdateOnsite
UpdateServiceTimes
UpdateEnroute
Close
Cancel
Reassign
Show
ModifyAfterClose

This are all different actions I need to take based on what the user wants to do. Can anyone help me out here with how to clean this up?

+1  A: 

I think it's clean already. If an object of yours is capable of doing 7-8 actions, then your structure is the way to go. If you had one controller that is responsible for the actions of multiple business objects, then I'd have suggested you change it into the way your current design is in.

One thing though about your current design, it'd be a good idea to just have one update action on ServiceCallController and that action could take what to update as a parameter. After all, all those update actions do one thing : update your business object.

But if you are still not satisfied, then you can just have one action that's named "do" which takes the action as parameter and passes that to a service layer which returns what the request wanted. But IMO, that wouldn't be a good design, so I definitely don't suggest it.

çağdaş
A: 

If the file it self is getting to large to work with you could either use partial classes, Or back the logic off in to a separate class and leave your controller think and lean.

TWith2Sugars