c# - How to check a change in a Model Object fields without checking individual fields in MVC? -
i have big model
public class somemodel { public int id { get; set; } .....a lot(24) of fields here..... }
now on post actionresult edit(somemodel somemodel)
want check if has been changed user respect original model values in database. using if else
makes lot of messy code. there anyway check if altered user , if possible field altered user?
i thinking using method one
public class somemodel { //... public override bool equals(object obj) { var type = this.gettype(); bool sameobj = true; //for each public property 'somemodel' //[edited]type.getproperties().each(prop=>{ // sorry i'm using custom extension methode here //you should use instead type.getproperties().tolist().foreach(prop=>{ //dynamically checks they're equals if(!prop.getvalue(this,null).equals(prop.getvalue(obj,null))){ sameobj=false; } } return sameobj; } }
/!\ edited
Comments
Post a Comment