private void btnSave_Click(object sender, EventArgs e) { StandardLookup _lookup = new StandardLookup(); if (IsEdit == true) { _lookup = _db.GetLookupById(this.LookupId); } _lookup.code = txtCode.Text; _lookup.description = txtDescription.Text; _lookup.lookupgroup = LookupGroup; _lookup.isActive = true; if (IsEdit == true) { _db.SaveLookup(_lookup); _db.SaveChanges(); MessageBox.Show("Lookup Saved", "Lookup has been updated ", MessageBoxButtons.OK, MessageBoxIcon.Information); } else { _db.AddToLookups(_lookup); _db.SaveChanges(); MessageBox.Show("Lookup Saved", "Lookup has been Created ", MessageBoxButtons.OK, MessageBoxIcon.Information); } this.Close(); }
public void SaveLookup(StandardLookup _lookup) { try { using (var ctx = new customerDbEntities()) { ctx.StandardLookups.Add(_lookup); ctx.Entry(_lookup).State = System.Data.Entity.EntityState.Modified; ctx.SaveChanges(); } } catch (DbEntityValidationException e) { foreach (var eve in e.EntityValidationErrors) { Console.WriteLine("Entity of type \"{0}\" in state \"{1}\" has the following validation errors:", eve.Entry.Entity.GetType().Name, eve.Entry.State); foreach (var ve in eve.ValidationErrors) { Console.WriteLine("- Property: \"{0}\", Error: \"{1}\"", ve.PropertyName, ve.ErrorMessage); } } throw; } }
public string GetStandardLookupDescription(int Id) { using (var myContext = new customerDbEntities()) { StandardLookup q = myContext.StandardLookups.Where(w => w.id == Id).Single(); return(q.description); } }
private void frmStandardLookupEditorEdit_Load(object sender, EventArgs e) { if (IsEdit == true) { StandardLookup _lookup = new StandardLookup(); _lookup = _db.GetLookupById(this.LookupId); txtCode.Text = _lookup.code; txtDescription.Text = _lookup.description; } }
public StandardLookup GetLookupById(int id) { StandardLookup q = new StandardLookup(); using (var myContext = new customerDbEntities()) { q = myContext.StandardLookups.Where(w => w.id == id).FirstOrDefault(); } return(q); }
public void AddToLookups(StandardLookup lookup) { using (var myContext = new customerDbEntities()) { myContext.StandardLookups.Add(lookup); try { myContext.SaveChanges(); } catch (DbEntityValidationException ex) { foreach (var entityValidationErrors in ex.EntityValidationErrors) { foreach (var validationError in entityValidationErrors.ValidationErrors) { Console.Write("Property: " + validationError.PropertyName + " Error: " + validationError.ErrorMessage); } } } } }