public Command CreateCommand(Command command) { if (command == null) { throw new ArgumentException(nameof(command)); } command.Id = Guid.NewGuid(); return(_commandRepository.CreateCommand(command)); }
public ActionResult <CommandReadDTO> CreateCommand(CommandCreateDTO command) { var commandModel = _mapper.Map <Command>(command); _repository.CreateCommand(commandModel); _repository.SaveChanges(); var commandRead = _mapper.Map <CommandReadDTO>(commandModel); return(CreatedAtRoute(nameof(GetCommandById), new { Id = commandRead.Id }, commandRead)); }
public ActionResult <CommandReadDto> CreateCommand([FromBody] CommandCreateDto cmd) { var commandModel = _mapper.Map <Command>(cmd); _commandRepository.CreateCommand(commandModel); _commandRepository.SaveChanges(); var commandReadDto = _mapper.Map <CommandReadDto>(commandModel); return(CreatedAtRoute(nameof(GetCommandById), new { Id = commandReadDto.Id }, commandReadDto)); }
public ActionResult <CommandReadDTO> CreateCommand(CommandCreateDTO commandCreate) { var commandModel = _mapper.Map <Command>(commandCreate); _ICommand.CreateCommand(commandModel); _ICommand.SaveChanges(); var commandReadDTO = _mapper.Map <CommandReadDTO>(commandModel); return(CreatedAtRoute(nameof(GetCommandById), new { Id = commandReadDTO.Id }, commandReadDTO)); // 201 Created //return Ok(commandReadDTO); }
public ActionResult <CommandReadDto> CreateCommand(CommandCreateDto newCommand) { var commandModel = _mapper.Map <Command>(newCommand); _repository.CreateCommand(commandModel); // persist the created command _repository.SaveChanges(); // return Ok(commandModel); // return the created command using the GetCommandById route return(CreatedAtRoute(nameof(GetCommandById), new { Id = commandModel.Id }, commandModel)); }
public ActionResult <CommandReadDto> CreateCommand(CommandCreateDto commandCreateDto) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var commandModel = _mapper.Map <Command>(commandCreateDto); _repository.CreateCommand(commandModel); _repository.SaveChanges(); var commandReadDto = _mapper.Map <CommandReadDto>(commandModel); return(CreatedAtRoute(nameof(GetCommandById), new { Id = commandReadDto.Id }, commandReadDto)); }