Esempio n. 1
0
 public override void DeleteHandler()
 {
     using(var db = new DBContext(dbconn.GetConnection()))
     {
         db.Entry(Data).State = EntityState.Deleted;
         IsComplete = db.SaveChanges() == 1;
     }
 }
        /// <summary>
        /// Load Person List
        /// </summary>
        public void Load()
        {
            using(var db = new DBContext(dbconn.GetConnection()))
            {
                var query = from t in db.Persons
                            orderby t.Name
                            select t;

                _contacts = new ObservableCollection<Person>(query);
                OnPropertyChanged("Persons");
            }
        }
Esempio n. 3
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;
                }
            }
        }
Esempio n. 4
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;
                }
            }
        }