//==========================CREATE===============================//


        public async Task <bool> CreateNewIngredient(CreateIngredient model)
        {
            var entity =
                new Ingredient()
            {
                Name = model.Name,
            };

            _context.Ingredients.Add(entity);
            return(await _context.SaveChangesAsync() == 1);
        }
        public virtual HttpResponseMessage Post(CreateIngredient createIngredient)
        {
            Ingredient ingredient = AutoMapper.Map <CreateIngredient, Ingredient>(createIngredient);

            ingredientService.Add(ingredient);

            Ingredient    createdIngredient    = ingredientService.Get(ingredient.Id);
            IngredientDto createdIngredientDto = AutoMapper.Map <Ingredient, IngredientDto>(createdIngredient);

            createdIngredientDto.Unit = unitService.Get(ingredient.UnitId);

            return(Request.CreateResponse(HttpStatusCode.Created, createdIngredientDto));
        }
Beispiel #3
0
        public object Post(CreateIngredient request)
        {
            long Id = 0;
            try
            {
                var ing = ingRepos.Add(request as Ingredient);

                Id = ing.Id;
            }
            catch (Exception ex)
            {
                logger.Error(ex.Message + ex.StackTrace);
                return new HttpResult(System.Net.HttpStatusCode.InternalServerError, ex.Message);
            }

            return new HttpResult(System.Net.HttpStatusCode.Created, "Ingredient Created:" + Id);
        }
 public async Task <IActionResult> Create(CreateIngredient createIngredient) =>
 (await _createIngredientHandler.Handle(createIngredient))
 .Match <IActionResult>(
     result => Ok(result),
     erro => BadRequest(erro));