public ActionResult <Ingredient> Create([FromBody] Ingredient newIng) { try { return(Ok(_service.Create(newIng))); } catch (Exception e) { return(BadRequest(e.Message)); } }
public ActionResult <Ingredient> Create([FromBody] Ingredient newIngredient) { try { return(Ok(_ingredientsService.Create(newIngredient))); } catch (System.Exception err) { return(BadRequest(err.Message)); } }
public async Task <ActionResult <Ingredient> > Create([FromBody] Ingredient newIngredient) { try { // TODO[epic=Auth] Get the user info to set the creatorID Account userInfo = await HttpContext.GetUserInfoAsync <Account>(); // safety to make sure an account exists for that user before CREATE-ing stuff. _acctService.GetOrCreateAccount(userInfo); // newIngredient.CreatorId = userInfo.Id; Ingredient ingredient = _service.Create(newIngredient); return(Ok(ingredient)); } catch (Exception e) { return(BadRequest(e.Message)); } }
public ActionResult <string> Create([FromBody] Ingredient ingredient) { var authId = User.Claims.FirstOrDefault(c => c.Type == ClaimTypes.NameIdentifier).Value; //string ownerId = ""; Ingredient ingredientToCreate = new Ingredient(); if (ingredient.Owner == authId) // validate owner Id matches with tokenId { //ownerId = ingredient.Owner; _logger.LogDebug("TRYING TO CREATE INGREDIENT..."); ingredientToCreate = _ingredientsService.Create(ingredient); _logger.LogDebug($"INGREDIENT CREATED: {ingredientToCreate.Id}"); } else { return(NotFound()); } _logger.LogDebug($"NEW INGREDIENT ID: {ingredientToCreate.Id}"); return(CreatedAtRoute( routeName: nameof(GetById), routeValues: new { id = ingredientToCreate.Id.ToString() }, value: ingredientToCreate)); }