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