Let’s say I want to use Breeze to create a Task entity (I’m using EF), but because this is a real task application, the task must be associated to the currently logged in user. Tasks have UserId foreign keys that need to be populated during save and that’s where I’m stuck. Doing this in a mostly client-side application is a foreign concept to me. I can’t very well specify the UserId foreign key on the client side because I don’t want a clever user might create tasks for another user. Where do I go about hooking into the save process to populate the UserId FK with the currently logged in user (System.Web.HttpContext.Current.User.Identity.Name in this case).
Feel free to point me in the direction of another post or documentation. As I said, this is a new concept to me so I don’t really know what to search for.
And to whoever answer this question, I love you with all my heart. 🙂
Take a look at the documentation on the Breeze website about the Custom EFContextProvider’s Save Interceptor. You will need to create your own provider and implement the BeforeSaveEntity method. In that method you can set the UserId of the task to the current user just like you did with MVC4.