public ActionResult <IEnumerable <Ingredient> > Get() { try { return(Ok(_service.Get())); } catch (Exception e) { return(BadRequest(e.Message)); } }
public ActionResult <IEnumerable <Ingredient> > GetAction() { try { return(Ok(_ingredientsService.Get())); } catch (System.Exception err) { return(BadRequest(err.Message)); } }
public IActionResult Get(string name) { var authId = User.Claims.FirstOrDefault(c => c.Type == ClaimTypes.NameIdentifier).Value; if (string.IsNullOrWhiteSpace(name)) { var fetchAll = new ResponseModel { Success = true, Message = "Found ingredients.", Data = new Data { Ingredients = _ingredientsService.Get(authId) } }; /* * var successResponse = new[] * { * fetchAll * };*/ return(Ok(new[] { fetchAll })); } else { name = name.ToLower(); List <Ingredient> ingredients = _ingredientsService.GetIngredientsByName(name); if (ingredients == null || ingredients.Count == 0) { var notFound = new ResponseModel { Success = false, Message = "Not found", Data = null, Instance = HttpContext.Request.Path }; var notFoundResponse = new[] { notFound }; return(NotFound(notFoundResponse)); } var success = new ResponseModel { Success = true, Message = "Found named ingredients.", Data = new Data { Ingredients = ingredients } }; /* * var successResponse = new [] * { * success * };*/ return(Ok(new[] { success })); } }
public async Task <IActionResult> Get() { var ingredients = await _ingredientsService.Get(); return(Ok(ingredients)); }