public IActionResult CreateProduct(int productId, [FromBody] ProductForCreationDto saleItem) { //productID is actually the product model id, and saleItem is the product if (saleItem == null) { return(BadRequest()); } //productID is actually the product model id, and salesitem is the product id if (!_productInfoRepository.ProductModelExists(productId)) { return(NotFound()); } var finalProduct = Mapper.Map <Entities.Product>(saleItem); _productInfoRepository.AddProductForModel(productId, finalProduct); if (!_productInfoRepository.Save()) { return(StatusCode(500, "A problem occured while handling your request.")); } var productToReturn = Mapper.Map <Models.ProductDto>(finalProduct); return(CreatedAtRoute("GetProduct", new { productId = productId, saleItemId = productToReturn.Id }, productToReturn)); }
public IActionResult CreateProductFeature(int productId, [FromBody] ProductFeatureForCreationDto productFeature) { if (null == productFeature) { return(BadRequest()); } //Description and name can not be the same (for some reason) if (productFeature.Name == productFeature.Description) { ModelState.AddModelError("Description", "The description must be different to name"); } if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (!_productInfoRepository.ProductExists(productId)) { return(NotFound()); } var newProductFeature = Mapper.Map <Entities.ProductFeature>(productFeature); _productInfoRepository.AddFeatureForProduct(productId, newProductFeature); if (!_productInfoRepository.Save()) { return(StatusCode(500, "Failed to save")); } var newProductFeatureReturn = Mapper.Map <Models.ProductFeatureDto>(newProductFeature); //Note the returned productId is the same as the one that was passed in return(CreatedAtRoute("GetProductFeature", new { productid = productId, id = newProductFeature.Id }, newProductFeatureReturn)); }