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());
            }
        }
Exemple #2
0
        /// <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;
                    }
                }
            }
        }
Exemple #3
0
        /// <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);
            }
        }
Exemple #4
0
        /// <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--;
                    }
                }
            }
        }