Example #1
0
 public ActionResult <Ingredient> Get(int id)
 {
     try
     {
         return(Ok(_service.GetById(id)));
     }
     catch (Exception e)
     {
         return(BadRequest(e.Message));
     }
 }
Example #2
0
 public ActionResult <Ingredient> GetById(int id)
 {
     try
     {
         return(Ok(_ingredientsService.GetById(id)));
     }
     catch (System.Exception err)
     {
         return(BadRequest(err.Message));
     }
 }
Example #3
0
        public IActionResult GetById(string id)
        {
            var result = _ingredientsService.GetById(id);
            List <Ingredient> ingredient = new List <Ingredient>()
            {
                result
            };

            if (result == null)
            {
                var badRequest = new ResponseModel
                {
                    Success  = false,
                    Message  = "Bad Request.",
                    Data     = null,
                    Instance = HttpContext.Request.Path
                };

                var badRequestResponse = new[]
                {
                    badRequest
                };
                return(BadRequest(badRequestResponse));
            }

            var success = new ResponseModel
            {
                Success = true,
                Message = $"Found ingredient by ID: {id}.",
                Data    = new Data {
                    Ingredients = ingredient
                }
            };

            var successResponse = new[]
            {
                success
            };

            return(Ok(successResponse));
        }