public async Task <IActionResult> Patch([FromBody] PatchInstructions data, string id) { if (data == null) { return(NoContent()); } string operation = data.op; string path = data.path; string value = data.value; bool retVal = false; if (path != null) { if (operation.Equals("replace")) { retVal = await questionManager.UpdateQuestionAnswerAsync(value, id); } else { return(BadRequest()); } } if (retVal == true) { return(Ok()); } else { return(BadRequest()); } }
/// <summary> /// Adds or replace an instruction. If instruction order already exists, corresponding instruction is replaced; else specified instruction is added to the list. /// </summary> /// <param name="instruction">Instruction to set</param> public void SetInstruction(PatchInstruction instruction) { if (instruction == null || instruction.Order < 1) { return; } // Unsupported parameters are removed instruction.RemoveUnsupportedParameters(); if (instruction.Order > PatchInstructions.Count) { // Add mode PatchInstructions.Add(instruction); } else { // Replace mode for (int i = 0; i < PatchInstructions.Count; i++) { PatchInstruction currentInstruction = PatchInstructions[i]; if (currentInstruction.Order == instruction.Order) { PatchInstructions[i] = instruction; break; } } } }
/// <summary> /// Import specified instruction to current patch /// </summary> /// <param name="anotherInstruction"></param> public void ImportInstruction(PatchInstruction anotherInstruction) { if (anotherInstruction != null) { anotherInstruction.Order = PatchInstructions.Count + 1; PatchInstructions.Add(anotherInstruction); } }
/// <summary> /// Deletes an instruction at specified order /// </summary> /// <param name="order">Instruction order</param> public void DeleteInstructionAt(int order) { if (order > PatchInstructions.Count) { return; } // Retrieving instruction & deletion PatchInstruction instructionToDelete = GetInstruction(order); if (instructionToDelete != null) { PatchInstructions.Remove(instructionToDelete); // Updating order of following instructions foreach (PatchInstruction anotherInstruction in _PatchInstructions) { if (anotherInstruction.Order > order) { anotherInstruction.Order--; } } } }