// public bool AddCustomerInsurance(CustomerInsurance customerInsurance) { using (var conn = new SqlConnection(PrescienceRxConnectionString)) { conn.Open(); using (var cmd = new SqlCommand(AddCustomerInsuranceSp, conn)) { cmd.CommandType = System.Data.CommandType.StoredProcedure; cmd.Parameters.Add("@CustomerId", SqlDbType.Int).Value = customerInsurance.CustomerId; cmd.Parameters.Add("@InsuranceId", SqlDbType.Int).Value = customerInsurance.InsuranceId; cmd.Parameters.Add("@EffectiveDate", SqlDbType.DateTime).Value = customerInsurance.EffectiveDate; cmd.Parameters.Add("@EndDate", SqlDbType.DateTime).Value = (customerInsurance.EndDate==null?DateTime.MinValue:customerInsurance.EndDate); cmd.Parameters.Add("@PcpName", SqlDbType.VarChar).Value = customerInsurance.PcpName; cmd.Parameters.Add("@CustomerInsuranceNumber", SqlDbType.VarChar).Value = customerInsurance.CustomerInsuranceNumber; cmd.Parameters.Add("@InsuranceType", SqlDbType.VarChar).Value = customerInsurance.InsuranceType; cmd.Parameters.Add("@IsActive", SqlDbType.Bit).Value = customerInsurance.IsActive; return Convert.ToBoolean(cmd.ExecuteScalar()); } } }
public List<CustomerInsurance> GetCustomerInsurance(int companyId, int customerInsuranceId) { var lst = new List<CustomerInsurance>(); CustomerInsurance customerInsurance = null; using (var conn = new SqlConnection(PrescienceRxConnectionString)) { conn.Open(); using (var cmd = new SqlCommand(GetCustomerInsuranceByIDSp, conn)) { cmd.CommandType = System.Data.CommandType.StoredProcedure; cmd.Parameters.Add("@CustomerInsuranceID", SqlDbType.Int); cmd.Parameters["@CustomerInsuranceID"].Value = customerInsuranceId; using (var myReader = cmd.ExecuteReader()) { try { if (myReader.HasRows) { while (myReader.Read()) { customerInsurance = new CustomerInsurance(myReader); lst.Add(customerInsurance); } } } catch (Exception ex) { // TODO Logg Error here } } } } return lst; }