public override void DeleteHandler() { using(var db = new DBContext(dbconn.GetConnection())) { db.Entry(Data).State = EntityState.Deleted; IsComplete = db.SaveChanges() == 1; } }
public override void EditHandler() { Data.ModelValidation(); IsComplete = !Data.HasErrors; if(IsComplete) { using(var db = new DBContext(dbconn.GetConnection())) { db.Persons.Attach(Data); PropertyInfo[] properties = typeof(Person).GetProperties(BindingFlags.DeclaredOnly | BindingFlags.Public | BindingFlags.Instance); foreach(PropertyInfo property in properties) { if(property.GetValue(Data) != property.GetValue(OriginalData)) db.Entry(Data).Property(property.Name).IsModified = true; } IsComplete = db.SaveChanges() == 1; } } }