public static List<Customer> GetCustomers() { List<Customer> customerList = new List<Customer>(); SqlConnection connection = DBConnection.GetConnection(); string selectStatement = "SELECT CustomerID, Name FROM Customers"; SqlCommand selectCommand = new SqlCommand(selectStatement, connection); SqlDataReader reader = null; try { connection.Open(); reader = selectCommand.ExecuteReader(); while (reader.Read()) { Customer customer = new Customer((int)reader["CustomerID"]); customer.Name = reader["Name"].ToString(); customerList.Add(customer); } } finally { if (connection != null) connection.Close(); if (reader != null) reader.Close(); } return customerList; }
public static int AddIncident(Customer customer, Product product, string title, string description) { if (customer == null || product == null) { throw new ArgumentException("customer and product parameters must not be null"); } Incident incident = new Incident(); incident.CustomerID = customer.CustomerID; incident.ProductCode = product.ProductCode; incident.Title = title; incident.Description = description; incident.DateOpened = DateTime.Now; return IncidentData.AddIncident(incident); }