コード例 #1
0
        public async Task <ActionResult> Put(Guid id, [FromBody] UpdatePlantViewModel model)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            try
            {
                UpdatePlantModel updatePlantModel = _mapper.Map <UpdatePlantModel>(model);
                updatePlantModel.Id = id;

                Plant plant = await _commands.Update(updatePlantModel);

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

                return(Ok(_mapper.Map <PlantDetailsViewModel>(plant)));
            }
            catch (Exception ex) when(ex is ResourceNotFoundException)
            {
                return(NotFound(new ErrorViewModel(ex)));
            }
            catch (Exception ex) when(ex is ResourceStateException)
            {
                return(Conflict(new ErrorViewModel(ex)));
            }
        }
コード例 #2
0
ファイル: IntegrationTests.cs プロジェクト: JachuPL/Spice
        public async Task PutPlantReturnsBadRequestAndCorrectContentType()
        {
            // Given
            UpdatePlantViewModel 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");
        }