public ActionResult UpdateCommand(int id, CommanderUpdateDto cmd)
        {
            var commandModelFromRepo = _repo.GetCommandById(id);

            if (commandModelFromRepo == null)
            {
                return(NotFound());
            }
            _mapper.Map(cmd, commandModelFromRepo);
            _repo.UpdateCommand(commandModelFromRepo);
            _repo.SaveChanges();

            return(NotFound());
        }
        public ActionResult UpdateCommand(int id, CommanderUpdateDto commanderUpdateDto)
        {
            var cmd = _repo.GetCommandById(id);

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

            _mapper.Map(commanderUpdateDto, cmd);

            _repo.Savechanges();
            return(NoContent());
        }
Example #3
0
        public ActionResult UpdateCommand(int id, CommanderUpdateDto commanderUpdateDto)
        {
            var commandModelFromRepo = _repository.GetCommandById(id);

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

            // this mapping has updated the commandModelFromRepo with values coming from
            // commandUpdate. so we don't actually have to do anything other than save changes
            _mapper.Map(commanderUpdateDto, commandModelFromRepo);

            // in this case we don't have to use the following but keeping this is good pratice
            _repository.UpdateCommand(commandModelFromRepo);

            _repository.SaveChanges();

            return(NoContent());
        }