public void Insert(BankEntity t) { SqlConnection conn = null; SqlCommand cmd = null; try { conn = DALHelper.CreateSqlDbConnection(); cmd = new SqlCommand("usp_InsertBank", conn); cmd.CommandType = System.Data.CommandType.StoredProcedure; cmd.Parameters.AddWithValue("@Title", t.Title); cmd.Parameters.AddWithValue("@Description", t.Description); t.Id = Convert.ToInt32(cmd.ExecuteScalar()); } catch (Exception) { throw; } finally { conn.Close(); cmd.Dispose(); conn.Dispose(); } }
public void Delete(BankEntity t) { SqlConnection conn = null; SqlCommand cmd = null; try { conn = DALHelper.CreateSqlDbConnection(); cmd = new SqlCommand("usp_DeleteBank", conn); cmd.CommandType = System.Data.CommandType.StoredProcedure; cmd.Parameters.AddWithValue("@Id", t.Id); cmd.ExecuteNonQuery(); } catch (Exception) { throw; } finally { conn.Close(); cmd.Dispose(); conn.Dispose(); } }
protected void ProceedButton_Click(object sender, EventArgs e) { BankEntity entity = new BankEntity(); entity.Title = TitleTextBox.Text; entity.Description = OtherInfoTextBox.Text; new BankMapper().Insert(entity); Response.Redirect("List.aspx"); }
protected void ProceedButton_Click(object sender, EventArgs e) { BankEntity entity = new BankEntity(); entity.Id = Convert.ToInt32(Request.QueryString["BankId"]); entity.Title = TitleTextBox.Text; entity.Description = OtherInfoTextBox.Text; entity.Status = StatusEnum.Active; new BankMapper().Update(entity); Response.Redirect("List.aspx"); }
public BankEntity Get(BankEntity t) { SqlConnection conn = null; SqlCommand cmd = null; try { conn = DALHelper.CreateSqlDbConnection(); cmd = new SqlCommand("usp_GetBankById", conn); cmd.CommandType = System.Data.CommandType.StoredProcedure; cmd.Parameters.AddWithValue("@Id", t.Id); SqlDataReader rdr = cmd.ExecuteReader(); BankEntity entity = new BankEntity(); while (rdr.Read()) { entity.Id = Convert.ToInt32(rdr["Id"]); entity.Status = (StatusEnum)Convert.ToInt32(rdr["Status"]); entity.Title = Convert.ToString(rdr["Title"]); entity.Description = Convert.ToString(rdr["Description"]); } return entity; } catch (Exception) { throw; } finally { conn.Close(); cmd.Dispose(); conn.Dispose(); } }
public void Update(BankEntity t) { SqlConnection conn = null; SqlCommand cmd = null; try { conn = DALHelper.CreateSqlDbConnection(); cmd = new SqlCommand("usp_UpdateBank", conn); cmd.CommandType = System.Data.CommandType.StoredProcedure; cmd.Parameters.AddWithValue("@Id", t.Id); cmd.Parameters.AddWithValue("@Title", t.Title); cmd.Parameters.AddWithValue("@Description", t.Description); cmd.Parameters.AddWithValue("@Status", Convert.ToInt32(t.Status)); cmd.ExecuteNonQuery(); } catch (Exception) { throw; } finally { conn.Close(); cmd.Dispose(); conn.Dispose(); } }
public List<BankEntity> ListWithAdvancedFilter(string search, StatusEnum? status) { SqlConnection conn = null; SqlCommand cmd = null; try { conn = DALHelper.CreateSqlDbConnection(); cmd = new SqlCommand("usp_ListBanks", conn); cmd.CommandType = System.Data.CommandType.StoredProcedure; cmd.Parameters.AddWithValue("@Search", search); if (status != null) { cmd.Parameters.AddWithValue("@Status", status); } SqlDataReader rdr = cmd.ExecuteReader(); List<BankEntity> list = new List<BankEntity>(); while (rdr.Read()) { BankEntity entity = new BankEntity(); entity.Id = Convert.ToInt32(rdr["Id"]); entity.Status = (StatusEnum)Convert.ToInt32(rdr["Status"]); entity.Title = Convert.ToString(rdr["Title"]); entity.Description = Convert.ToString(rdr["Description"]); list.Add(entity); } return list; } catch (Exception) { throw; } finally { conn.Close(); cmd.Dispose(); conn.Dispose(); } }