Beispiel #1
0
        public async Task <Ingredient> CreateAsync(IngredientCreateDTOin input)
        {
            Ingredient ing = this.mapper.Map <Ingredient>(input);

            await this.ingRepo.AddAssync(ing);

            await this.ingRepo.SaveChangesAsync();

            return(ing);
        }
        public async Task <ActionResult <int> > Create(IngredientCreateDTOin newIng)
        {
            if (await this.ingService.IsNameUsedAsync(newIng.Name))
            {
                return(BadRequest("Ingredient Name is already in Use"));
            }
            if (this.UserId != newIng.AuthorId)
            {
                return(BadRequest("UserId and AuthorId missmatch!"));
            }
            Ingredient result = await this.ingService.CreateAsync(newIng);

            if (result is null)
            {
                return(BadRequest("Ingredient was not created!"));
            }
            return(result.Id);
        }