예제 #1
0
 // Not implemented. No products are modified.
 public ProductResponse SetProducts(ProductRequest request)
 {
     return new ProductResponse();
 }
예제 #2
0
        /// <summary>
        /// Requests product data.
        /// </summary>
        /// <param name="request">Product request message.</param>
        /// <returns>Product response message.</returns>
        public ProductResponse GetProducts(ProductRequest request)
        {
            ProductResponse response = new ProductResponse();
            response.CorrelationId = request.RequestId;

            // Validate client tag and access token
            if (!ValidRequest(request, response, Validate.ClientTag | Validate.AccessToken))
                return response;

            ProductCriteria criteria = request.Criteria as ProductCriteria;

            if (request.LoadOptions.Contains("Categories"))
            {
                IEnumerable<Category> categories = productDao.GetCategories();
                response.Categories = Mapper.ToDataTransferObjects(categories);
            }

            if (request.LoadOptions.Contains("Products"))
            {
                IEnumerable<Product> products = productDao.GetProductsByCategory(criteria.CategoryId, criteria.SortExpression);
                response.Products = Mapper.ToDataTransferObjects(products);
            }

            if (request.LoadOptions.Contains("Product"))
            {
                Product product = productDao.GetProduct(criteria.ProductId);
                product.Category = productDao.GetCategoryByProduct(criteria.ProductId);

                response.Product = Mapper.ToDataTransferObject(product);
            }

            if (request.LoadOptions.Contains("Search"))
            {
                IList<Product> products = productDao.SearchProducts(criteria.ProductName,
                    criteria.PriceFrom, criteria.PriceThru, criteria.SortExpression);

                response.Products = Mapper.ToDataTransferObjects(products);
            }
            return response;
        }