コード例 #1
0
        public async Task <IActionResult> Update(int id, [FromBody] DirectorUpdateDTO directorDTO)
        {
            try
            {
                _logger.LogInfo("Update started");
                if (id < 1 || directorDTO == null || id != directorDTO.Id)
                {
                    _logger.LogWarn("Empty request");
                    return(BadRequest());
                }
                var isExists = await _directorRepository.IsExists(id);

                if (!isExists)
                {
                    _logger.LogWarn("Director does not exists");
                    return(BadRequest());
                }
                var director  = _mapper.Map <Director>(directorDTO);
                var isSuccess = await _directorRepository.Update(director);

                if (!isSuccess)
                {
                    return(InternalError("Director update failed"));
                }
                _logger.LogInfo("Director updated");
                return(NoContent());
            }
            catch (Exception ex)
            {
                return(InternalError($"Something went wrong: {ex.Message}"));
            }
        }