Ejemplo n.º 1
0
        /// <summary>
        /// Client List with Orders
        /// </summary>
        /// <returns>A List of all client objects and their accosiated orders</returns>
        public static List <Customer> AllClients()
        {
            OrderRepository orderRepository = new OrderRepository();

            SqlConnection connection = new SqlConnection(ConnectionString);

            connection.Open();

            SqlCommand      command   = new SqlCommand("SELECT * FROM Customer", connection);
            var             reader    = command.ExecuteReader();
            List <Customer> customers = new List <Customer>();

            while (reader.Read())
            {
                Customer customer = new Customer()
                {
                    Name        = reader["Name"].ToString(),
                    DateOfBirth = DateTime.Parse(reader["DateOfBirth"].ToString()),
                    Country     = reader["Country"].ToString(),
                    CustomerId  = Convert.ToInt32(reader["CustomerId"]),
                    Orders      = orderRepository.GetOrders(Convert.ToInt32(reader["CustomerId"]))
                };
                customers.Add(customer);
            }
            return(customers);
        }
Ejemplo n.º 2
0
 public List <Order> GetOrders()
 {
     using (OrderRepository orderRepository = new OrderRepository())
     {
         return(orderRepository.GetOrders());
     }
 }