c# - breezejs issues with the save bundle -


im working breezejs, , server-side code of app .net.

in views (client side), want add , entity want save it. lets assume entity :

{   "id": 1,   "name": "somename",   "createddate": "1900-01-01t05:00:00z",   "updateddate": "1900-01-01t05:00:00z",   "createdby": null,   "updatedby": null,   "rowversion": 0,    etc ...   } } 

i want set values of createddate updateddate createdby , updatedby, can using javascript of course, dont want client take care of kind of things.

my breeze controller lives function this:

[httppost] public saveresult savechanges(jobject savebundle) {     return _contextprovider.savechanges(savebundle);  } 

as u can see savebundle jobject, when debug see savebundle this:

{ "entities": [ {   "id": 1,   "name": "somename",   "createddate": "1900-01-01t05:00:00z",   "updateddate": "1900-01-01t05:00:00z",   "createdby": null,   "updatedby": null,   "rowversion": 0,    etc ...     }   } } ], "saveoptions": {} } 

how can change values of createddate updateddate createdby , updatedby in savebundle before save commited ???

this jobject array of objects proprety, can manipulate json javascript, how can .net ???

thanks lot.

thanks jay traband post found way make changes entity before saving it.

i overloaded beforesaveentity :

protected override bool beforesaveentity(entityinfo entityinfo) {         // return false if don´t want  save entity         var entitytype = entityinfo.entity.gettype();          if (entityinfo.entity.gettype() == typeof(myentitytypemodel))         {             if (entityinfo.entitystate == entitystate.added)             // can 'modified' or 'deleted'             {                 var mymodel = entityinfo.entity myentitytypemodel;                  mymodel.createddate = datetime.now;                 mymodel.updateddate = datetime.now;                 string username = membership.getuser().username;                 mymodel.createdby = username;                 mymodel.updatedby = username;             }         }         return true;    } 

thanks lot, , hope someday.


Comments

Popular posts from this blog

java.util.scanner - How to read and add only numbers to array from a text file -

rewrite - Trouble with Wordpress multiple custom querystrings -