// public bool AddInsurance(Insurance insurance) { using (var conn = new SqlConnection(PrescienceRxConnectionString)) { conn.Open(); using (var cmd = new SqlCommand(AddInsuranceSp, conn)) { cmd.CommandType = System.Data.CommandType.StoredProcedure; cmd.Parameters.Add("@CompanyId", System.Data.SqlDbType.Int); cmd.Parameters["@CompanyId"].Value = insurance.CompanyId; cmd.Parameters.Add("@InsuranceName", System.Data.SqlDbType.VarChar); cmd.Parameters["@InsuranceName"].Value = insurance.InsuranceName; cmd.Parameters.Add("@InsuranceAddress", System.Data.SqlDbType.VarChar); cmd.Parameters["@InsuranceAddress"].Value = insurance.InsuranceAddress; cmd.Parameters.Add("@InsurancePhone", System.Data.SqlDbType.VarChar); cmd.Parameters["@InsurancePhone"].Value = insurance.InsurancePhone; cmd.Parameters.Add("@InsuranceWebsite", System.Data.SqlDbType.VarChar); cmd.Parameters["@InsuranceWebsite"].Value = insurance.InsuranceWebsite; //cmd.Parameters.Add("@CreatedBy", System.Data.SqlDbType.Int); //cmd.Parameters["@CreatedBy"].Value = insurance.CreatedBy; //cmd.Parameters.Add("@CreatedDate", System.Data.SqlDbType.Int); //cmd.Parameters["@CreatedDate"].Value = DateTime.UtcNow; return Convert.ToBoolean(cmd.ExecuteScalar()); } } }
public bool UpdateInsurance(Insurance insurance) { using (var conn = new SqlConnection(PrescienceRxConnectionString)) { conn.Open(); using (var cmd = new SqlCommand(UpdateInsuranceSp, conn)) { cmd.CommandType = System.Data.CommandType.StoredProcedure; cmd.Parameters.Add("@InsuranceId", System.Data.SqlDbType.Int); cmd.Parameters["@InsuranceId"].Value = insurance.InsuranceId; cmd.Parameters.Add("@CompanyId", System.Data.SqlDbType.Int); cmd.Parameters["@CompanyId"].Value = insurance.CompanyId; cmd.Parameters.Add("@InsuranceName", System.Data.SqlDbType.VarChar); cmd.Parameters["@InsuranceName"].Value = insurance.InsuranceName; cmd.Parameters.Add("@InsuranceAddress", System.Data.SqlDbType.VarChar); cmd.Parameters["@InsuranceAddress"].Value = insurance.InsuranceAddress; cmd.Parameters.Add("@InsurancePhone", System.Data.SqlDbType.VarChar); cmd.Parameters["@InsurancePhone"].Value = insurance.InsurancePhone; cmd.Parameters.Add("@InsuranceWebSite", System.Data.SqlDbType.VarChar); cmd.Parameters["@InsuranceWebSite"].Value = insurance.InsuranceWebsite; return cmd.ExecuteNonQuery() > 0; } } }
// public Insurance GetInsurance(int insuranceId) { Insurance insurance = null; using (var conn = new SqlConnection(PrescienceRxConnectionString)) { conn.Open(); using (var cmd = new SqlCommand(GetInsuranceByIdSp, conn)) { cmd.CommandType = System.Data.CommandType.StoredProcedure; cmd.Parameters.Add("@InsuranceId", System.Data.SqlDbType.Int); cmd.Parameters["@InsuranceId"].Value = insuranceId; using (var myReader = cmd.ExecuteReader()) { try { if (myReader.HasRows) { myReader.Read(); insurance = new Insurance(myReader); } } catch (Exception ex) { // TODO Logg Error here } } } } return insurance; }