public IActionResult AddProduct([FromBody] Product product) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var productType = _productTypeRepository.GetProductType(product.ProductTypeId); if (productType == null) { return(NotFound("Cannot find product type with provided productTypeId.")); } var macronutrient = _macronutrientRepository.GetMacronutrient(product.MacronutrientId); if (macronutrient == null) { return(NotFound("Cannot find macronutrient with provided macronutrientId.")); } _productRepository.AddProduct(product, productType, macronutrient); return(new JsonResult(product.Id)); }
public async Task <IActionResult> GetProductType(int id) { if (!_auth.IsValidUser(User)) { return(NoContent()); } var productType = await _repo.GetProductType(id); return(Ok(productType)); }
public async Task <IActionResult> GetProductType(int id) { var type = await _repo.GetProductType(id); var typeForView = _mapper.Map <ProductTypeForViewDto>(type); return(Ok(typeForView)); }
public IActionResult GetProductType(int productTypeId) { if (productTypeId <= 0) { return(BadRequest("Incorrent productTypeId.")); } return(new JsonResult(_productTypeRepository.GetProductType(productTypeId))); }
public IActionResult Get([FromODataUri] int productTypeId) { try { var productType = _productTypeRepository.GetProductType(productTypeId); if (productType == null) { return(NotFound()); } var result = Mapper.Map <ProductTypeDto>(productType); return(Ok(result)); } catch (Exception ex) { _logger.LogError($"Failed in Get /ProductTypes(productTypeId): {ex}"); return(BadRequest()); } }
public async Task <ActionResult <ProductType> > GetProductType(int id) { var prodType = await _productTypeRepo.GetProductType(id); if (prodType == null) { return(NotFound()); } return(Ok(prodType)); }
public async Task <ActionResult <ProductType> > GetProductType(int productTypeId) { var productType = await _productTypeRepository.GetProductType(productTypeId); if (productType == null) { return(NotFound($"Product type with id: {productTypeId} does not exist")); } return(Ok(productType)); }
public ProductType GetProductType(System.Int32 ProductTypeId) { return(_iProductTypeRepository.GetProductType(ProductTypeId)); }
public IEnumerable <ProductType> Get() { return(_repo.GetProductType()); }