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)); }
public IActionResult Update(int id, [FromBody] Dto.UpdateProduct productDto) { var product = ProductsRepo.GetById(id); Mapper.Map(productDto, product); ProductsRepo.Update(product); return(Ok()); }
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); }
public Dto.Product GetById(int id) { return(Mapper.Map <Dto.Product>(ProductsRepo.GetById(id))); }