public static List<Product> GetProducts() { List<Product> productList = new List<Product>(); SqlConnection connection = DBConnection.GetConnection(); string selectStatement = "SELECT ProductCode, Name FROM Products"; SqlCommand selectCommand = new SqlCommand(selectStatement, connection); SqlDataReader reader = null; try { connection.Open(); reader = selectCommand.ExecuteReader(); while (reader.Read()) { Product product = new Product(reader["ProductCode"].ToString()); product.Name = reader["Name"].ToString(); productList.Add(product); } } finally { if (connection != null) connection.Close(); if (reader != null) reader.Close(); } return productList; }
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); }