private void btnSave_Click(object sender, EventArgs e) { ProgamType _newProgType = new ProgamType(); if (IsEditMode == true) { _newProgType = _db.GetProgramTypeById(ProgramTypeId, databaseId); } _newProgType.ProgramTypesDescription = txtDescription.Text; _newProgType.Notes = txtNotes.Text; _newProgType.CustomerId = CustomerId; _newProgType.FosterCare = chkFosterCare.Checked; _newProgType.SubstanceAbuse = chkSubstanceAbuse.Checked; _newProgType.Residential = chkResidential.Checked; _newProgType.databaseID = databaseId; if (IsEditMode == true) { _db.SaveProgramTypes(_newProgType); _db.SaveChanges(); MessageBox.Show(this, "Program Types Saved", "Program Types has been updated ", MessageBoxButtons.OK, MessageBoxIcon.Information); this.Close(); } else { _db.AddToProgramType(_newProgType); _db.SaveChanges(); MessageBox.Show(this, "Program Types Saved", "Program Types has been Created ", MessageBoxButtons.OK, MessageBoxIcon.Information); this.Close(); } }
public void SaveProgramTypes(ProgamType _programType) { try { using (var ctx = new customerDbEntities()) { ctx.ProgamTypes.Add(_programType); ctx.Entry(_programType).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 ProgamType GetProgramTypeById(int Id, int databaseId) { using (var myContext = new customerDbEntities()) { ProgamType q = myContext.ProgamTypes.Where(w => w.id == Id && w.databaseID == databaseId).FirstOrDefault(); return(q); } }
private void frmProgramTypes_Load(object sender, EventArgs e) { ProgamType _newProgType = new ProgamType(); if (IsEditMode == true) { _newProgType = _db.GetProgramTypeById(ProgramTypeId, databaseId); txtDescription.Text = _newProgType.ProgramTypesDescription; txtNotes.Text = _newProgType.Notes; chkFosterCare.Checked = (bool)_newProgType.FosterCare; chkResidential.Checked = (bool)_newProgType.Residential; chkSubstanceAbuse.Checked = (bool)_newProgType.SubstanceAbuse; } }
private void radButton8_Click(object sender, EventArgs e) { ProgamType _deleteProgamType = new ProgamType(); _deleteProgamType = CustomerDb.GetProgramTypeById(ProgramTypeId, DatabaseId); DialogResult dialogResult = MessageBox.Show(this, "Are you sure you wish to Program Type ", "Delete Program Type", MessageBoxButtons.YesNo, MessageBoxIcon.Information); if (dialogResult == DialogResult.Yes) { CustomerDb.DeleteProgramType(_deleteProgamType); BindProgramTypes(CustomerId); } else if (dialogResult == DialogResult.No) { //do something else } BindProgramTypes(CustomerId); }
public void AddToProgramType(ProgamType newProgramType) { using (var myContext = new customerDbEntities()) { myContext.ProgamTypes.Add(newProgramType); 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); } } } } }