public async Task AddAsync(IngredientCreateDto ingredientCreateDto)
        {
            var payload = JsonConvert.SerializeObject(ingredientCreateDto);

            var content = new StringContent(
                payload,
                Encoding.UTF8,
                "application/json"
                );
            var relativeUri = new Uri(IngredientListsDynamicRoutes.INGREDIENT_LIST_ROUTE(_ingredientListId),
                                      UriKind.Relative);
            var httpResponseMessage = await _httpClient.PutAsync(
                relativeUri,
                content
                );

            if (httpResponseMessage.StatusCode != HttpStatusCode.OK)
            {
                var responseContent = await httpResponseMessage.Content.ReadAsStringAsync();

                var exception = HttpResponseContentToException.Convert(responseContent);

                throw exception;
            }
        }
 private async Task When_I_add_a_ingredient()
 {
     _lemonIngredientCreateDto = new IngredientCreateDto
     {
         Title       = "Lemon",
         Description = "An acid fruit that is botanically a many-seeded pale yellow oblong berry produced by a small thorny citrus tree (Citrus limon) and that has a rind from which an aromatic oil is extracted"
     };
     await _client.IngredientLists
     .List(_ingredientListId)
     .AddAsync(_lemonIngredientCreateDto);
 }
예제 #3
0
        public ActionResult <IngredientReadDto> CreateIngredient(IngredientCreateDto ingredientCreateDto)
        {
            var ingredientModel = _mapper.Map <Ingredient>(ingredientCreateDto);

            _baseRepo.ingredient.CreateIngredient(ingredientModel);

            _baseRepo.SaveChanges();

            var ingredientReadDto = _mapper.Map <IngredientReadDto>(ingredientModel);

            return(CreatedAtRoute(nameof(GetIngredientById), new { Id = ingredientReadDto.IngredientId }, ingredientReadDto));
        }
        private async Task When_I_add_a_ingredient_with_a_title_of_91_length()
        {
            _ingredientWithTooLongTitleCreateDto = new IngredientCreateDto
            {
                Title       = "this title is 91 chars long !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!",
                Description = "this ingredients title is expected to be too long"
            };



            _titleLengthTooLongException = await Assert.ThrowsAsync <TitleLengthTooLongException>(() =>
                                                                                                  _client.IngredientLists
                                                                                                  .List(_ingredientListId)
                                                                                                  .AddAsync(_ingredientWithTooLongTitleCreateDto)
                                                                                                  );
        }
        public async Task <IActionResult> AddIngredientAsync(Guid ingredientListId,
                                                             [FromBody] IngredientCreateDto ingredientCreateDto)
        {
            IActionResult actionResult;

            try
            {
                var ingredient     = IngredientCreateDto.ToIngredient(ingredientCreateDto);
                var ingredientList = await _ingredientListRepository.GetAsync(ingredientListId);

                ingredientList.AddIngredientToList(ingredient);

                actionResult = Ok();
            }
            catch (Exception exception) when(ExceptionToStatusCode.CanConvert(exception, out actionResult))
            {
            }

            return(actionResult);
        }
예제 #6
0
        public async Task <ActionResult> Create(IngredientCreateDto command)
        {
            await CommandDispatcher.DispatchAsync(command);

            return(Created($"api/ingredients/{command.Name}", null));
        }