Exemple #1
0
        public void UpdateShop(ShopDTO shopDto)
        {
            Shop shop = MappingUtil.MapInstance <ShopDTO, Shop>(shopDto);

            validator.Validate(shop);

            dataset.Shops.Update(shop);
        }
        public void UpdateProduct(ProductDTO productDto)
        {
            Product product = MappingUtil.MapInstance <ProductDTO, Product>(productDto);

            validator.Validate(product);

            dataset.Products.Update(product);
        }
        // PUT api/<controller>/5
        public IHttpActionResult Put(int id, [FromBody] Product product)
        {
            ProductDTO productDto = MappingUtil.MapInstance <Product, ProductDTO>(product);

            try
            {
                productService.UpdateProduct(productDto);
            }
            catch (EntityValidationExeption ex)
            {
                return(BadRequest(ex.Message));
            }

            return(Ok());
        }
        // PUT api/<controller>/5
        public IHttpActionResult Put(int id, [FromBody] Shop shop)
        {
            ShopDTO shopDto = MappingUtil.MapInstance <Shop, ShopDTO>(shop);

            try
            {
                shopService.UpdateShop(shopDto);
            }
            catch (EntityValidationExeption ex)
            {
                return(BadRequest(ex.Message));
            }

            return(Ok());
        }
        // GET api/<controller>/5
        public IHttpActionResult Get(int id)
        {
            ShopDTO shopDto = shopService.GetShop(id);

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

            IEnumerable <ProductDTO> shopProductDtos = productService.GetShopProducts(id);
            ShopProducts             shopProducts    = new ShopProducts()
            {
                Shop     = MappingUtil.MapInstance <ShopDTO, Shop>(shopDto),
                Products = MappingUtil.MapCollection <ProductDTO, Product>(shopProductDtos)
            };

            return(Ok(shopProducts));
        }
Exemple #6
0
        public ShopDTO GetShop(int id)
        {
            var shop = dataset.Shops.Get(id);

            return(MappingUtil.MapInstance <Shop, ShopDTO>(shop));
        }