public void saveChanges() { using (var db = new PlanningContext()) { contact_history data = null; if (!this._isCreateMode) { var id = Convert.ToInt32(this.contact_history_id.Text); data = db.contact_history.Where(d => d.contact_history_id == id).FirstOrDefault(); if (data == null) { this._mainInterface.statusText = $"ERROR: ID '{this.contact_history_id.Text}' does not exist."; return; } } else { data = new contact_history(); } data.contact_history_id = Convert.ToInt32(this.contact_history_id.Text); data.date_and_time = (DateTime)this.date_and_time.SelectedDate; data.is_active = (bool)this.is_active.IsChecked; data.comment = /**/ (this.comment.Text); data.contact = new Func <contact>(() => { foreach (var v in db.contacts) { if (v.contact_id == (this.contact.item as contact).contact_id) { return(v); } } return(null); })(); data.history_event = new Func <history_event>(() => { foreach (var v in db.history_event) { if (v.history_event_id == (this.history_event.item as history_event).history_event_id) { return(v); } } return(null); })(); if (this._isCreateMode) { db.contact_history.Add(data); } db.SaveChanges(); } }
public void deleteItem(object item) { if (item == null) { return; } contact_history data = item as contact_history; if (data == null) { return; } using (var db = new PlanningContext()) { db.contact_history.Remove(db.contact_history.Where(d => d.contact_history_id == data.contact_history_id).First()); db.SaveChanges(); } }