예제 #1
0
        public ActionResult <CommandReadDTO> CreateCommand(CommandCreateDTO newCommand)
        {
            var command = _mapper.Map <Command>(newCommand);

            _repo.CreateCommand(command);
            _repo.SaveChanges();

            return(CreatedAtRoute(nameof(GetCommandById), new { Id = command.Id }, _mapper.Map <CommandReadDTO>(command)));
        }
예제 #2
0
        public ActionResult <CommandReadDto> CreateCommand(CommandCreateDto commandCreateDto)
        {
            Command command = mapper.Map <Command>(commandCreateDto);

            repository.CreateCommand(command);
            repository.SaveChanges();
            CommandReadDto commandReadDto = mapper.Map <CommandReadDto>(command);

            return(CreatedAtRoute(nameof(GetCommandById), new { Id = commandReadDto.Id }, commandReadDto));
        }
        public ActionResult <CommandReadDto> CreateCommand(CommandCreateDto commandCreateDto)
        {
            var commandModel = _mapper.Map <Command>(commandCreateDto);

            _repository.CreateCommand(commandModel);

            var commandReadDto = _mapper.Map <CommandReadDto>(commandModel);

            return(CreatedAtRoute(nameof(GetCommandById), new { Id = commandReadDto.Id }, commandReadDto));
        }
예제 #4
0
        public ActionResult <CommandReadDTO> CreateCommand(CommandCreateDTO newCommand)
        {
            var commandModel = _mapper.Map <Command>(newCommand);

            _repository.CreateCommand(commandModel);
            _repository.SaveChanges();

            var commandReturnValue = _mapper.Map <CommandReadDTO>(commandModel);

            return(CreatedAtRoute(nameof(GetCommandById), new { Id = commandReturnValue.Id }, commandReturnValue));
        }
예제 #5
0
        public ActionResult <CommandReadDto> CreateCommand([FromBody] CommandCreateDto ccd)
        {
            var commandModel = mapper.Map <Command>(ccd);

            repository.CreateCommand(commandModel);
            repository.SaveChanges();

            var commandReadDto = mapper.Map <CommandReadDto>(commandModel);

            return(CreatedAtRoute(nameof(GetCommandById), new { Id = commandReadDto.Id }, commandReadDto));
        }
예제 #6
0
        public ActionResult <CommandReadDto> CreateCommand(CommandCreateDto commandCreateDto)
        {
            var command = _mapper.Map <Command>(commandCreateDto);

            _commanderRepository.CreateCommand(command);
            _commanderRepository.SaveChanges();

            var commandReadDto = _mapper.Map <CommandReadDto>(command);

            return(CreatedAtRoute("GetCommandById", new { Id = commandReadDto.Id }, commandReadDto));
        }
예제 #7
0
        public ActionResult <CommandReadDto> CreateCommand(CommandCreateDto command)
        {
            var commandModel = _mapper.Map <Command>(command);

            _repository.CreateCommand(commandModel);
            _repository.SaveChanges();

            var commandReadDto = _mapper.Map <CommandReadDto>(commandModel);

            return(Ok(commandReadDto));
        }
예제 #8
0
        public ActionResult <CommandReadDTO> CreateCommand(CommandCreateDTO commandCreateDTO)
        {
            var commandModel = Mapper.Map <Command>(commandCreateDTO);

            Repository.CreateCommand(commandModel);
            Repository.SaveChanges();

            var commandReadDTO = Mapper.Map <CommandReadDTO>(commandModel);

            //return Ok(commandModel);
            return(CreatedAtRoute(nameof(GetCommandById), new { Id = commandReadDTO.Id }, commandReadDTO));
        }
