views:

15

answers:

1

Our users need to be able to export data in CSV format, edit some of the records, and upload the data again. The data does not map to entities, you could say that the object graph is flattened to fit in the Excel-based workflow.

Right now this happens in the controllers because I thought these DTO classes were view models. It smells but I don't have a clear idea how to fix that. Is there a pattern I could/should follow?

Thanks!

+1  A: 

Start by abstract this logic into an interface containing the necessary method. Implement this interface against the CSV format. Pass the interface in the constructor of the controller. Use DI to inject the proper implementation. In the controller action call the method on the interface.

If you want to return CSV directly from your controller action you could write a custom ActionResult like CsvActionResult which will take the model and serialize it into CSV so that in your controller action you return new CsvResult(someModel).

Darin Dimitrov
+1 for the custom ActionResult. I will start with that. Thanks!
michielvoo