Exemple #1
0
        public ActionResult <CommandReadDto> CreateCommand(CommandCreateDto commandCreateDto)
        {
            var commandModel = _mapper.Map <Command>(commandCreateDto);

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

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

            return(CreatedAtRoute(nameof(GetCommandById), new { Id = returnCommanReadDto.Id }, returnCommanReadDto));
        }
Exemple #2
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(nameof(GetCommandById), new { Id = commandReadDTO.Id }, commandReadDTO));
        }
        public ActionResult <CommandReadDto> CreateCommand([FromBody] CommandCreateDto cmd)
        {
            Command commandModel = _mapper.Map <Command>(cmd);

            _repo.CreateCommand(commandModel);
            _repo.SaveChanges();

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

            return(CreatedAtRoute(nameof(GetCommandById), new { commandReadDto.Id }, commandReadDto));
        }
        [HttpPost] // Post api/command
        public ActionResult <CommandCreateDTO> CreateCommand(CommandCreateDTO commandCreateDTO)
        {
            Command commandModel = _mapper.Map <Command>(commandCreateDTO);

            _repo.CreateCommand(commandModel);
            _repo.SaveChanges();

            CommandReadDTO commandReadDTO = _mapper.Map <CommandReadDTO>(commandModel);

            return(CreatedAtRoute("GetCommandById", new { commandReadDTO.Id }, commandReadDTO)); // Using HttpGet route name
        }
        public ActionResult <CommandReadDtos> CreateCommand(CommandCreateDtos cmd)
        {
            var commandModel = _mapper.Map <Command>(cmd);

            _repo.CreateCommand(commandModel);
            _repo.SaveChanges();
            var commandReadDto = _mapper.Map <CommandReadDtos>(commandModel);

            // return Ok(commandReadDto);
            return(CreatedAtRoute(nameof(GetCommandById), new { Id = commandReadDto.Id }, commandReadDto));
        }
Exemple #6
0
        public ActionResult <CommandCreateDto> CreateCommand(CommandCreateDto commandCreateDto)
        {
            var commandModel = _mapper.Map <Command>(commandCreateDto);

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

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

            //pogledati na dokumentaciji ovu metodu
            return(CreatedAtRoute("GetCommandById", new { Id = commandReadDto.Id }, commandReadDto));
        }
        public ActionResult <CommandReadDto> CreateCommand(CommandCreateDto command)
        {
            var newCommand = _mapper.Map <Command>(command);

            _repository.CreateCommand(newCommand);

            _repository.SaveChanges();

            var commandRead = _mapper.Map <CommandReadDto>(newCommand);

            return(CreatedAtRoute(nameof(GetCommandById), new { Id = newCommand.Id }, newCommand));
        }
Exemple #8
0
        //cogemos como input un CommandCreateDto y se devuelve como output un CommandReadDto.
        //queremos coger lo que haya en el body de la request y convertirlo en un modelo que podamos poner en nuestro repositorio, para eso usaremos Automapper
        public ActionResult <CommandReadDto> CreateCommand(CommandCreateDto commandCreateDto)
        {
            var commandModel = _mapper.Map <Command>(commandCreateDto);//queremos hace Map a Command y la source es commandCreateDto

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

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

            //para crear un 201 Created, buscar mas info de CreatedAtRoute method para mas info
            return(CreatedAtRoute(nameof(GetCommandById), new { Id = commandReadDto.Id }, commandReadDto));
        }
        public ActionResult <CommandCreateDto> CreateCommand(CommandCreateDto commandCreateDto)
        {
            //Source to target mapping
            var commandModel = _mapper.Map <Command>(commandCreateDto);

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

            // return Ok(commandReadDto);
            return(CreatedAtRoute(nameof(GetCommandById), new { Id = commandReadDto.Id }, commandReadDto));
        }
Exemple #10
0
      [HttpPost] public ActionResult <CommandCreateDto> CreateCommand(CommandCreateDto cm)
      {
          var cmdmodel = _mapper.Map <Command>(cm);

          _repo.CreateCommand(cmdmodel);
          _repo.SaveChanges();

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

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

            _repository.CreateCommand(commandModel);
            _repository.SaveChanges(); //this makes sure that the command created gets saved in our database

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

            //this returns a specific route for the command with a unique id. This also returns a 201 Created response
            return(CreatedAtRoute(nameof(GetCommandById), new { Id = commandReadDto.Id }, commandReadDto));
        }
Exemple #12
0
        public ActionResult <CommandReadDto> CreateCommand(CommandCreateDto commandCreateDto)
        {
            //Accept DTO Obj, cnvrt to Command model, pass it down to SQL Commander to add data return DTO
            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));
        }
