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));
        }
Example #2
0
        public ActionResult <CommandCreateDto> 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));
        }
Example #3
0
        public ActionResult <CommandCreateDto> CreateCommand(CommandCreateDto commandCreateDto)
        {
            var commandItem = _mapper.Map <Command>(commandCreateDto);

            _commanderRepo.CreateCommand(commandItem);
            _commanderRepo.SaveChanges();
            var commandReadDto = _mapper.Map <CommandReadDto>(commandItem);

            return(CreatedAtRoute(nameof(GetCommandById), new { Id = commandReadDto.Id }, commandReadDto));
            //return Ok(commandItem);
        }
Example #4
0
        public ActionResult <CommandReadDto> CreateCommand(CommandCreateDto cmd)
        {
            Command command = _mapper.Map <Command>(cmd);

            _repository.CreateCommand(command);
            _repository.SaveChanges();

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

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

            _repo.Create(cmdModel);
            _repo.Savechanges();

            var cmdCreateDto = _mapper.Map <CommandReadDto>(cmdModel);

            return(CreatedAtRoute(nameof(GetCommandById), new { id = cmdModel.Id }, cmdCreateDto));
        }
        public ActionResult <CommandReadDto> CreateCommand(CommandCreateDto command)
        {
            var writeCommand = _mapper.Map <Command>(command);

            _commanderRepo.CreateCommand(writeCommand);
            _commanderRepo.SaveChanges();

            var readCommand = _mapper.Map <CommandReadDto>(writeCommand);

            return(CreatedAtRoute(nameof(GetCommandById), new { Id = readCommand.Id }, readCommand));
        }
        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));
        }
        public ActionResult<CommandReadDto> CreateCommand(CommandCreateDto commandCreateDto) //It is CommandReadDto because as a respond of POST method is exactly that dto
        {
            var model = _mapper.Map<Command>(commandCreateDto);
            _repository.CreateCommand(model);
            _repository.SaveChanges();

            var commandReadDto = _mapper.Map<CommandReadDto>(model);    //It;s made for return a response to client as a CommandReadDto to maintain contract - response as a location

            return CreatedAtRoute(nameof(GetCommandById), new { Id = commandReadDto.Id }, commandReadDto);    /* https://docs.microsoft.com/en-us/dotnet/api/system.web.http.apicontroller.createdatroute?view=aspnetcore-2.2 */
            //return Ok(commandReadDto);
        }
        public async Task <ActionResult <CommandReadDto> > CreateCommandAsync(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));
            //return Ok(commandReadDto);
        }
Example #10
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));
        }
Example #11
0
        public ActionResult <CommandReadDto> CreateCommand(CommandCreateDto commandCreateDto)
        {
            var commandModel = _mapper.Map <Command>(commandCreateDto);                                     //Map from dto to model

            _repository.CreateCommand(commandModel);                                                        //First you have to map the DTO and then you call the DB create method
            _repository.SaveChanges();                                                                      //Commit your changes

            var commandReadDto = _mapper.Map <CommandReadDto>(commandModel);                                //Map it back to DTO to respond to client

            return(CreatedAtRoute(nameof(GetCommandById), new { Id = commandReadDto.Id }, commandReadDto)); //It finds the created object in order to manipulate the reponse code
        }
Example #12
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));
        }
Example #13
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));
        }
Example #14
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));
        }
Example #15
0
        public ActionResult <CommandReadDto> CreateCommand(CommandCreateDto commandCreateDto)
        {
            var commandModel = _mapper.Map <Command>(commandCreateDto);

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

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

            // Returns 201 Created and specifies location attribute in header
            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);

            // 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));
        }
Example #17
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));
        }
        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
        }
Example #19
0
        public ActionResult <CommandReadDto> CreateCommands(CommandCreateDto cmdCreateDto)
        {
            var createModel = _mapper.Map <Command>(cmdCreateDto);

            _command.CreateCommand(createModel);
            _command.SaveChanges();

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

            return(CreatedAtRoute(nameof(GetCommandById), new { id = commandReadDto.Id }, commandReadDto));
            //return Ok(commandModel);
        }
        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);
        }
Example #21
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));
        }
Example #22
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));
        }
Example #23
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 commandCreateDto)
        {
            var commandModel = _mapper.Map <Command>(commandCreateDto);

            _repoistory.CreateCommand(commandModel);

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

            return(CreatedAtRoute(
                       "getCommandById", new { id = commandRead.Id }, commandRead
                       ));
        }
Example #25
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));
        }
Example #26
0
        public ActionResult <CommandReadDto> CreateCommand(CommandCreateDto cmd)
        {
            var commandItem = _mapper.Map <Command>(cmd);

            _repository.CreateCommand(commandItem);
            if (_repository.dbSaveChanges())
            {
                var cmdReadDto = _mapper.Map <CommandReadDto>(commandItem);
                return(CreatedAtRoute(nameof(GetCommandById), new { id = cmdReadDto.id }, cmdReadDto));
            }
            return(NotFound());
        }
Example #27
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));
        }
Example #28
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));
        }
Example #29
0
        public ActionResult <CommandCreateDto> CreateCommand(CommandCreateDto commandCreateDto) // not Command cmd? worth noting
        {                                                                                       // we want to map to the object (Command), and the source is 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)); // 201 Created, it gives full url to the file
                                                                                                            // to check this stuff checkout docs.microsoft.net about ApiController.CreatedAtRoute
                                                                                                            //    return Ok(commandReadDto); // not final
        }
Example #30
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));
        }