public void saveChanges() { using (var db = new PlanningContext()) { device_history_action data = null; if (!this._isCreateMode) { var id = Convert.ToInt32(this.device_history_action1.Text); data = db.device_history_action.Where(d => d.device_history_action1 == id).FirstOrDefault(); if (data == null) { this._mainInterface.statusText = $"ERROR: ID '{this.device_history_action1.Text}' does not exist."; return; } } else { data = new device_history_action(); } data.device_history_action1 = Convert.ToInt32(this.device_history_action1.Text); data.description = /**/ (this.description.Text); data.is_active = (bool)this.is_active.IsChecked; data.comment = /**/ (this.comment.Text); 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); })(); if (this._isCreateMode) { db.device_history_action.Add(data); } db.SaveChanges(); } }
public void deleteItem(object item) { if (item == null) { return; } device_history_action data = item as device_history_action; if (data == null) { return; } using (var db = new PlanningContext()) { db.device_history_action.Remove(db.device_history_action.Where(d => d.device_history_action1 == data.device_history_action1).First()); db.SaveChanges(); } }