示例#1
0
 public override void DeleteHandler()
 {
     using(var db = new DBContext(dbconn.GetConnection()))
     {
         db.Entry(Data).State = EntityState.Deleted;
         IsComplete = db.SaveChanges() == 1;
     }
 }
示例#2
0
        public override void AddHandler()
        {
            Data.ModelValidation();
            IsComplete = !Data.HasErrors;

            if(IsComplete)
            {
                using(var db = new DBContext(dbconn.GetConnection()))
                {
                    db.Persons.Add(Data);
                    IsComplete = db.SaveChanges() == 1;
                }
            }
        }
示例#3
0
        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;
                }
            }
        }