Ejemplo n.º 1
0
        public async Task <ActionResult <CommandReadDto> > CreateCommand(CommandWriteDto command, CancellationToken cancellationToken)
        {
            var commandModel = _mapper.Map <Command>(command);
            await _repository.CreateCommand(commandModel, cancellationToken).ConfigureAwait(false);

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

            //CreatedAtRoute returns URI of created value. ie api/commands/{id}
            return(CreatedAtRoute(nameof(GetCommandById), new { Id = commandResult.Id }, commandResult));
        }
        public ActionResult <CommandReadDto> CreateCommand(CommandWriteDto command)
        {
            var commandModel = _mapper.Map <Command>(command);

            _repo.CreateCommad(commandModel);
            _repo.saveChanges();

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

            /*if (commandItem == null) return NotFound();*/
            return(CreatedAtRoute(nameof(GelCommandById), new { Id = commandReadDto.Id }, commandReadDto));
        }
Ejemplo n.º 3
0
        public ActionResult <CommandReadDto> CreateCommand(CommandWriteDto command)
        {
            var commandModel = mapper.Map <Command>(command);

            repository.CreateCommand(commandModel);

            repository.SaveChanges();

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

            return(CreatedAtRoute(nameof(GetCommandById), new { Id = commanderReadDto.Id }, commanderReadDto));
        }
Ejemplo n.º 4
0
 public ActionResult <CommandReadDto> CreateCommand(CommandWriteDto commandWriteDto)
 {
     if (commandWriteDto != null)
     {
         var command = _mapper.Map <Command>(commandWriteDto);
         _repo.CreateCommand(command);
         _repo.SaveChange();
         var commandReadDto = _mapper.Map <CommandReadDto>(command);
         return(CreatedAtRoute(nameof(GetCommandById), new { Id = commandReadDto.Id }, commandReadDto));
     }
     return(NotFound());
 }
Ejemplo n.º 5
0
        public async Task <ActionResult> UpdateCommand(int id, CommandWriteDto commandDto, CancellationToken cancellationToken)
        {
            var command = await _repository.GetCommandById(id, cancellationToken).ConfigureAwait(false);

            if (command == null)
            {
                return(NotFound());
            }
            _mapper.Map(commandDto, command);

            await _repository.UpdateCommand(command, cancellationToken);

            return(NoContent());
        }
        public ActionResult <CommandReadDto> UpdateCommand(int id, CommandWriteDto commandWriteDto)
        {
            var commandModel = _repo.GetCommandById(id);

            if (commandModel == null)
            {
                return(NotFound());
            }

            _mapper.Map(commandWriteDto, commandModel);//it updated the model in the DbContext

            //_repo.UpdateCommand(commandModel);

            _repo.saveChanges();


            return(NoContent());
        }