6

I have a design question. I am implementing a purchase flow in my Web that has 4 steps:

A -> B -> C <-> D -> E
  • A: Build a PurchaseModel object and POST it to B.
  • B: Shows a purchase summary.
  • C, D: Login/register. This step is optional if the user is already logged in. The user can go from C to D and vice-versa.
  • E: Post to paypal

I need the PurchaseModel travelling from A to E, so my question is:

How can I pass the PurchaseModel between controllers/views? What is the recommended solution in this case?

NOTE: A, B, C and D are controllers that have the attribute [AllowAnonymous].

UPDATE

Would be correct to store the PurchaseModel in a session variable in STEP B, and then use it in the other controllers?

halfer
  • 19,824
  • 17
  • 99
  • 186
Daniel Peñalba
  • 30,507
  • 32
  • 137
  • 219
  • You might benefit from this link, http://stackoverflow.com/questions/8923578/create-wizard-steps-in-mvc-and-razor – Ronald Jan 16 '14 at 10:12
  • Store it in Session. Session holds on the server-side so it's secure way. – Maris Jan 16 '14 at 10:33
  • Are sessions user-independanty, and work fine if the user is not logged in? – Daniel Peñalba Jan 16 '14 at 10:44
  • @DanielPeñalba Yes sessions are user-independanty, but there is one problem with them, that the lifetime of session is not same as the lifetime of loged user, so be careful with that http://completedevelopment.blogspot.sk/2009/12/caution-with-using-sessiontimeout-and.html – Marian Ban Jan 16 '14 at 15:57

1 Answers1

2

I think an action should only take parameters that are relevant to it. In the case of registration or login I see these as separate concerns, so it would be wrong to pass a PurchaseModel to them. If you were passing data between different steps that is relevant to all steps I would do it via passing a common view model, or models that inherit from one another, but as this is not how it is in your case I would store in session. This will not be affected by logging in.

Rob West
  • 5,189
  • 1
  • 27
  • 42
  • 1
    Sorry about that. It is good design to separate concerns. I would expect your login and registration to be used outside of the purchase flow, so it does not make sense for them to take values for purchases. Therefore, better design to store a purchase details in session. – Rob West Jan 16 '14 at 14:38