Example #1
0
        public async Task <IActionResult> Put(int id, [FromBody] TViewModel viewModel)
        {
            _logger.LogTrace(LogEventId, AwesomeMethods.ConvertDataForLog(viewModel, _converter));

            if (viewModel.Id != id)
            {
                _logger.LogError(LogEventId, $"INVALID ID : ({id})");
                return(BadRequest(_response
                                  .AddError(_localizer["InvalidId"])
                                  .Get()));
            }

            if (!await _repository.Exists(id))
            {
                _logger.LogWarning(LogEventId, $"NOT FOUND : ID ({id})");
                return(NotFound(_response
                                .AddWarning(_localizer["IdNotFound"])
                                .Get()));
            }

            var model = Mapper.Map <TModel>(viewModel);

            _repository.Update(model);

            return(await ApplyChanges(model));
        }