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));
            }
        }
        public bool Update(ValueForUpdateDto valueForUpdateDto)
        {
            var valueForUpdated = _mapper.Map <Value>(valueForUpdateDto);
            var updatedValue    = _uow.Values.Update(valueForUpdated);

            return(_uow.Save() > 0 ? true : false);
        }
        public bool Update(ValueForUpdateDto valueForUpdateDto)
        {
            var valueToUpdate = new Value
            {
                Id   = valueForUpdateDto.Id,
                Name = valueForUpdateDto.Name
            };

            var updatedValue = _uow.Values.Update(valueToUpdate);

            return(_uow.Save() > 0 ? true : false);
        }
        public async Task <IActionResult> Put(int id, ValueForUpdateDto valueForUpdate)
        {
            var data = await repository.GetValue(id);

            mapper.Map(valueForUpdate, data);

            if (await repository.SaveAll())
            {
                return(Ok(data));
            }

            return(BadRequest());
        }
        public async Task <IActionResult> UpdateValue(int id, ValueForUpdateDto valueForUpdateDto)
        {
            var valueFromRepo = await _repo.GetValue(id);

            _mapper.Map(valueForUpdateDto, valueFromRepo);

            valueFromRepo.LastUpdated = DateTime.Now;

            if (await _repo.SaveAll())
            {
                return(NoContent());
            }

            throw new Exception($"Updating value {id} failed on save");
        }
Beispiel #6
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));
            }
        }