protected void btnSubmit_Click(object sender, EventArgs e) { try { if (hid.Value == "Update") { VehicleIncidenceType typ = null; bool rst = false; typ = LookUpBLL.GetIncidenceType(Convert.ToInt32(txtID.Text)); if (typ != null) { typ.Name = txtDept.Text.ToUpper();; rst = LookUpBLL.UpdateIncidenceType(typ); if (rst != false) { BindGrid(); success.Visible = true; success.InnerHtml = " <button type='button' class='close' data-dismiss='alert'>×</button> Record updated successfully!!."; return; } } else { error.Visible = true; error.InnerHtml = " <button type='button' class='close' data-dismiss='alert'>×</button>Record could Not updated. Kindly try again. If error persist contact Administrator!!."; } } else { string typ = ""; typ = txtDept.Text; bool result = false; VehicleIncidenceType type = new VehicleIncidenceType(); type.Name = typ.ToUpper(); result = LookUpBLL.AddIncidenceType(type); if (result) { BindGrid(); txtDept.Text = ""; success.Visible = true; success.InnerHtml = " <button type='button' class='close' data-dismiss='alert'>×</button> Record added successfully!!."; return; } else { error.Visible = true; error.InnerHtml = " <button type='button' class='close' data-dismiss='alert'>×</button>Record could Not added. Kindly try again. If error persist contact Administrator!!."; } } } catch (Exception ex) { error.Visible = true; error.InnerHtml = "<button type='button' class='close' data-dismiss='alert'>×</button> An error occurred. kindly try again!!!"; Utility.WriteError("Error: " + ex.Message); } }
public static bool AddIncidenceType(VehicleIncidenceType type) { try { using (FleetMgtSysDBEntities db = new FleetMgtSysDBEntities()) { db.VehicleIncidenceTypes.Add(type); db.SaveChanges(); return(true); } } catch (Exception ex) { // Utility.WriteError("Error Msg: " + ex.Message); throw ex; } }
public static bool UpdateIncidenceType(VehicleIncidenceType type) { try { bool rst = false; using (var db = new FleetMgtSysDBEntities()) { db.VehicleIncidenceTypes.Attach(type); db.Entry(type).State = System.Data.Entity.EntityState.Modified; db.SaveChanges(); rst = true; } return(rst); } catch (Exception ex) { Utility.WriteError("Error Msg: " + ex.InnerException); throw ex; } }