예제 #1
0
        /// <summary>
        /// Request customer data.
        /// </summary>
        /// <param name="request">Customer request message.</param>
        /// <returns>Customer response message.</returns>
        public CustomerResponse GetCustomers(CustomerRequest request)
        {
            CustomerResponse response = new CustomerResponse();

            response.CorrelationId = request.RequestId;

            // Validate client tag, access token, and user credentials
            if (!ValidRequest(request, response, Validate.All))
            {
                return(response);
            }

            CustomerCriteria criteria = request.Criteria as CustomerCriteria;
            string           sort     = criteria.SortExpression;

            if (request.LoadOptions.Contains("Customers"))
            {
                IEnumerable <Customer> customers;
                if (!criteria.IncludeOrderStatistics)
                {
                    // Simple customer list without order information
                    customers = customerDao.GetCustomers(criteria.SortExpression);
                }
                else if (sort.IndexOf("NumOrders") >= 0 || sort.IndexOf("LastOrderDate") >= 0)
                {
                    // Sort order is handled by the Order Dao
                    IList <Customer> list = customerDao.GetCustomers();
                    customers = orderDao.GetOrderStatistics(list, sort);
                }
                else
                {
                    // Sort order is handled by the Customer Dao, but alse need order statistics
                    IList <Customer> list = customerDao.GetCustomers(sort);
                    customers = orderDao.GetOrderStatistics(list);
                }
                response.Customers = customers.Select(c => Mapper.ToDataTransferObject(c)).ToList();
            }

            if (request.LoadOptions.Contains("Customer"))
            {
                Customer customer = customerDao.GetCustomer(criteria.CustomerId);
                if (request.LoadOptions.Contains("Orders"))
                {
                    customer.Orders = orderDao.GetOrders(customer.CustomerId);
                }

                response.Customer = Mapper.ToDataTransferObject(customer);
            }

            return(response);
        }
예제 #2
0
        /// <summary>
        /// Request customer data.
        /// </summary>
        /// <param name="request">Customer request message.</param>
        /// <returns>Customer response message.</returns>
        public CustomerResponse GetCustomers(CustomerRequest request)
        {
            var response = new CustomerResponse(request.RequestId);

            // Validate client tag, access token, and user credentials
            if (!ValidRequest(request, response, Validate.All))
            {
                return(response);
            }

            var    criteria = request.Criteria as CustomerCriteria;
            string sort     = criteria.SortExpression;

            if (request.LoadOptions.Contains("Customers"))
            {
                IEnumerable <Customer> customers;
                if (!criteria.IncludeOrderStatistics)
                {
                    customers = _customerDao.GetCustomers(sort);
                }
                else
                {
                    customers = _customerDao.GetCustomersWithOrderStatistics(sort);
                }

                response.Customers = customers.Select(c => Mapper.ToDataTransferObject(c)).ToList();
            }

            if (request.LoadOptions.Contains("Customer"))
            {
                var customer = _customerDao.GetCustomer(criteria.CustomerId);
                if (request.LoadOptions.Contains("Orders"))
                {
                    customer.Orders = _orderDao.GetOrdersByCustomer(customer.CustomerId);
                }

                response.Customer = Mapper.ToDataTransferObject(customer);
            }

            return(response);
        }