public async Task <IHttpActionResult> Get(ODataQueryOptions <Product> queryOptions)
        {
            logger.Trace("Call ProductsController GetProducts");

            try
            {
                queryOptions.Validate(_validationSettings);
            }
            catch (ODataException ex)
            {
                return(BadRequest(ex.Message));
            }

            var allProducts = productRepository.Get();

            var task = allProducts.Select(async r =>
            {
                var links = await linkRepository.GetByReferenceIdAsync(r.Id);

                var specifications = await productSpecificationRepository.GetByParentIdAsync(r.Id);

                var specifications_task = specifications.Select(async s =>
                {
                    s.Child    = productRepository.GetById(s.ChildId);
                    s.ChildUom = await uomRepository.GetByIdAsync(s.ChildUomId);
                    return(s);
                });

                var specifications_list = await Task.WhenAll(specifications_task);

                r.Price       = productPriceService.GetByProductId(r.Id);
                r.Categories  = productCategoryService.GetCategoriesByProductId(r.Id).ToList();
                r.Links       = links.ToList();
                r.Ingredients = specifications_list;

                return(r);
            });

            var data = await Task.WhenAll(task);

            //var query = queryOptions
            //    .ApplyTo(data.AsQueryable());

            //data = query.ToList();

            return(Ok(data));
        }
Esempio n. 2
0
        public async Task <IHttpActionResult> Get([FromODataUri] System.Guid key)
        {
            logger.Trace("Call UomController Get by Id");

            var query = await uomRepository.GetByIdAsync(key);

            return(Ok(query));
        }
Esempio n. 3
0
        public async Task <IHttpActionResult> GetUom([FromODataUri] System.Guid key)
        {
            logger.Trace("Call OrderLineController GetUom");

            var orderLine = await orderLineRepository.GetByIdAsync(key);

            if (orderLine == null)
            {
                return(NotFound());
            }

            var uom = await uomRepository.GetByIdAsync(orderLine.UomId);

            return(Ok(uom));
        }