コード例 #1
0
        public ActionResult <CommandUpdateDTO> PutMethodById(int id, CommandUpdateDTO newcmd)
        {
            var commandsItem = _repository.GetCommandById(id);

            if (commandsItem != null)
            {
                var newDTO = _mapper.Map <Command>(newcmd);
                _repository.UpdateCommand(id, newDTO);
                if (_repository.SaveChanges())
                {
                    // return Ok();
                    var returnObj = _mapper.Map <CommandReadDTO>(newDTO);
                    returnObj.Id = id;
                    //return Ok(returnObj);
                    return(CreatedAtRoute(nameof(GetCommandById), new { Id = returnObj.Id }, returnObj));
                }
                throw new System.ArgumentException("Save Failed", "original");
            }

            /*Option 2:
             * _mapper.Map(newcmd, commandsItem);
             * _repository.UpdateCommand(commandsItem);
             * _repository.SaveChanges();
             */
            return(NotFound());
        }
コード例 #2
0
        public ActionResult UpdateCommand(int id, CommandUpdateDto commandUpdateDto)
        {
            // Check if command exists
            var commandModelFromRepo = _repository.GetCommandById(id);

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

            // Here, we have CommandUpdateDto that has data and
            // CommandModel from repo that has data
            _mapper.Map(commandUpdateDto, commandModelFromRepo);

            // In the interest of maintainig a separate interface from
            // implementation, this is good practice...
            // but it isn't really needed because of the way Entity Framework
            // works
            _repository.UpdateCommand(commandModelFromRepo);

            // Save changes
            _repository.SaveChanges();

            // Return 204 Status
            return(NoContent());
        }
コード例 #3
0
        public ActionResult UpdateCommand(int id, CommandUpdateDto commandUpdateDto)
        {
            if (commandUpdateDto == null)
            {
                return(NotFound());
            }
            if (!ModelState.IsValid)
            {
                return(ValidationProblem(ModelState));
            }

            var commandModelFromRepo = _repository.GetCommandById(id);

            if (commandModelFromRepo == null)
            {
                return(NotFound());
            }
            _mapper.Map(commandUpdateDto, commandModelFromRepo);

            _repository.UpdateCommand(commandModelFromRepo);

            _repository.SaveChanges();

            return(NoContent());
        }
コード例 #4
0
        public ActionResult <CommandRest> UpdateCommand(int id, CommandParams command)
        {
            var commandModel = _repository.GetCommandById(id);

            _mapper.Map(command, commandModel);
            _repository.UpdateCommand(id, commandModel);
            return(NoContent());
        }
コード例 #5
0
        public ActionResult UdateCommand(int id, CommandUpdateDto commandUpdateDto)
        {
            var commandModelFromRepo = ReturnCommandIsValueNotNull(id).Value;

            _mapper.Map(commandUpdateDto, commandModelFromRepo);

            _repository.UpdateCommand(commandModelFromRepo);

            _repository.SaveChanges();

            return(NoContent());
        }
コード例 #6
0
        public ActionResult UpdateCommand(int id, CommandUpdateDto commandUpdateDto)
        {
            var commandModalFromRepo = _repository.GetCommandById(id);

            if (commandModalFromRepo == null)
            {
                return(NotFound());
            }
            _mapper.Map(commandUpdateDto, commandModalFromRepo);
            _repository.UpdateCommand(commandModalFromRepo);
            _repository.SaveChanges();
            return(NoContent());
        }
コード例 #7
0
        public ActionResult <CommandReadDto> UpdateCommand(int id, CommandUpdateDto commandUpdateDto)
        {
            var commandFromRepo = _repository.GetCommnadById(id);

            if (commandFromRepo == null)
            {
                return(NotFound());
            }
            _mapper.Map(commandUpdateDto, commandFromRepo);
            _repository.UpdateCommand(commandFromRepo);
            _repository.saveChganges();
            return(NoContent());
        }
コード例 #8
0
        public ActionResult UpdateCommand(int id, CommandUpdateDto command)
        {
            var commandItem = _commanderRepo.GetCommandById(id);

            if (commandItem == null)
            {
                return(NotFound());
            }
            _mapper.Map(command, commandItem);
            _commanderRepo.UpdateCommand(commandItem);
            _commanderRepo.SaveChanges();
            return(NoContent());
        }
コード例 #9
0
        public ActionResult UpdateCommand(int id, CommandUpdateDto commandUpdateDto)
        {
            if (!TryGetCommand(id, out var commandModelFromRepo))
            {
                return(NotFound());
            }

            _mapper.Map(commandUpdateDto, commandModelFromRepo);

            _repository.UpdateCommand(commandModelFromRepo);
            _repository.SaveChanges();

            return(NoContent());
        }
コード例 #10
0
ファイル: CommandsController.cs プロジェクト: PwL95/WebApi
        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());
        }
