예제 #1
0
        public static Customer Load(int customerId)
        {
            Customer        customer   = new Customer();
            OrderRepository ordersRepo = InvestecFactory.GetOrderRepository();

            SqlConnection connection = default;

            try
            {
                connection = new SqlConnection(ConnectionString);
                connection.Open();

                SqlCommand command = new SqlCommand(Constants.LoadCustomersQuery + customerId,
                                                    connection);
                var reader = command.ExecuteReader();

                while (reader.Read())
                {
                    customer.Name        = reader["Name"].ToString();
                    customer.DateOfBirth = DateTime.Parse(reader["DateOfBirth"].ToString());
                    customer.Country     = reader["Country"].ToString();
                    customer.Orders      = ordersRepo.LoadOrdersForCustomer(customerId);
                }
            }
            catch (Exception ex)
            {
                throw new Exception($"Error loading customerId '{customerId}'. Error Message: {ex.Message}", ex);
            }
            finally
            {
                connection?.Close();
            }


            return(customer);
        }
예제 #2
0
 public CustomerService()
 {
     orderRepository = new OrderRepository();
 }
예제 #3
0
        public IOrderService Create()
        {
            var orderRepository = new OrderRepository(_connectionStringBuilderProvider);

            return(new OrderService(orderRepository, _customerRepository, _orderValidator, _vatApplicator));
        }
예제 #4
0
 private static void LoadCustomerOrders(Customer customer)
 {
     customer.Orders = OrderRepository.GetCustomerOrders(customer.CustomerId);
 }
예제 #5
0
 public OrderRepositoryWrapper()
 {
     orderRepository = new OrderRepository();
 }
예제 #6
0
        public OrderService(IDatabase customerDb, IDatabase orderDb)
        {
            _customerDb = customerDb;

            _orderRepository = new OrderRepository(orderDb);
        }
예제 #7
0
 public OrderService(OrderRepository orderRepository)
 {
     this.orderRepository = orderRepository;
 }