예제 #1
0
        public async Task <IActionResult> PutConcert([FromRoute] int id, [FromBody] Concert concert)
        {
            _logger.LogInformation("-> requested PUT /concerts");
            if (!ModelState.IsValid)
            {
                _logger.LogError("-> PUT /concerts model is not valid");
                _logger.LogInformation("-> PUT /concerts returned BadRequest");
                return(BadRequest(ModelState));
            }

            if (id != concert.Id)
            {
                _logger.LogInformation("-> PUT /concerts returned BadRequest");
                return(BadRequest());
            }

            _repo.ChangeState(concert, EntityState.Modified);

            try
            {
                await _repo.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!_repo.ConcertExists(id))
                {
                    _logger.LogInformation("-> PUT /concerts returned NotFound");
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }
            _logger.LogInformation("-> PUT /concerts returned NoContent");
            return(NoContent());
        }