示例#1
0
        public ActionResult <CommandReadDTO> PostCommand(CommandWriteDTO commandDTO)
        {
            var command = _mapper.Map <Command>(commandDTO);

            _repository.Command.PostCommand(command);
            if (_repository.SaveChanges())
            {
                return(CreatedAtRoute(nameof(GetCommandById), new { command.ComId }, _mapper.Map <CommandReadDTO>(command)));
            }
            return(NotFound());
        }
示例#2
0
        public ActionResult UpdateCommand(int id, CommandWriteDTO commandUpdateDTO)
        {
            var commandModel = _command_repo.GetCommandById(id);

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

            _mapper.Map(commandUpdateDTO, commandModel);
            _command_repo.UpdateCommand(commandModel);
            _command_repo.SaveChanges();

            return(NoContent());
        }
示例#3
0
        public ActionResult PutCommand(int id, CommandWriteDTO commandDTO)
        {
            var commandModelFromRepo = _repository.Command.GetCommandById(id);

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

            _mapper.Map(commandDTO, commandModelFromRepo);
            if (_repository.SaveChanges())
            {
                return(NoContent());
            }
            return(NotFound());
        }