// //private const string sp = ""; public int AddCustomer(Customer customer) { using (var conn = new SqlConnection(PrescienceRxConnectionString)) { conn.Open(); using (var cmd = new SqlCommand(AddCustomerSp, conn)) { cmd.CommandType = System.Data.CommandType.StoredProcedure; cmd.Parameters.Add("@CompanyId", SqlDbType.Int).Value = customer.CompanyId; cmd.Parameters.Add("@FirstName", SqlDbType.VarChar).Value = customer.FirstName; cmd.Parameters.Add("@LastName", SqlDbType.VarChar).Value = customer.LastName; if (!string.IsNullOrEmpty(customer.DateOfBirth)) { cmd.Parameters.Add("@DateOfBirth", SqlDbType.Date).Value = (customer.DateOfBirth == null ? "1/1/1900" : customer.DateOfBirth); } cmd.Parameters.Add("@MiddleInitial", SqlDbType.VarChar).Value = customer.MiddleInitial; cmd.Parameters.Add("@Email", SqlDbType.VarChar).Value = customer.Email; cmd.Parameters.Add("@Address1", SqlDbType.VarChar).Value = customer.Address1; cmd.Parameters.Add("@Address2", SqlDbType.VarChar).Value = customer.Address2; cmd.Parameters.Add("@City", SqlDbType.VarChar).Value = customer.City; cmd.Parameters.Add("@State", SqlDbType.VarChar).Value = customer.State; cmd.Parameters.Add("@Zip", SqlDbType.VarChar).Value = customer.Zip; cmd.Parameters.Add("@HomePhone", SqlDbType.VarChar).Value = customer.HomePhone; cmd.Parameters.Add("@CellPhone", SqlDbType.VarChar).Value = customer.CellPhone; cmd.Parameters.Add("@CreatedBy", SqlDbType.Int).Value = customer.CreatedBy; return Convert.ToInt32(cmd.ExecuteScalar()); } } }
// public Customer GetCustomer(int customerId) { Customer customer = null; using (var conn = new SqlConnection(PrescienceRxConnectionString)) { conn.Open(); using (var cmd = new SqlCommand(GetCustomerByIDSp, conn)) { cmd.CommandType = System.Data.CommandType.StoredProcedure; cmd.Parameters.Add("@CustomerId", SqlDbType.Int); cmd.Parameters["@CustomerId"].Value = customerId; using (var myReader = cmd.ExecuteReader()) { try { if (myReader.HasRows) { myReader.Read(); customer = new Customer(myReader); } } catch (Exception ex) { // TODO Logg Error here } } } } return customer; }
public CustomerInsurance() { customer = new Customer(); }