コード例 #11
0
        public ActionResult <CommandReadDto> UpdateCommand(int id, CommandUpdateDto objCommandUpdateDto)
        {
            var objCommandItem = _reporsitory.GetCommandById(id);

            if (objCommandItem == null)
            {
                return(NotFound());
            }
            _mapper.Map(objCommandUpdateDto, objCommandItem);
            _reporsitory.UpdateCommand(objCommandItem);
            _reporsitory.SaveChanges();

            return(NoContent());
        }
コード例 #12
0
        public ActionResult UpdateCommand(int id, CommanderUpdateDto cmd)
        {
            var commandModelFromRepo = _repo.GetCommandById(id);

            if (commandModelFromRepo == null)
            {
                return(NotFound());
            }
            _mapper.Map(cmd, commandModelFromRepo);
            _repo.UpdateCommand(commandModelFromRepo);
            _repo.SaveChanges();

            return(NotFound());
        }
コード例 #13
0
        public ActionResult UpdateCommand([FromRoute] int id, [FromBody] CommandUpdateDto cmd)
        {
            Command commandModel = _repo.GetCommandById(id);

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

            _mapper.Map(cmd, commandModel);
            _repo.UpdateCommand(commandModel);
            _repo.SaveChanges();

            return(NoContent());
        }
コード例 #14
0
        public ActionResult UpdateCommand(int id, CommandUpdateDto commandUpdateDto)
        {
            var commandModelFromRepo = _repository.GetCommandById(id);

            if (commandModelFromRepo == null)
            {
                return(NotFound());
            }
            _mapper.Map(commandUpdateDto, commandModelFromRepo); // this does the update

            _repository.UpdateCommand(commandModelFromRepo);     // not really needed, good practice though
            _repository.SaveChanges();

            return(NoContent());
        }
コード例 #15
0
        public ActionResult UpdateCommand(int id, CommandUpdateDto commandUpdate)
        {
            var command = _repo.GetCommandById(id);

            if (command is null)
            {
                return(NotFound());
            }
            _mapper.Map(commandUpdate, command);

            _repo.UpdateCommand(command);
            _repo.SaveChanges();

            return(NoContent());
        }
コード例 #16
0
        public ActionResult UpdateCommand(int id, CommandUpdateDto command)
        {
            var existing = Repository.GetCommandById(id);

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

            Mapper.Map(command, existing);
            Repository.UpdateCommand(existing);
            Repository.SaveChanges();

            return(NoContent());
        }
コード例 #17
0
        public ActionResult UpdateCommand(int id, CommandUpdateDTO commandUpdateDTO)
        {
            var commandFromRepo = _repo.GetCommandById(id);

            if (commandFromRepo == null)
            {
                return(NotFound());
            }
            _mapper.Map(commandUpdateDTO, commandFromRepo);
            _repo.UpdateCommand(commandFromRepo);

            _repo.SaveChanges();

            return(NoContent());
        }
コード例 #18
0
        public ActionResult UpdateCommand(int id, CommandUpdateDto commandUpdateDto)
        {
            var commandModelFromService = _commanderService.GetCommandById(id);

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

            _mapper.Map(commandUpdateDto, commandModelFromService);
            _commanderService.UpdateCommand(commandModelFromService);
            _commanderService.SaveChanges();

            return(NoContent());
        }
コード例 #19
0
        public ActionResult <CommandReadDto> UpdateCommand(int id, CommandUpdateDto commandUpdateDto)
        {
            var commandModelFromRepo = _repository.GetCommandById(id);

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

            _mapper.Map(commandUpdateDto, commandModelFromRepo);         //entity framework knows that there was a change in the command model object
            _repository.UpdateCommand(commandModelFromRepo);             //Doing nothing due to the EF possibilities
            _repository.SaveChanges();

            return(NoContent());
        }
コード例 #20
0
ファイル: Commands.cs プロジェクト: Jasio182/Commander
        public ActionResult UpdateCommand(int id, CommandUpdateDto commandUpdateDto)
        {
            var commandModelFromRepo = _repository.GetCommandById(id);

            if (commandModelFromRepo == null)
            {
                return(NotFound());
            }
            // Both commandUpdateDto and commandModelFromRepo already have data.
            // Mapper inserts data from commandUpdateDto to commandModelFromRepo
            _mapper.Map(commandUpdateDto, commandModelFromRepo);
            _repository.UpdateCommand(commandModelFromRepo);
            _repository.SaveChanges();
            return(NoContent());
        }
