コード例 #1
0
        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));
        }
コード例 #2
0
        public async Task <IActionResult> GetProductType(int id)
        {
            if (!_auth.IsValidUser(User))
            {
                return(NoContent());
            }

            var productType = await _repo.GetProductType(id);

            return(Ok(productType));
        }
コード例 #3
0
        public async Task <IActionResult> GetProductType(int id)
        {
            var type = await _repo.GetProductType(id);

            var typeForView = _mapper.Map <ProductTypeForViewDto>(type);

            return(Ok(typeForView));
        }
コード例 #4
0
        public IActionResult GetProductType(int productTypeId)
        {
            if (productTypeId <= 0)
            {
                return(BadRequest("Incorrent productTypeId."));
            }

            return(new JsonResult(_productTypeRepository.GetProductType(productTypeId)));
        }
コード例 #5
0
        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());
            }
        }
コード例 #6
0
        public async Task <ActionResult <ProductType> > GetProductType(int id)
        {
            var prodType = await _productTypeRepo.GetProductType(id);

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

            return(Ok(prodType));
        }
コード例 #7
0
        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));
        }
コード例 #8
0
 public ProductType GetProductType(System.Int32 ProductTypeId)
 {
     return(_iProductTypeRepository.GetProductType(ProductTypeId));
 }
コード例 #9
0
 public IEnumerable <ProductType> Get()
 {
     return(_repo.GetProductType());
 }