예제 #9
0
        public ActionResult <CommandReadDTO> CreateCommand([FromBody] CommandCreateDTO commandCreateDTO)
        {
            var commandModel = _mapper.Map <Command>(commandCreateDTO);

            _repository.CreateCommand(commandModel);
            _repository.SaveChanges();

            var commandReadDto = _mapper.Map <CommandReadDTO>(commandModel);


            return(CreatedAtRoute(nameof(GetById), new { commandReadDto.Id }, commandReadDto));
        }
        public ActionResult <CommandReadDto> CreateCommand(CommandCreateDto commandCreateDto)
        {
            var command = _mapper.Map <Command>(commandCreateDto);

            _respository.CreateCommand(command);

            // return Ok(command); // 200 OK

            var commandReadDto = _mapper.Map <CommandReadDto>(command);

            return(CreatedAtRoute(nameof(GetById), new { Id = commandReadDto.Id }, commandReadDto)); // 201 Created
        }
예제 #11
0
        public ActionResult <CommandReadDto> CreateCommand(CommandCreateDto commandCreateDto)
        {
            var commandModel = _mapper.Map <Command>(commandCreateDto);

            _repository.CreateCommand(commandModel);
            _repository.SaveChanges();

            //this is kind of to get rid of platform data that we dont want to show
            var commandReadDto = _mapper.Map <CommandReadDto>(commandModel);

            return(CreatedAtRoute(nameof(GetCommandById), new { Id = commandReadDto.Id }, commandReadDto));
        }
예제 #12
0
        public ActionResult <CommandReadDto> CreateCommand(CommandCreateDto createDto)
        {
            //Since we're taking CommandCreateDto as argument, then the only way the object can be put into the db is by
            //mapping it into a Command model/ object, as that's the way db understands it
            var commandModel = _mapper.Map <Command>(createDto);

            _repository.CreateCommand(commandModel);
            _repository.SaveChanges();

            var commandReadDto = _mapper.Map <CommandReadDto>(commandModel);

            // Using the CreatedAtRoute method to return a 201 status code - https://stackoverflow.com/a/61691888/11124256
            return(CreatedAtRoute(nameof(GetCommandById), new { Id = commandReadDto.Id }, commandReadDto));
        }
        public ActionResult <CommandReadDto> CreateCommand(CommandCreateDto commandCreateDto)
        {
            var commandModel = _mapper.Map <Command>(commandCreateDto);

            _repository.CreateCommand(commandModel);
            _repository.SaveChanges();

            var commandReadDto = _mapper.Map <CommandReadDto>(commandModel);

            //return Ok(commandReadDto);

            // route, route values got to response header
            // created object goes to response body
            return(CreatedAtRoute(nameof(GetCommandById), new { id = commandReadDto.Id }, commandReadDto));
        }
예제 #14
0
        public ActionResult <CommandReadDTO> CreateCommand(CommandCreateDTO cmd)
        {
            var command = _mapper.Map <Command>(cmd);

            _repository.CreateCommand(command);

            _repository.SaveChanges();

            var commandReadDTO = _mapper.Map <CommandReadDTO>(command);

            //Return as a result the url that can be used to call the object creates
            //return as well a 201 result
            //For this to work is necessary to name your endpoint that you want to return, in this case the GET by Id
            return(CreatedAtRoute(nameof(GetById), new { Id = commandReadDTO.Id }, commandReadDTO));
            //return Ok(commandReadDTO);
        }
예제 #15
0
        public ActionResult <CommandReadDto> CreateCommand(CommandCreateDto commandCreateDto)
        {
            // Use Automapper to convert the Dto from the client into a Command model
            var commandModel = _mapper.Map <Command>(commandCreateDto);

            // Create the model in the repository, and save the changes to the db
            _repository.CreateCommand(commandModel);
            _repository.SaveChanges();

            // Use Automapper to create the Dto to be passed back to the client based on the commandModel provided
            var commandReadDto = _mapper.Map <CommandReadDto>(commandModel);

            // Returns the commandReadDto with the URI to the newly created resource URI included in the header (utilising the GetCommandById ActionResult)
            // This is important as part of the REST API spec of creating a new resource
            // CreatedAtRoute will also return a 201 Created response
            return(CreatedAtRoute(nameof(GetCommandById), new { Id = commandReadDto.Id }, commandReadDto));
        }