コード例 #21
0
        public async Task <ActionResult> UpdateCommand(int id, CommandUpdateDto cmd)
        {
            var commandFromRepo = await _repo.GetCommandById(id);

            if (commandFromRepo == null)
            {
                return(NotFound(new ApiResponse(404)));
            }

            // TODO: Fix mapping
            commandFromRepo.Task = cmd.Task;
            commandFromRepo.Instructions.Description = cmd.Instructions;
            commandFromRepo.Platform.Id   = cmd.PlatformId;
            commandFromRepo.Platform.Name = cmd.PlatformName;

            // _mapper.Map(cmd, commandFromRepo);

            _repo.UpdateCommand(commandFromRepo);

            if (!await _repo.SaveChanges())
            {
                return(BadRequest(new ApiResponse(409, "Resource could not be updated.")));
            }

            return(NoContent());
        }
コード例 #22
0
        public ActionResult UpdateCommand(int id, CommandUpdateDTO commandUpdateDTO)
        {
            var commandModelFromRepo = _repository.GetCommandById(id);

            if (commandModelFromRepo == null)
            {
                return(NotFound());
            }
            _mapper.Map(commandUpdateDTO, commandModelFromRepo);

            _repository.UpdateCommand(commandModelFromRepo); // not doing anthing currently, for future if EF is swapped for somethign else

            _repository.SaveChanges();

            return(NoContent());
        }
コード例 #23
0
        public ActionResult UpdateCommand(int id, CommandUpdateDto commandUpdateDto)
        {
            var commandModelFromRepo = _repository.GetCommandById(id);
            if(commandModelFromRepo == null)
            {
                return NotFound();
            }

            _mapper.Map(commandUpdateDto, commandModelFromRepo);    //!!!Different syntax, because both of these classes has data (existing model)

            _repository.UpdateCommand(commandModelFromRepo);

            _repository.SaveChanges();

            return NoContent();
        }
コード例 #24
0
        public ActionResult UpdateCommand(int id, CommandCreateDTO commandUpdateDTO)
        {
            var commandModelFromRepo = repository.GetCommandById(id);

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

            mapper.Map(commandUpdateDTO, commandModelFromRepo);

            repository.UpdateCommand(commandModelFromRepo);
            repository.SaveChanges();

            return(NoContent());
        }
コード例 #25
0
        public ActionResult UpdateCommand(int id, CommandUpdateDto commandUpdateDto)
        {
            var commandModelFromRepo = _repository.GetCommandById(id);

            if (commandModelFromRepo == null)
            {
                return(NotFound());  //returns 404 Not Found if command id does not exist
            }
            _mapper.Map(commandUpdateDto, commandModelFromRepo);

            _repository.UpdateCommand(commandModelFromRepo);

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

            return(NoContent());       //returns 204 response
        }
コード例 #26
0
        public ActionResult UpdateCommand(int id, UpdateCommandDto dto)
        {
            var modelFromRepo = _repo.GetCommandById(id);

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

            _map.Map(dto, modelFromRepo);

            _repo.UpdateCommand(modelFromRepo);
            _repo.SaveChanges();

            return(NoContent());
        }
コード例 #27
0
        public ActionResult UpdateCommand(int id, CommandUpdateDto commandUpdateDto)
        {
            var commandFromRepo = _commanderRepo.GetCommandById(id);

            if (commandFromRepo == null)
            {
                return(NotFound());
            }
            _mapper.Map(commandUpdateDto, commandFromRepo);// this syntax because both has data present, previously only source data was available
            //this already upadated our model so no needed implementation in SqlCommanderRepo
            _commanderRepo.UpdateCommand(commandFromRepo);

            _commanderRepo.SaveChanges();

            return(NoContent());
        }
コード例 #28
0
        public ActionResult UpdateCommand(int id, CommandUpdateDto cmd)
        {
            var commandModelFromRepo = _repo.GetCommandById(id);

            if (commandModelFromRepo == null)
            {
                return(NotFound());
            }
            _mapper.Map(cmd, commandModelFromRepo); //commandModelFromRepo would be updated, we don't need to call to an update method

            _repo.UpdateCommand(commandModelFromRepo);

            _repo.SaveChanges();

            return(NoContent());
        }
コード例 #29
0
        public ActionResult updateCommand(int id, CommandUpdateDto commandUpdateDto)
        {
            var commandModelFromRepo = _repository.GetCommandById(id);

            if (commandModelFromRepo == null)
            {
                return(NotFound());
            }
            _mapper.Map(commandUpdateDto, commandModelFromRepo);

            _repository.UpdateCommand(commandModelFromRepo); //dont do anything its just for implementation

            _repository.SaveChanges();

            return(NoContent());
        }
コード例 #30
0
        public ActionResult UpdateCommand(int id, CommandUpdateDto commandUpdateDto)
        {
            var commandModelFromRepo = _repository.GetCommandById(id);

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

            //The following is basicly, overriding commandModelFromRepo with commandUpdateDto
            _mapper.Map(commandUpdateDto, commandModelFromRepo);
            _repository.UpdateCommand(commandModelFromRepo);
            _repository.SaveChanges();

            return(NoContent());
        }