Пример #1
0
        public IActionResult GetStock(int id, [FromQuery] string fields)
        {
            // check requested fields are valid
            if (!_typeHelperService.TypeHasProperties <SupermarketStockDTO>(fields))
            {
                return(BadRequest());
            }

            // get stock by id
            var stockFromRepo = _supermarketRepository.GetStockById(id);

            // check stock exists
            if (stockFromRepo == null)
            {
                return(NotFound());
            }

            // map and return stock
            var stock = Mapper.Map <SupermarketStockDTO>(stockFromRepo);

            var links = CreateLinksForSupermarketStock(id, fields);

            var linkedResourceToReturn = stock.ShapeData(fields)
                                         as IDictionary <string, object>;

            linkedResourceToReturn.Add("links", links);

            return(Ok(linkedResourceToReturn));
        }