コード例 #1
0
        public async Task <IActionResult> Put(int id, [FromBody] ValueForUpdateDto valueForUpdateDto)
        {
            try
            {
                if (!ModelState.IsValid || id != valueForUpdateDto.Id)
                {
                    return(BadRequest());
                }

                var selectedValue = await _valueService.GetByIdAsync(id);

                if (selectedValue == null)
                {
                    return(NotFound());
                }

                _valueService.Update(valueForUpdateDto);
                return(NoContent());
            }
            catch (Exception ex)
            {
                _logger.LogError(ex.Message);
                return(StatusCode(500));
            }
        }
コード例 #2
0
        public async Task <ActionResult <ValueModel?> > Put(int id, [FromBody] ValueModel value)
        {
            if (id != value.Id)
            {
                return(KeyMismatchBadRequest());
            }

            TryValidateModel(value);
            return(OkOrNotFound(await _valueService.Update(value)));
        }
コード例 #3
0
        public IActionResult Put(int id, [FromBody] ValueForUpdateDto valueForUpdateDto)
        {
            try
            {
                if (!ModelState.IsValid || id != valueForUpdateDto.Id)
                {
                    return(BadRequest());
                }

                _valueService.Update(valueForUpdateDto);
                return(NoContent());
            }
            catch (Exception ex)
            {
                _logger.LogError(ex.Message);
                return(StatusCode(500));
            }
        }
コード例 #4
0
        public async Task <IActionResult> Put([FromBody] ValuesViewModel value)
        {
            try
            {
                if (!ModelState.IsValid)
                {
                    return(BadRequest(ModelState));
                }

                var customObject = await _valueService.Get(value.Id);

                customObject.Id   = value.Id;
                customObject.Name = value.Name;
                await _valueService.Update(customObject);

                return(Accepted());
            }
            catch (KeyNotFoundException)
            {
                Response.Headers.Add("x-status-reason", $"No resource was found with the unique identifier '{value.Id}'.");
                return(NotFound());
            }
        }
コード例 #5
0
 public async Task Update_InvalidId_GetsException()
 {
     await _valueService.Update(new ValueModel { Id = 5, Name = "FAIL" });
 }