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());
        }
        public ActionResult partialCommandUpdate(int id, JsonPatchDocument <CommandUpdateDTO> patchDocument)
        {
            Command commandFromRepo = _repository.GetCommandByID(id);

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

            CommandUpdateDTO commandToPatch = _mapper.Map <CommandUpdateDTO>(commandFromRepo);

            patchDocument.ApplyTo(commandToPatch, ModelState);

            if (!TryValidateModel(commandToPatch))
            {
                return(ValidationProblem(ModelState));
            }

            _mapper.Map(commandToPatch, commandFromRepo);

            _repository.UpdateCommand(commandFromRepo);

            _repository.saveChanges();

            return(NoContent());
        }
        public ActionResult UpdateCommand(int id, CommandUpdateDTO commandUpdateDTO)
        {
            var commandModelFromRepo = _repository.GetCommandById(id);

            if (commandModelFromRepo == null)
            {
                return(NotFound());
            }
            _mapper.Map(commandUpdateDTO, commandModelFromRepo);
            _repository.UpdateCommand(commandModelFromRepo);
            _repository.SaveChanges();
            return(NoContent());
        }
        public ActionResult UpdateCommand(int id, CommandUpdateDTO commandUpdateDTO)
        {
            Command foundCommand = repository.GetCommandById(id);

            if (foundCommand == null)
            {
                return(NotFound());
            }
            mapper.Map(commandUpdateDTO, foundCommand);
            repository.UpdateCommand(foundCommand);
            repository.SaveChanges();
            return(NoContent());
        }
Beispiel #5
0
        public ActionResult UpdateCommand(int id, CommandUpdateDTO commandUpdateDTO)
        {
            var commandItem = Repository.GetCommandBy(id);

            if (commandItem == null)
            {
                return(NotFound());
            }
            var commandModel = Mapper.Map(commandUpdateDTO, commandItem);

            Repository.UpdateCommand(commandItem);
            Repository.SaveChanges();

            return(NoContent());
        }
Beispiel #6
0
        public ActionResult <CommandReadDTO> UpdateCommand(int id, CommandUpdateDTO updateCommand)
        {
            var command = _repo.GetCommandById(id);

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

            _mapper.Map(updateCommand, command);
            _repo.UpdateCommand(command);
            _repo.SaveChanges();

            return(Ok(_mapper.Map <CommandReadDTO>(command)));
        }
Beispiel #7
0
        public ActionResult UpdateCommand(int id, CommandUpdateDTO commandUpdate)
        {
            var commandModelFromRepo = _ICommand.GetCommandById(id);

            if (commandModelFromRepo == null)
            {
                return(NotFound()); // 404 Not found
            }

            _mapper.Map(commandUpdate, commandModelFromRepo);
            _ICommand.UpdateCommand(commandModelFromRepo);
            _ICommand.SaveChanges();

            return(NoContent()); // 204 No Content Success
        }
Beispiel #8
0
        public ActionResult UpdateCommand(int id, CommandUpdateDTO command)
        {
            var commandFromRepo = _repo.GetCommandById(id);

            if (commandFromRepo == null)
            {
                return(NotFound());
            }
            //       map source,   destination
            _mapper.Map(command, commandFromRepo);
            _repo.UpdateCommand(commandFromRepo);
            _repo.SaveChanges();

            return(NoContent());
        }
        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());
        }
        [HttpPut("{id}")] //Put api/command/{id}
        public ActionResult <CommandUpdateDTO> UpdateCommand(int id, CommandUpdateDTO commandUpdateDTO)
        {
            // Checks to see if command is found
            Command commandModelRepo = _repo.GetCommandById(id);

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

            _mapper.Map(commandUpdateDTO, commandModelRepo);
            _repo.UpdateCommand(commandModelRepo);
            _repo.SaveChanges();

            return(NoContent());
        }
        public ActionResult updateCommand(int id, CommandUpdateDTO commandUpdate)
        {
            Command commandFromRepo = _repository.GetCommandByID(id);

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

            _mapper.Map(commandUpdate, commandFromRepo);

            _repository.UpdateCommand(commandFromRepo);

            _repository.saveChanges();

            return(NoContent());
        }
