Ejemplo n.º 1
0
        public ActionResult UpdateCommand(int id, CommandUpdateDto commandUpdateDto)
        {
            var commandModelRepo = _commandRepo.GetCommandById(id);

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

            _mapper.Map(commandUpdateDto, commandModelRepo);

            _commandRepo.UpdateCommand(commandModelRepo);

            return(NoContent());
        }
Ejemplo n.º 2
0
        public ActionResult UpdateCommand(int id, CommandUpdateDto commandUpdateDto)
        {
            var commandModelFromRepo = _repository.GetCommandById(id);

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

            _mapper.Map(commandUpdateDto, commandModelFromRepo);
            _repository.UpdateCommand(commandModelFromRepo);

            _repository.SaveChanges();

            return(NoContent());
        }
Ejemplo n.º 3
0
        public ActionResult PartialComandUpdate(int id, JsonPatchDocument <CommandUpdateDto> patchDoc)
        {
            var commandModelFromRepo = _repository.GetCommandById(id);

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

            var commandToPatch = _mapper.Map <CommandUpdateDto>(commandModelFromRepo);

            patchDoc.ApplyTo(commandToPatch, ModelState);

            if (!TryValidateModel(commandToPatch))
            {
                return(ValidationProblem(ModelState));
            }

            _mapper.Map(commandToPatch, commandModelFromRepo);

            _repository.UpdateCommand(commandModelFromRepo);

            _repository.SaveChanges();

            return(NoContent());
        }
Ejemplo n.º 4
0
        public ActionResult UpdateCommand(int id, JsonPatchDocument <CommandUpdateDto> patchDoc)
        {
            try
            {
                //Validation
                var commandModel = _repository.GetCommandById(id);
                if (commandModel == null)
                {
                    return(NotFound());
                }

                var commandToPatch = _mapper.Map <CommandUpdateDto>(commandModel);

                patchDoc.ApplyTo(commandToPatch, ModelState);

                //Validate model to patch
                if (!TryValidateModel(commandToPatch))
                {
                    return(ValidationProblem(ModelState));
                }

                _mapper.Map(commandToPatch, commandModel);

                _repository.UpdateCommand(commandModel);

                _repository.SaveChanges();

                return(Ok());
            }
            catch (Exception e)
            {
                throw e;
            }
        }
Ejemplo n.º 5
0
        public ActionResult UpdateCommand(int id, CommandDtoUpdate commandDtoUpdate)
        {
            var commandFromRepo = _repo.GetCommandById(id);

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

            _mapper.Map(commandDtoUpdate, commandFromRepo);

            _repo.UpdateCommand(commandFromRepo);
            _repo.SaveChanges();

            return(NoContent());
        }
Ejemplo n.º 6
0
        public ActionResult UpdateCommand(int id, CommandUpdateDto commandUpdateDto)
        {   // kinda placeholder
            var commandModelFromRepo = _repository.GetCommandById(id);

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

            _mapper.Map(commandUpdateDto, commandModelFromRepo);
            // this mapping actually updates our model and those changes are being tracked
            // by DbContext, so we dont need to do anything in UpdateCommand in SqlRepo
            // but good practice is still to call Update method on our repository and supply our model
            // our implementations may need that

            _repository.UpdateCommand(commandModelFromRepo);

            _repository.SaveChanges(); // we need to do that!

            return(NoContent());
        }
Ejemplo n.º 7
0
        public ActionResult UpdateCommand(int id, CommandUpdateDto commandUpdate)
        {
            var updateCommand = _repo.GetCommandById(id);

            if (updateCommand == null)
            {
                NotFound();
            }
            _mapper.Map(commandUpdate, updateCommand);
            _repo.UpdateCommand(updateCommand);
            _repo.SaveChanges();
            return(Ok(updateCommand));
        }
Ejemplo n.º 8
0
        public ActionResult UpdateCommand(int id, [FromForm] CommandUpdateDto commandUpdateDto)
        {
            var commandFromRepo = _repository.GetCommandById(id);

            //validations
            if (commandFromRepo == null)
            {
                return(NotFound());
            }

            _mapper.Map(commandUpdateDto, commandFromRepo);

            _repository.UpdateCommand(commandFromRepo);//Good practice

            _repository.SaveChanges();

            return(NoContent());
        }
Ejemplo n.º 9
0
        public ActionResult PartialCommandUpdate(int id, JsonPatchDocument<CommandUpdateDto> patchDocument)
        {
            var command = _repository.GetCommandById(id);
            if (command == null)
            {
                return NotFound();
            }
            var commandDto = _mapper.Map<CommandUpdateDto>(command);
            patchDocument.ApplyTo(commandDto, ModelState);

            if (!TryValidateModel(commandDto))
            {
                return ValidationProblem(ModelState);
            }

            _mapper.Map(commandDto, command);
            _repository.UpdateCommand(command);
            _repository.SaveChanges();
            return NotFound();

        }