Пример #1
0
        public async Task <ActionResult> Put(Guid id, [FromBody] UpdateNutrientViewModel model)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            try
            {
                UpdateNutrientModel updateNutrientModel = _mapper.Map <UpdateNutrientModel>(model);
                updateNutrientModel.Id = id;

                Nutrient nutrient = await _commands.Update(updateNutrientModel);

                if (nutrient is null)
                {
                    return(NotFound());
                }

                return(Ok(_mapper.Map <NutrientDetailsViewModel>(nutrient)));
            }
            catch (Exception ex) when(ex is ResourceStateException)
            {
                return(Conflict(new ErrorViewModel(ex)));
            }
        }
Пример #2
0
        public async Task PutNutrientReturnsBadRequestAndCorrectContentType()
        {
            // Given
            UpdateNutrientViewModel model = ViewModelFactory.CreateInvalidUpdateModel();

            // When
            HttpResponseMessage response = await Client.PutAsJsonAsync(EndPointFactory.UpdateEndpoint(), model);

            // Then
            response.StatusCode.Should().Be(HttpStatusCode.BadRequest);
            response.Content.Headers.ContentType.ToString().Should().Be("application/problem+json; charset=utf-8");
        }