public ActionResult PartialCommandUpdate(int id, JsonPatchDocument <CommandUpdateDto> patchDoc) { var commandModelFromRepo = _repository.GetCommandById(id); if (commandModelFromRepo == null) { return(NotFound()); } var commandToPatch = _mapper.Map <CommandUpdateDto>(commandModelFromRepo); patchDoc.ApplyTo(commandToPatch, ModelState); if (!TryValidateModel(commandToPatch)) { return(ValidationProblem(ModelState)); } _mapper.Map(commandToPatch, commandModelFromRepo); _repository.UpdateCommand(commandModelFromRepo); _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 cmdUpdateDto) { var modelCommand = _repository.GetCommandById(id); if (modelCommand == null) { return(NotFound()); } _mapper.Map(cmdUpdateDto, modelCommand); _repository.UpdateCommand(modelCommand); _repository.SaveChanges(); return(NoContent()); }
public ActionResult UpdateCommand(int id, CommandUpdateDto commandUpdateDto) { if (_repository.GetCommandById(id) == null) { return(NotFound()); } var commandToUpdate = _mapper.Map <Command>(commandUpdateDto); commandToUpdate.Id = id; _repository.UpdateCommand(commandToUpdate); return(NoContent()); }
public ActionResult UpdateCommand(int id, CommandUpdateDto commandUpdateDto) { var commandModelFromRepo = _repository.GetCommandById(id); if (commandModelFromRepo == null) { return(NotFound()); } _mapper.Map(commandUpdateDto, commandModelFromRepo); //copy the content passed from the request into the copy from the repository(DbContext) _repository.UpdateCommand(commandModelFromRepo); _repository.SaveChanges(); return(NoContent()); }
public ActionResult UpdateCommand(int id, CommandUpdateDto cmd) { var commandModelFromRepo = _commandAPIRepo.GetCommandById(id); if (commandModelFromRepo == null) { _logger?.LogWarn("command not found"); return(NotFound()); } _mapper.Map(cmd, commandModelFromRepo); _commandAPIRepo.UpdateCommand(commandModelFromRepo); _commandAPIRepo.SaveChanges(); return(NoContent()); }
public ActionResult UpdateCommand(int id, CommandUpdateDto command) { var commandModel = repo.GetCommandById(id); if (commandModel == null) { return(NotFound()); } mapper.Map(command, commandModel); repo.UpdateCommand(commandModel); repo.SaveChanges(); return(NoContent()); }
public ActionResult UpdateCommand(int id, CommandUpdateDto cmdUpdateDto) { var cmd = repo.GetCommandById(id); if (cmd == null) { return(NotFound()); } // cmd is a reference to the object stored in the context mapper.Map(cmdUpdateDto, cmd); // This updates the context since it updates cmd repo.UpdateCommand(cmd); repo.SaveChanges(); return(NoContent()); }
public ActionResult UpdateCommand(int id, CommandUpdateDto dto) { var existingCmd = _repo.GetCommandById(id); if (existingCmd == null) { return(NotFound()); } // modify the existing cmd in place, so doesn't return anything _mapper.Map(dto, existingCmd); _repo.UpdateCommand(existingCmd); _repo.SaveChanges(); return(NoContent()); }
public ActionResult UpdateCommand(int id, CommandUpdateDto commandUpdateDto) { var commandModelFromRepo = _repository.GetCommandById(id); if (commandModelFromRepo == null) { return(NotFound()); } // By reference the Command object is updated in the DB Context. we not converting but updating an existing object _mapper.Map(commandUpdateDto, commandModelFromRepo); _repository.UpdateCommand(commandModelFromRepo); _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); //another form of mapping _repository.UpdateCommand(commandModelFromRepo); //just kept in case you swap out the repo implementation in future _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); // does nothing here but left out incase of future i change to EF framework that requires it _repository.UpdateCommand(commandModelFromRepo); _repository.SaveChanges(); return(NoContent()); }
public ActionResult UpdateCommand(int id, CommandUpdateDto updateDto) { if (!ModelState.IsValid) { return(BadRequest()); } var commandFromRepo = _repository.GetCommandById(id); if (commandFromRepo == null) { return(NotFound()); } var commandModel = _mapper.Map(updateDto, commandFromRepo); _repository.UpdateCommand(commandFromRepo); _repository.SaveChanges(); return(NoContent()); }
public ActionResult <string> updateCommand(Command cmd, int id) { var commandModelFromRepo = _repository.GetCommandById(id); if (commandModelFromRepo == null) { return(NotFound("No record to update")); } else { var commandItem = _repository.UpdateCommand(cmd, id); return(commandItem); } }
public ActionResult UpdateCommand(int id, CommandUpdateDto commandUpdateDto) { var commandModelFromRepo = reposService.GetCommandById(id); if (commandModelFromRepo == null) { return(NotFound()); } mapper.Map(commandUpdateDto, commandModelFromRepo); reposService.UpdateCommand(commandModelFromRepo); //does nothing by EF but may be used by other implementation reposService.SaveChanges(); return(NoContent()); //empty response. //return CreatedAtRoute(nameof(GetCommandById),new {Id = commandModelFromRepo.Id}, commandModelFromRepo); }