Skip to content
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Simplified IF Statements
  • Loading branch information
Darkace01 committed Oct 25, 2020
commit 7d6821fd0492b4f1eec8d4054c2e640716289f07
11 changes: 0 additions & 11 deletions Controllers/CommandsController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,7 @@ public ActionResult<CommandReadDto> GetCommandById(int id)
{
var commandItem = _repository.GetCommandById(id);
if (commandItem != null)
{
return Ok(_mapper.Map<CommandReadDto>(commandItem));
}
return NotFound();
}

Expand All @@ -62,9 +60,7 @@ public ActionResult UpdateCommand(int id, CommandUpdateDto commandUpdateDto)
{
var commandModelFromRepo = _repository.GetCommandById(id);
if (commandModelFromRepo == null)
{
return NotFound();
}
_mapper.Map(commandUpdateDto, commandModelFromRepo);

_repository.UpdateCommand(commandModelFromRepo);
Expand All @@ -77,17 +73,12 @@ public ActionResult PartialCommandUpdate(int id, JsonPatchDocument<CommandUpdate
{
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);

Expand All @@ -102,9 +93,7 @@ public ActionResult DeleteCommand(int id)
{
var commandModelFromRepo = _repository.GetCommandById(id);
if (commandModelFromRepo == null)
{
return NotFound();
}
_repository.DeleteCommand(commandModelFromRepo);

return NoContent();
Expand Down