private void btnSave_Click(object sender, EventArgs e)
 {
     if (ValidateName())
     {
         if (Mode == EntryMode.New)
         {
             ExpenseCategory expense = new ExpenseCategory()
             {
                 IsActive = true,
                 Name     = txtName.Text.Trim()
             };
             db.ExpenseCategories.Add(expense);
             db.SaveChanges();
             MessageBox.Show("Saved", "Success", MessageBoxButtons.OK);
             DialogResult = DialogResult.Yes;
         }
         else
         {
             var expense = db.ExpenseCategories.FirstOrDefault(x => x.Id == expenseId);
             if (expense != null)
             {
                 expense.Name = txtName.Text.Trim();
                 db.SaveChanges();
                 MessageBox.Show("Saved", "Success", MessageBoxButtons.OK);
                 DialogResult = DialogResult.Yes;
             }
             else
             {
                 MessageBox.Show("Error", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                 DialogResult = DialogResult.No;
             }
         }
     }
 }
 private void btnSave_Click(object sender, EventArgs e)
 {
     if (ValidateName())
     {
         if (Mode == EntryMode.New)
         {
             ServiceMaster service = new ServiceMaster()
             {
                 IsActive = true,
                 Name     = txtName.Text.Trim()
             };
             db.ServiceMasters.Add(service);
             db.SaveChanges();
             MessageBox.Show("Saved", "Success", MessageBoxButtons.OK);
             DialogResult = DialogResult.Yes;
         }
         else
         {
             var service = db.ServiceMasters.FirstOrDefault(x => x.Id == ServiceId);
             if (service != null)
             {
                 service.Name = txtName.Text.Trim();
                 db.SaveChanges();
                 MessageBox.Show("Saved", "Success", MessageBoxButtons.OK);
                 DialogResult = DialogResult.Yes;
             }
             else
             {
                 MessageBox.Show("Error", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                 DialogResult = DialogResult.No;
             }
         }
     }
 }