Ejemplo n.º 1
0
        public IActionResult GetById(int ProductId)
        {
            var singleProduct = _repo.GetById(ProductId);

            if (singleProduct == null)
            {
                return(NotFound("No Product with that ID was found"));
            }
            return(Ok(singleProduct));
        }
Ejemplo n.º 2
0
        public IActionResult Update(int id, [FromBody] Dto.UpdateProduct productDto)
        {
            var product = ProductsRepo.GetById(id);

            Mapper.Map(productDto, product);
            ProductsRepo.Update(product);
            return(Ok());
        }
Ejemplo n.º 3
0
        public IActionResult Create(int id, [FromBody] Dto.UpdateProduct newProductDto)
        {
            var newProduct = new Model.Product(id);

            Mapper.Map(newProductDto, newProduct);
            ProductsRepo.Create(newProduct);

            var createdProduct = ProductsRepo.GetById(id);

            Logger.LogInformation("New product was created: {@product}", createdProduct);

            return(Created($"{id}", Mapper.Map <Dto.Product>(createdProduct)));
        }
        public void AddProductToCatalog()
        {
            var id = (int)controller.AddProduct(_testProduct).Data;

            Assert.AreEqual(_testProduct.Name, _pRepo.GetById(id).Name);
        }
Ejemplo n.º 5
0
 public Dto.Product GetById(int id)
 {
     return(Mapper.Map <Dto.Product>(ProductsRepo.GetById(id)));
 }