Exemplo n.º 1
0
        public void saveChanges()
        {
            using (var db = new PlanningContext())
            {
                device_address data = null;

                if (!this._isCreateMode)
                {
                    var id = Convert.ToInt32(this.device_address_id.Text);
                    data = db.device_address.Where(d => d.device_address_id == id).FirstOrDefault();
                    if (data == null)
                    {
                        this._mainInterface.statusText = $"ERROR: ID '{this.device_address_id.Text}' does not exist.";
                        return;
                    }
                }
                else
                {
                    data = new device_address();
                }

                data.device_address_id = Convert.ToInt32(this.device_address_id.Text);
                data.pin_number        = Convert.ToInt32(this.pin_number.Text);
                data.ip_address        = /**/ (this.ip_address.Text);
                data.comment           = /**/ (this.comment.Text);
                data.is_active         = (bool)this.is_active.IsChecked;
                data.device            = new Func <device>(() => { foreach (var v in db.devices)
                                                                   {
                                                                       if (v.device_id == (this.device.item as device).device_id)
                                                                       {
                                                                           return(v);
                                                                       }
                                                                   }
                                                                   return(null); })();
                data.device_address_type = new Func <device_address_type>(() => { foreach (var v in db.device_address_type)
                                                                                  {
                                                                                      if (v.device_address_type_id == (this.device_address_type.item as device_address_type).device_address_type_id)
                                                                                      {
                                                                                          return(v);
                                                                                      }
                                                                                  }
                                                                                  return(null); })();


                if (this._isCreateMode)
                {
                    db.device_address.Add(data);
                }
                db.SaveChanges();
            }
        }
Exemplo n.º 2
0
        public void deleteItem(object item)
        {
            if (item == null)
            {
                return;
            }

            device_address data = item as device_address;

            if (data == null)
            {
                return;
            }

            using (var db = new PlanningContext())
            {
                db.device_address.Remove(db.device_address.Where(d => d.device_address_id == data.device_address_id).First());
                db.SaveChanges();
            }
        }