private static void UpdateTestInstances(BusinessFlow businessFlow, ObservableList <ActivitiesGroup> existingActivitiesGroups, QCTestSet testSet, ObservableList <ExternalItemFieldBase> testInstancesFields)
        {
            QCTestInstanceColl testInstances = ImportFromQCRest.ImportTestSetInstanceData(testSet);

            foreach (QCTestInstance testInstance in testInstances)
            {
                ActivitiesGroup ag = businessFlow.ActivitiesGroups.Where(x => (x.ExternalID == testInstance.TestId.ToString() && x.ExternalID2 == testInstance.Id.ToString())).FirstOrDefault();
                if (ag == null)
                {
                    QCRestAPIConnect.DeleteEntity(ResourceType.TEST_CYCLE, testInstance.Id);
                }
                else
                {
                    existingActivitiesGroups.Add(ag);
                    //set item fields for test instances
                    foreach (ExternalItemFieldBase field in testInstancesFields)
                    {
                        if ((field.ToUpdate || field.Mandatory) && (!(field.ExternalID == "test-id") && !(field.ExternalID == "cycle-id")))
                        {
                            if (string.IsNullOrEmpty(field.ExternalID) == false && field.SelectedValue != "NA")
                            {
                                if (testInstance.ElementsField.ContainsKey(field.ID))
                                {
                                    testInstance.ElementsField[field.ExternalID] = field.SelectedValue;
                                }
                            }
                        }
                    }

                    try
                    {
                        QCItem          item     = ConvertObjectValuesToQCItem(testInstance, ResourceType.TEST_CYCLE, true);
                        ALMResponseData response = QCRestAPIConnect.UpdateEntity(ResourceType.TEST_CYCLE, testInstance.Id, item);

                        if (response.IsSucceed)
                        {
                            testInstances.Add(QCRestAPIConnect.GetTestInstanceDetails(testInstance.Id));
                            ag.ExternalID2 = response.IdCreated;//the test case instance ID in the test set- used for exporting the execution details
                        }
                    }
                    catch (Exception ex)
                    {
                        Reporter.ToLog(eLogLevel.ERROR, $"Method - {MethodBase.GetCurrentMethod().Name}, Error - {ex.Message}");
                    }
                }
            }
        }
        private static void UpdateTestStep(QCTestCase test, ActivitiesGroup activitiesGroup, Activity identifiedActivity, ObservableList <ExternalItemFieldBase> designStepsFields, ObservableList <ExternalItemFieldBase> designStepsParamsFields)
        {
            QCTestCaseStepsColl testCaseDesignStep = QCRestAPIConnect.GetTestCasesSteps(new List <string> {
                test.Id
            });

            //delete the un-needed steps
            foreach (QCTestCaseStep step in testCaseDesignStep)
            {
                if (activitiesGroup.ActivitiesIdentifiers.Where(x => x.IdentifiedActivity.ExternalID == step.Id.ToString()).FirstOrDefault() == null)
                {
                    QCRestAPIConnect.DeleteEntity(ALM_Common.DataContracts.ResourceType.DESIGN_STEP, step.Id);
                }
            }

            //delete the existing parameters
            QCTestCaseParamsColl testCaseParams = QCRestAPIConnect.GetTestCaseParams(test.Id);

            if (testCaseParams.Count > 0)
            {
                for (int indx = 0; indx < testCaseParams.Count; indx++)
                {
                    QCRestAPIConnect.DeleteEntity(ALM_Common.DataContracts.ResourceType.DESIGN_STEP_PARAMETERS, testCaseParams[indx].Id);
                }
            }

            foreach (QCTestCaseStep step in testCaseDesignStep)
            {
                //set item fields
                foreach (ExternalItemFieldBase field in designStepsFields)
                {
                    if (field.ToUpdate || field.Mandatory)
                    {
                        if (string.IsNullOrEmpty(field.SelectedValue) == false && field.SelectedValue != "NA")
                        {
                            if (step.ElementsField.ContainsKey(field.ExternalID))
                            {
                                step.ElementsField[field.ExternalID] = field.SelectedValue;
                            }
                        }
                    }
                }

                step.ElementsField["name"] = identifiedActivity.ActivityName;
                string descriptionTemplate =
                    "<html><body><div align=\"left\"><font face=\"Arial\"><span style=\"font-size:8pt\"><<&Description&&>><br /><<&Parameters&>><br /><<&Actions&>></span></font></div></body></html>";
                string description = descriptionTemplate.Replace("<<&Description&&>>", identifiedActivity.Description);

                QCTestCaseParamsColl testParams = QCRestAPIConnect.GetTestCaseParams(test.Id);
                string paramsSigns = string.Empty;
                if (identifiedActivity.Variables.Count > 0)
                {
                    paramsSigns = "<br />Parameters:<br />";
                    foreach (VariableBase var in identifiedActivity.Variables)
                    {
                        paramsSigns += "&lt;&lt;&lt;" + var.Name.ToLower() + "&gt;&gt;&gt;<br />";
                        //try to add the paramter to the test case parameters list
                        try
                        {
                            QCTestCaseParam newParam = new QCTestCaseParam();

                            //set item fields
                            foreach (ExternalItemFieldBase field in designStepsParamsFields)
                            {
                                if (field.ToUpdate || field.Mandatory)
                                {
                                    if (string.IsNullOrEmpty(field.SelectedValue) == false && field.SelectedValue != "NA")
                                    {
                                        newParam.ElementsField.Add(field.ExternalID, field.SelectedValue);
                                    }
                                    else
                                    {
                                        try { newParam.ElementsField.Add(field.ExternalID, "NA"); }
                                        catch { }
                                    }
                                }
                            }

                            newParam.Name   = var.Name.ToLower();
                            newParam.TestId = test.Id;

                            QCItem itemTestCaseParam = ConvertObjectValuesToQCItem(newParam, ResourceType.TEST_CASE_PARAMETERS);
                            QCRestAPIConnect.CreateNewEntity(ResourceType.TEST_CASE_PARAMETERS, itemTestCaseParam);
                        }
                        catch (Exception ex) { Reporter.ToLog(eLogLevel.ERROR, $"Method - {MethodBase.GetCurrentMethod().Name}, Error - {ex.Message}"); }
                    }
                }

                description = description.Replace("<<&Parameters&>>", paramsSigns);

                string actsDesc = string.Empty;
                if (identifiedActivity.Acts.Count > 0)
                {
                    actsDesc = "Actions:<br />";
                    foreach (Act act in identifiedActivity.Acts)
                    {
                        actsDesc += act.Description + "<br />";
                    }
                }
                description      = description.Replace("<<&Actions&>>", actsDesc);
                step.Description = description;
                step.ElementsField["expected"] = identifiedActivity.Expected;

                QCItem          itemDesignStep = ConvertObjectValuesToQCItem(step, ResourceType.DESIGN_STEP, true);
                ALMResponseData response       = QCRestAPIConnect.UpdateEntity(ResourceType.DESIGN_STEP, step.Id, itemDesignStep);

                identifiedActivity.ExternalID = step.Id;
            }
        }