Beispiel #12
0
        public ActionResult <CommandReadDTO> UpdateCommand(int id, CommandUpdateDTO commandUpdateDTO)
        {
            var commandModelFromRepo = _repository.GetCommandById(id);

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

            _mapper.Map(commandUpdateDTO, commandModelFromRepo);    //updates commandModelFromRepo with content dial 1st param

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

            return(NoContent());

            // Response : OK
        }
        public async Task <ActionResult> UpdateCommand(int id, CommandUpdateDTO cmdUpdateDTO)
        {
            var commandToUpdate = await _db.GetCommandByIdAsync(id);

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

            //takes care of updating- hence empty interface implementation
            _mapper.Map(cmdUpdateDTO, commandToUpdate);

            //just in case later in future you need more specific update implementation
            await _db.UpdateCommandAsync(commandToUpdate);

            await _db.SaveChangesAsync();

            return(NoContent());
        }
        public ActionResult UpdateCommand(int id, CommandUpdateDTO pCommand)
        {
            var commandModel = _context.GetCommandById(id);

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

            _mapper.Map(pCommand, commandModel);

            _context.UpdateCommand(commandModel);

            _context.SaveChanges();

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

            return(CreatedAtRoute(nameof(GetCommandById), new { Id = commandReadDTO.Id }, commandReadDTO));
        }
        public ActionResult <CommandReadDTO> UpdateCommand(int id, CommandUpdateDTO commandUpdateDTO)
        {
            var commandModelIFromRepo = _repository.GetCommandById(id);

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

            _mapper.Map(commandUpdateDTO, commandModelIFromRepo);

            _repository.UpdateCommand(commandModelIFromRepo);

            _repository.SaveChanges();

            return(NoContent());
            //return CreatedAtRoute(nameof(GetCommandById), new { Id = commandReadDTO.Id }, commandReadDTO);
            //return Ok(commandReadDTO);
        }
        [HttpPatch("{id}")] //Patch api/commands/{id}
        public ActionResult PartialCommandUpdate(int id, JsonPatchDocument <CommandUpdateDTO> jsonPatchDoc)
        {
            Command commandModelRepo = _repo.GetCommandById(id);

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

            CommandUpdateDTO commandToPatch = _mapper.Map <CommandUpdateDTO>(commandModelRepo); // new C.U.DTO to our command repo and into commandPatch

            jsonPatchDoc.ApplyTo(commandToPatch, ModelState);
            if (!TryValidateModel(commandToPatch))
            {
                return(ValidationProblem(ModelState));     // Validation
            }
            _mapper.Map(commandToPatch, commandModelRepo); // update command patch to our repo
            _repo.UpdateCommand(commandModelRepo);
            _repo.SaveChanges();

            return(NoContent());
        }
Beispiel #17
0
        public ActionResult <CommandReadDTO> Put(Guid id, [FromBody] CommandUpdateDTO updateCommand)
        {
            if (updateCommand == null)
            {
                return(BadRequest());
            }
            if (!ModelState.IsValid)
            {
                return(UnprocessableEntity());
            }
            var commandDb = repositoryWrapper.Command.GetByCondition(c => c.Id.Equals(id), false).FirstOrDefault();

            if (commandDb == null)
            {
                return(NotFound());
            }
            mapper.Map(updateCommand, commandDb);
            repositoryWrapper.Command.Update(commandDb);
            var result = repositoryWrapper.Save();

            return(NoContent());
        }
        public ActionResult PartialUpdateCommand(int id, JsonPatchDocument <CommandUpdateDTO> patchDocument)
        {
            Command foundCommand = repository.GetCommandById(id);

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

            CommandUpdateDTO commandToPatch = mapper.Map <CommandUpdateDTO>(foundCommand);

            patchDocument.ApplyTo(commandToPatch, ModelState);

            if (TryValidateModel(patchDocument))
            {
                return(ValidationProblem(ModelState));
            }
            mapper.Map(commandToPatch, foundCommand);
            repository.UpdateCommand(foundCommand);
            repository.SaveChanges();
            return(NoContent());
        }
        public async Task <IActionResult> PutCommand(int id, CommandUpdateDTO commandUpdateDTO)
        {
            //if (id != command.ID)
            //{
            //    return BadRequest();
            //}

            var command = _context.Commands.FirstOrDefault(c => c.ID == id);

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

            _mapper.Map(commandUpdateDTO, command);

            _context.Entry(command).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!CommandExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(CreatedAtAction(nameof(GetCommand), new { command.ID }, command));
        }