コード例 #1
0
        //==========================CREATE===============================//


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

            _context.Ingredients.Add(entity);
            return(await _context.SaveChangesAsync() == 1);
        }
コード例 #2
0
        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));
        }
コード例 #3
0
ファイル: Services.cs プロジェクト: neotamizhan/VitaTop
        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);
        }
コード例 #4
0
 public async Task <IActionResult> Create(CreateIngredient createIngredient) =>
 (await _createIngredientHandler.Handle(createIngredient))
 .Match <IActionResult>(
     result => Ok(result),
     erro => BadRequest(erro));