Friday, 15 May 2015

asp.net mvc 3 - Current user identity in ObjectContext.SavingChanges -



asp.net mvc 3 - Current user identity in ObjectContext.SavingChanges -

i using objectcontext.savingchanges event update createddate/updateddate columns based on object state this

partial void oncontextcreated() { //extension of command timeout avoid processing problems. commandtimeout = 600; //time in seconds this.savingchanges += new eventhandler(entities_savingchanges); } protected void entities_savingchanges(object sender, eventargs e) { var addedobjects = this.objectstatemanager.getobjectstateentries(system.data.entitystate.added); foreach (var addedobject in addedobjects) { var propertyinfo = addedobject.entity.gettype().getproperty("createddate"); if (propertyinfo != null) { propertyinfo.setvalue(addedobject.entity, datetime.utcnow, null); } } var modifiedobjects = this.objectstatemanager.getobjectstateentries(system.data.entitystate.modified); foreach (var modifiedobject in modifiedobjects) { var propertyinfo = modifiedobject.entity.gettype().getproperty("updateddate"); if (propertyinfo != null) { propertyinfo.setvalue(modifiedobject.entity, datetime.utcnow, null); } } }

i have 2 more columns createduser , updateduser.

is there way update using current user name context?

ofcource, system.httpcontext.current null here separate class library project, access through wcf service.

if code resides in wcf service consume asp.net mvc application send current username parameter method invoking.

asp.net-mvc-3 entity-framework httpcontext

No comments:

Post a Comment