Exemplo n.º 1
0
        public ActionResult <CommandReadDto> CreateCommand(CommandCreateDto commandCreateDto)
        {
            var commandModel = _mapper.Map <Command>(commandCreateDto);
            int id           = _repository.CreateCommand(commandModel);

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

            commandReadDto.Id = id;
            return(CreatedAtRoute(nameof(GetCommandById), new { id = 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(CreatedAtRoute(nameof(GetCommandById), new { Id = commandReadDto.Id }, commandReadDto));
        }
Exemplo n.º 3
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(commandReadDto));
        }
Exemplo n.º 4
0
        public ActionResult <CommandReadDto> CreateCommand(CommandCreateDto cmdCreateDto)
        {
            var cmd = mapper.Map <Command>(cmdCreateDto);

            repo.CreateCommand(cmd);
            repo.SaveChanges();  // This also updates the context and the objects passed to it including cmd.
            var cmdReadDto = mapper.Map <CommandReadDto>(cmd);

            return(CreatedAtRoute(nameof(GetCommandById), new { Id = cmdReadDto.Id }, cmdReadDto));
        }
Exemplo n.º 5
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(CreatedAtRoute("GetCommandById",
                                  new { Id = commandReadDTO.Id },
                                  commandReadDTO));
        }
Exemplo n.º 6
0
        public ActionResult CreateCommand(CommandCreateDto dto)
        {
            var cmd = _mapper.Map <Command>(dto);

            _repo.CreateCommand(cmd);
            // this add Id to cmd (by reference)
            _repo.SaveChanges();

            var cmdReadDto = _mapper.Map <CommandReadDto>(cmd);

            return(CreatedAtRoute(nameof(GetCommandById), new { Id = cmdReadDto.Id }, cmdReadDto));
        }
Exemplo n.º 7
0
        public ActionResult <CommandReadDto> CreateCommand(CommandCreateDto commandCreateDto)
        {
            var commandModel = _mapper.Map <Command>(commandCreateDto);

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

            // this method return 201 status code, the newly created object and the uri of the object.
            // for nameof(GetCommandById) to work we need to name the GetCommandById action: Name="GetCommandById" in the httpget attribute
            return(CreatedAtRoute(nameof(GetCommandById), new { Id = commandReadDto.Id }, commandReadDto));
        }
Exemplo n.º 8
0
        public ActionResult <CommandReadDto> CreateCommand(CommandCreateDto commandCreateDto)
        {
            var commandModel = _mapper.Map <Command>(commandCreateDto);

            _repository.CreateCommand(commandModel);
            _repository.SaveChanges();  // This also updated commandModel var to reflect a valid Id value
            var commandReadDto = _mapper.Map <CommandReadDto>(commandModel);

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

            reposService.CreateCommand(commandModel);
            reposService.SaveChanges();

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

            //The CreatedAtRoute method is intended to return a URI to the newly created resource when you invoke a POST method to store some new object.
            //So if you POST an order item for instance, you might return a route like 'api/order/11' (11 being the id of the order obviously).
            return(CreatedAtRoute(nameof(GetCommandById), new { Id = commandReadDto.Id }, commandReadDto));
        }
Exemplo n.º 10
0
        public async Task <ActionResult <CommandReadDto> > CreateCommand([FromBody] CommandCreateDto cmd)
        {
            Command newCommand = _mapper.Map <Command>(cmd);

            await Task.Run(() => _commandAPIRepo.CreateCommand(newCommand));

            await Task.Run(() => _commandAPIRepo.SaveChanges());

            CommandReadDto createdCommand = _mapper.Map <CommandReadDto>(newCommand);

            //return Created("Success", new { data = createdCommand });

            return(
                CreatedAtRoute(
                    nameof(GetCommandById),
                    new { Id = createdCommand.Id },
                    new { data = createdCommand }
                    )
                );
        }
Exemplo n.º 11
0
        public ActionResult <Command> createCommands(Command cmd)
        {
            var commandItem = _repository.CreateCommand(cmd);

            return(Ok(commandItem));
        }