Exemple #13
0
        public ActionResult <CommandReadDto> CreateCommand(CommandCreateDto commCreateDto)
        {
            var commandModel = _mapper.Map <Command>(commCreateDto);

            _repos.CreateCommand(commandModel);
            _repos.SaveChanges();

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

            // When run in the context of http, it will return the serialized object in the body, but you should see a header in the response with the link to the resource
            return(CreatedAtRoute(nameof(GetCommandById), new { Id = commandReadDto.Id }, commandReadDto));
        }
        //return CommandReadDto object
        public ActionResult <CommandReadDto> CreateCommand(CommandCreateDTO commandCreataeDTO)
        {
            var commandModel = _mapper.Map <Command>(commandCreataeDTO);//Command is Destination and source is CreateDTO

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

            var commandReadDto = _mapper.Map <CommandReadDto>(commandModel);//destination CommandReadDto and source CreateDto

            //return Ok(commandReadDto);//status code = 200
            return(CreatedAtRoute(nameof(GetCommandById), new { Id = commandReadDto.Id }, commandReadDto));
        }
        public ActionResult <CommandReadDto> CreateCommand(CommandCreateDto commandCreateDto)
        {
            var commandModel = _mapper.Map <Command>(commandCreateDto); //recuperamos el modelo mapeando del commandCreateDto a Command

            _repository.CreateCommand(commandModel);                    // pasamos el modelo recuperado al repositorio
            _repository.SaveChanges();

            var commandReadDto = _mapper.Map <CommandReadDto>(commandModel);//mapeamos del commandmodel a CommandReadDto(para devolver un dto específico)

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

            _reporsitory.CreateCommand(commandModel);
            _reporsitory.SaveChanges();

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

            return(CreatedAtRoute(nameof(GetCommandById), new{ id = objcommandReadDto.Id }, objcommandReadDto));
            //return Ok(objcommandReadDto);
        }
        public ActionResult <CommandeReadDto> CreateCommande(CommandeCreateDto commande)
        {
            var commandeModel = _mapper.Map <Commande>(commande);

            _repository.CreateCommande(commandeModel);
            _repository.SaveChanges();

            var CommandeReadDto = _mapper.Map <CommandeReadDto>(commandeModel);

            return(CreatedAtRoute(nameof(GetCommandeById), new { Id = CommandeReadDto.Id }, CommandeReadDto));
            //return Ok(CommandeReadDto);
        }
Exemple #18
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 is really really cool
            return(CreatedAtRoute(nameof(GetCommandById), new { id = commandReadDto.Id }, commandReadDto));
        }
Exemple #19
0
        public ActionResult <CommandReadDTOS> CreateCommand(CommandCreateDTO commandCreateDTO)
        {
            var command = _mapper.Map <Command>(commandCreateDTO);

            _repo.CreateCommand(command);
            _repo.SaveChanges();
            var commandReadDTO = _mapper.Map <CommandReadDTOS>(command);

            return(CreatedAtRoute(nameof(GetCommandById), new { Id = commandReadDTO.Id }, commandReadDTO));

            //return Ok(_mapper.Map<CommandReadDTOS>(commandReadDTO));
        }
Exemple #20
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 201 with location of created resource inside header
            return(CreatedAtRoute(nameof(GetCommandById), new { id = commandReadDto.Id }, commandReadDto));
        }
Exemple #21
0
        public ActionResult <CommandReadDto> CreateCommand(CommandCreateDto commandCreateDto)
        {
            //convert from createDto to model
            var commandModel = _mapper.Map <Command>(commandCreateDto);

            _repository.CreatCommand(commandModel);
            _repository.SaveChanges();
            //convert from model to readDto
            var commandReadModel = _mapper.Map <CommandReadDto>(commandModel);

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

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

            // can see microsoft document about CreatedAtRoute
            // Postman會回傳這Command的取得路由而且是201 status code.
            return(CreatedAtRoute(nameof(GetCommandById), new { Id = commandReadDto.Id }, commandReadDto));
            // return Ok (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);
            return(CreatedAtRoute(nameof(GetCommandById), new { Id = commandReadDto.Id }, commandReadDto));
            // createAtRute status 201 created -> header 有提供location url可用
        }
        public ActionResult <CommandReadDto> CreateCommand(CommandCreateDto commandCreateDto)
        {
            var commandModel = _mapper.Map <Command>(commandCreateDto);

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

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

            // returns a created object with status of 201 with its location in a header
            return(CreatedAtRoute(nameof(GetCommandById), new { Id = commandReadDto.Id }, commandReadDto));
            // return Ok(commandReadDto);
        }
Exemple #25
0
        public ActionResult <CommandDto> CreateCommand(CreateCommandDto dto)
        {
            var model = _map.Map <Command>(dto);

            _repo.CreateCommand(model);
            _repo.SaveChanges();

            var CmdDto = _map.Map <CommandDto>(model);

            return(CreatedAtRoute(nameof(GetCommandById), new { Id = CmdDto.Id }, CmdDto));

            //return Ok(CmdDto);
        }
Exemple #26
0
        public ActionResult <CommandReadDto> CreateCommand(CommandCreateDto commandCreateDto)
        {
            var commandModel = _mapper.Map <Command>(commandCreateDto);

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

            /* Create the new resource and pass back the location at which it is created,
             * in this case we use the GetCommandByID function for this
             */
            return(CreatedAtRoute(nameof(GetCommandById), new { Id = commandReadDto.Id }, commandReadDto));
        }
Exemple #27
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(nameof(GetCommandById), new { Id = commandReadDto.Id }, commandReadDto)); //passes back location where is was created(check postman header)

            //return Ok(commandReadDto);
        }
        public ActionResult <CommandReadDto> CreateCommand(CommandCreateDto commandCreateDto)
        {
            var commandModel = _mapper.Map <Command>(commandCreateDto);  //CommandCreateDTO -> Domain Model

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

            //Deve retorna um CommandReadDto
            var commandReadDto = _mapper.Map <CommandReadDto>(commandModel);     //Domain Model -> CommandReadDto

            //Add status 201 + Rota do GetByID
            return(CreatedAtRoute(nameof(GetCommandById), new { Id = commandReadDto.Id }, commandReadDto));
        }
        public ActionResult <CommandReadDto> CreateCommand(CommandCreateDto commandCreateDto)
        {
            Command commandModel = _mapper.Map <Command>(commandCreateDto);

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

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

            //We changed the route to use de commandReadDto and show you in header the route of the just created object
            //new {} as you may know generates new Json object
            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); //this return 200 but we need 201

            return(CreatedAtRoute(nameof(GetCommandById), new { Id = commandReadDto.Id }, commandReadDto));
        }