private UPCRMRecord CreateNewRecord(
            UPCRMRecord parentRecord,
            UPCRMLinkParticipant participant,
            bool hasRequirement,
            UPMEditField requirementField,
            bool hasAcceptance,
            UPMEditField acceptanceField)
        {
            var record = UPCRMRecord.CreateNew(this.ParticipantsControl.LinkParticipantsInfoAreaId);

            if (parentRecord.IsNew && (parentRecord.Links == null || parentRecord.Links.Count == 0))
            {
                parentRecord.AddLink(new UPCRMLink(participant.LinkRecordIdentification));
            }

            this.ApplyTemplateFilterToRecord(record);
            record.AddLink(new UPCRMLink(parentRecord, -1));
            record.AddLink(new UPCRMLink(participant.LinkRecordIdentification));
            if (hasRequirement)
            {
                record.NewValueFieldId(requirementField.StringValue, participant.Context.RequirementField.FieldId);
            }

            if (hasAcceptance)
            {
                record.NewValueFieldId(acceptanceField.StringValue, participant.Context.AcceptanceField.FieldId);
            }

            return(record);
        }
        /// <summary>
        /// CRMs the records for parameters record add root.
        /// </summary>
        /// <param name="parameters">The parameters.</param>
        /// <param name="record">The record.</param>
        /// <param name="addRoot">if set to <c>true</c> [add root].</param>
        /// <returns></returns>
        public List <UPCRMRecord> CrmRecordsForParametersRecordAddRoot(Dictionary <string, object> parameters, UPCRMRecord record, bool addRoot)
        {
            List <UPCRMRecord> recordArray    = new List <UPCRMRecord>();
            UPCRMRecord        documentRecord = null;

            if (this.TemplateFilter != null)
            {
                UPConfigFilter filter = this.TemplateFilter.FilterByApplyingValueDictionary(parameters);
                if (filter != null)
                {
                    documentRecord      = UPCRMRecord.CreateNew(filter.InfoAreaId);
                    documentRecord.Mode = "NewOffline";
                    documentRecord.ApplyValuesFromTemplateFilter(filter);
                    recordArray.Add(documentRecord);
                }
            }

            if (!string.IsNullOrEmpty(this.DocumentLinkInfoAreaId) && documentRecord != null)
            {
                UPCRMRecord documentLinkRecord = UPCRMRecord.CreateNew(this.DocumentLinkInfoAreaId);
                documentLinkRecord.Mode = "NewOffline";
                UPConfigFilter filter = this.LinkTemplateFilter?.FilterByApplyingValueDictionary(parameters);
                if (filter != null)
                {
                    documentLinkRecord.ApplyValuesFromTemplateFilter(filter);
                }

                documentLinkRecord.AddLink(new UPCRMLink(record, this.RecordLinkId));
                documentLinkRecord.AddLink(new UPCRMLink(documentRecord, this.DocumentLinkLinkId));
                recordArray.Add(documentLinkRecord);
            }
            else if (string.IsNullOrEmpty(this.DocumentLinkInfoAreaId))
            {
                documentRecord?.AddLink(new UPCRMLink(record, this.RecordLinkId));
            }

            if (addRoot && recordArray.Count > 0)
            {
                recordArray.Add(record);
            }

            return(recordArray.Count > 0 ? recordArray : null);
        }
        /// <summary>
        /// Requests add as favorite.
        /// </summary>
        /// <param name="recordIdentification">The record identification.</param>
        /// <returns></returns>
        public bool RequestAddAsFavorite(string recordIdentification)
        {
            this.currentRequest = new UPOfflineRecordRequest();
            UPCRMRecord record = UPCRMRecord.CreateNew(Constants.FAVORITES_INFOAREAID);

            if (this.TemplateFilter != null)
            {
                record.ApplyValuesFromTemplateFilter(this.TemplateFilter);
            }

            record.AddLink(new UPCRMLink(recordIdentification, Constants.FAVORITES_LINKID));
            return(this.currentRequest.StartRequest(this.OfflineRequestMode, new List <UPCRMRecord> {
                record
            }, this));
        }
Exemplo n.º 4
0
        /// <summary>
        /// Method changes record variante, not having TYPE key.
        /// </summary>
        /// <returns>
        /// List of <see cref="UPCRMRecords" />.
        /// </returns>
        private List <UPCRMRecord> ChangedRecordsVrianteWithoutType()
        {
            var changedRecords = new List <UPCRMRecord>();

            for (var weekDay = 0; weekDay < weekDayArray.Length; weekDay++)
            {
                var functionValueMapping          = new Dictionary <string, object>();
                var functionValueMappingNullValue = new Dictionary <string, object>();
                var changedRecord = (UPCRMRecord)null;
                var weekDayU7     = weekDayArray[weekDay];
                if (weekDayU7 > 1)
                {
                    weekDayU7--;
                }
                else
                {
                    weekDayU7 = 7;
                }

                var contactRecordIdentification = SetFunctionValueMapping(weekDay, functionValueMapping, functionValueMappingNullValue);
                functionValueMapping["DAYOFWEEK"] = $"{weekDayU7}";
                if (contactRecordIdentification != null && functionValueMapping.Keys.Count == 1)
                {
                    changedRecord = new UPCRMRecord(contactRecordIdentification, "Delete");
                }
                else if (contactRecordIdentification == null && functionValueMapping.Keys.Count > 1)
                {
                    changedRecord = new UPCRMRecord(infoAreaid);
                    changedRecord.AddLink(new UPCRMLink(RecordIdentification));
                    functionValueMapping.Append(functionValueMappingNullValue);
                    AddValuesToRecordContextRecordId(functionValueMapping, changedRecord, contactRecordIdentification);
                }
                else if (contactRecordIdentification != null && !IsRecordEqual(contactRecordIdentification, functionValueMapping))
                {
                    changedRecord = new UPCRMRecord(contactRecordIdentification);
                    functionValueMapping.Append(functionValueMappingNullValue);
                    AddValuesToRecordContextRecordId(functionValueMapping, changedRecord, contactRecordIdentification);
                }

                if (changedRecord != null)
                {
                    changedRecords.Add(changedRecord);
                }
            }

            return(changedRecords);
        }
Exemplo n.º 5
0
        /// <inheritdoc/>
        public override List <UPCRMRecord> ChangedChildRecordsForParentRecord(UPCRMRecord parentRecord, bool userChangesOnly)
        {
            var childRecords = this.ParticipantsControl.ChangedRepParticipantAcceptanceRecords();

            if (!userChangesOnly && !string.IsNullOrEmpty(this.ParticipantsControl.RepAcceptanceInfoAreaId) && !parentRecord.IsNew)
            {
                var sync = new UPCRMRecord(this.ParticipantsControl.RepAcceptanceInfoAreaId, "Sync", null);
                sync.AddLink(new UPCRMLink(parentRecord, this.ParticipantsControl.RepAcceptanceLinkId));

                if (childRecords == null)
                {
                    childRecords = new List <UPCRMRecord>();
                }

                childRecords.Add(sync);
            }

            return(childRecords);
        }
        /// <summary>
        /// Changeds the records.
        /// </summary>
        /// <returns></returns>
        public List <UPCRMRecord> ChangedRecords()
        {
            UPCRMRecord syncRecord = new UPCRMRecord(this.QuotaSearchAndList.InfoAreaId, "Sync");

            syncRecord.AddLink(new UPCRMLink(this.linkRecordIdentification, this.QuotaLinkId));
            List <UPCRMRecord> changedRecords = new List <UPCRMRecord> {
                syncRecord
            };

            foreach (UPSERowQuota rowQuota in this.rowQuotaDictionary.Values)
            {
                List <UPCRMRecord> changedRecordsForRow = rowQuota.ChangedRecords();
                if (changedRecordsForRow.Count > 0)
                {
                    changedRecords.AddRange(changedRecordsForRow);
                }
            }

            return(changedRecords);
        }
Exemplo n.º 7
0
        ArrayList ChangedChildRecordsForParentRecord(UPCRMRecord parentRecord, bool userChangesOnly)
        {
            ArrayList childRecords = this.ParticipantsControl.ChangedRepParticipantAcceptanceRecords();

            if (!userChangesOnly && this.ParticipantsControl.RepAcceptanceInfoAreaId.Length && !parentRecord.IsNew)
            {
                UPCRMRecord sync = new UPCRMRecord(this.ParticipantsControl.RepAcceptanceInfoAreaId, "Sync");
                sync.AddLink(new UPCRMLink(parentRecord, this.ParticipantsControl.RepAcceptanceLinkId));
                if (childRecords)
                {
                    return(childRecords.ArrayByAddingObject(sync));
                }
                else
                {
                    return(NSMutableArray.ArrayWithObject(sync));
                }
            }
            else
            {
                return(childRecords);
            }
        }
Exemplo n.º 8
0
        private void ContinueWithParameters(Dictionary <string, object> parameterDictionary)
        {
            this.TemplateFilter = this.TemplateFilter.FilterByApplyingValueDictionaryDefaults(parameterDictionary, true);
            UPCRMRecord record       = new UPCRMRecord(this.RecordIdentification);
            string      linkRecordId = this.ViewReference.ContextValueForKey("LinkRecordId");

            if (!string.IsNullOrEmpty(linkRecordId))
            {
                int linkId = Convert.ToInt32(this.ViewReference.ContextValueForKey("LinkId"));
                if (linkId < 0)
                {
                    linkId = -1;
                }

                record.AddLink(new UPCRMLink(linkRecordId, linkId));
            }

            List <UPCRMRecord> childRecords = record.ApplyValuesFromTemplateFilter(this.TemplateFilter, false);

            if (childRecords?.Count > 0)
            {
                List <UPCRMRecord> linkRecords     = null;
                List <UPCRMRecord> combinedRecords = new List <UPCRMRecord> {
                    record
                };
                foreach (UPCRMRecord childRecord in childRecords)
                {
                    if (childRecord.Mode == "ParentUpdate")
                    {
                        if (linkRecords == null)
                        {
                            linkRecords = new List <UPCRMRecord> {
                                childRecord
                            };
                        }
                        else
                        {
                            linkRecords.Add(childRecord);
                        }
                    }
                    else
                    {
                        combinedRecords.Add(childRecord);
                    }
                }

                if (linkRecords?.Count == 0)
                {
                    this.ContinueWithRecords(combinedRecords);
                }
                else
                {
                    this.RecordsToSave = combinedRecords;
                    this.ContinueWithLinkRecords(linkRecords);
                }
            }
            else
            {
                this.ContinueWithRecords(new List <UPCRMRecord> {
                    record
                });
            }
        }
        private void ProcessResult(UPCRMResult result)
        {
            UPRecordCopyStep currentStep = this.stepQueue[0];

            this.stepQueue.RemoveAt(0);
            UPConfigQueryTable queryTable = currentStep.QueryTable;
            int count            = result.RowCount;
            int resultTableCount = result.NumberOfResultTables;
            UPContainerInfoAreaMetaInfo copyResultInfoArea = null;

            if (queryTable.InfoAreaId == currentStep.FieldControl.InfoAreaId)
            {
                copyResultInfoArea = result.MetaInfo.ResultInfoAreaMetaInfoAtIndex(0);
            }

            for (int i = 0; i < count; i++)
            {
                UPCRMResultRow row    = (UPCRMResultRow)result.ResultRowAtIndex(i);
                UPCRMRecord    record = new UPCRMRecord(queryTable.InfoAreaId);
                if (currentStep.DestinationRecord != null)
                {
                    record.AddLink(new UPCRMLink(currentStep.DestinationRecord, queryTable.LinkId));
                }

                for (int j = 1; j < resultTableCount; j++)
                {
                    string linkRecordIdentification = row.RecordIdentificationAtIndex(j);
                    if (string.IsNullOrEmpty(linkRecordIdentification) && !result.IsServerResult)
                    {
                        UPContainerInfoAreaMetaInfo resultInfoArea = result.MetaInfo.ResultInfoAreaMetaInfoAtIndex(j);
                        UPCRMLinkReader             linkReader     = new UPCRMLinkReader(StringExtensions.InfoAreaIdRecordId(currentStep.FieldControl.InfoAreaId, row.RootRecordId),
                                                                                         $"{resultInfoArea.InfoAreaId}:{resultInfoArea.LinkId}", null);
                        linkRecordIdentification = linkReader.RequestLinkRecordOffline();
                    }

                    int linkId = -1;
                    if (linkRecordIdentification?.Length > 8)
                    {
                        if (currentStep.DestinationRecord == null || queryTable.LinkId != linkId ||
                            linkRecordIdentification.InfoAreaId() != currentStep.DestinationRecord.InfoAreaId)
                        {
                            record.AddLink(new UPCRMLink(linkRecordIdentification, linkId));
                        }
                    }
                }

                Dictionary <string, object> fieldsWithFunctions = row.ValuesWithFunctions();
                UPConfigQueryTable          replacedTable       = queryTable.QueryTableByApplyingValueDictionary(fieldsWithFunctions);
                if (copyResultInfoArea != null)
                {
                    foreach (UPContainerFieldMetaInfo field in copyResultInfoArea.Fields)
                    {
                        string val = row.RawValueAtIndex(field.PositionInResult);
                        if (!string.IsNullOrEmpty(val))
                        {
                            record.AddValue(new UPCRMFieldValue(val, field.InfoAreaId, field.FieldId));
                        }
                    }
                }

                if (replacedTable != null)
                {
                    record.ApplyValuesFromTemplateFilter(replacedTable, true);
                }

                int numberOfSubTables = queryTable.NumberOfSubTables;
                if (numberOfSubTables > 0)
                {
                    for (int k = 0; k < numberOfSubTables; k++)
                    {
                        UPRecordCopyStep subStep = new UPRecordCopyStep();
                        subStep.QueryTable = queryTable.SubTableAtIndex(k);
                        subStep.SourceRecordIdentification = row.RootRecordIdentification;
                        subStep.DestinationRecord          = record;
                        this.ConfigForStepFromQueryTable(subStep, subStep.QueryTable);
                        this.stepQueue.Add(subStep);
                    }
                }

                this.recordArray.Add(record);
            }

            this.ExecuteNextStep();
        }
Exemplo n.º 10
0
        /// <summary>
        /// Changeds the records.
        /// </summary>
        /// <param name="rootRecord">The root record.</param>
        /// <param name="data">The data.</param>
        /// <param name="ignoreDefault">if set to <c>true</c> [ignore default].</param>
        /// <returns></returns>
        public List <UPCRMRecord> ChangedRecords(UPCRMRecord rootRecord, Dictionary <string, object> data, bool ignoreDefault)
        {
            if (!this.Multiple)
            {
                return(this.SingleAnswerChangedRecords(rootRecord, data, false, ignoreDefault));
            }

            if (!this.Changed)
            {
                return(null);
            }

            string        infoAreaId      = this.Root.SurveyAnswerSearchAndList.InfoAreaId;
            List <string> recordsToDelete = new List <string>();

            foreach (UPSurveyAnswerSingle singleRecord in this.singleAnswerDictionary.Values)
            {
                if (singleRecord.Deleted && !string.IsNullOrEmpty(singleRecord.RecordIdentification))
                {
                    recordsToDelete.Add(singleRecord.RecordIdentification);
                }
            }

            List <UPCRMRecord> changedRecords = new List <UPCRMRecord>();

            foreach (UPSurveyAnswerSingle singleRecord in this.singleAnswerDictionary.Values)
            {
                if (!singleRecord.Deleted && string.IsNullOrEmpty(singleRecord.RecordIdentification))
                {
                    UPCRMRecord record;
                    if (recordsToDelete.Count > 0)
                    {
                        string reUseRecordIdentification = recordsToDelete[0];
                        recordsToDelete.RemoveAt(0);
                        record = new UPCRMRecord(reUseRecordIdentification);
                    }
                    else
                    {
                        record = new UPCRMRecord(infoAreaId);
                        record.AddLink(new UPCRMLink(rootRecord, -1));
                        if (this.Root.AnswerQuestionNumberField != null)
                        {
                            record.AddValue(new UPCRMFieldValue(this.Question.QuestionId, infoAreaId, this.Root.AnswerQuestionNumberField.FieldId));
                        }
                    }

                    if (this.Root.SurveyAnswerTemplateFilter != null)
                    {
                        UPConfigFilter filter = this.Root.SurveyAnswerTemplateFilter.FilterByApplyingValueDictionaryDefaults(data, true);
                        record.ApplyValuesFromTemplateFilter(filter);
                    }

                    if (!string.IsNullOrEmpty(this.Question.RecordIdentification) && this.Question.Questionnaire.Manager.LinkAnswerToQuestion)
                    {
                        record.AddLink(new UPCRMLink(this.Question.RecordIdentification));
                    }

                    if (this.Question.HasAnswerOptions)
                    {
                        if (this.Root.AnswerAnswerNumberField != null)
                        {
                            record.AddValue(new UPCRMFieldValue(singleRecord.AnswerId, infoAreaId, this.Root.AnswerAnswerNumberField.FieldId));
                        }

                        if (this.Question.Questionnaire.Manager.LinkAnswerToQuestionAnswer && this.Question.HasAnswerOptions)
                        {
                            IQuestionnaireAnswerOption answerOption = this.Question.AnswerForId(singleRecord.AnswerId);
                            if (answerOption != null)
                            {
                                record.AddLink(new UPCRMLink(answerOption.RecordIdentification));
                            }
                        }
                    }
                    else
                    {
                        if (this.Root.AnswerAnswerTextField != null)
                        {
                            string text = singleRecord.AnswerId;
                            if (this.Question.AnswersFromCatalog && this.Question.Questionnaire.Manager.SaveCatalogValuesAsText)
                            {
                                text = this.Question.TextForAnswerId(this.AnswerText) ?? string.Empty;
                            }

                            record.AddValue(new UPCRMFieldValue(text, infoAreaId, this.Root.AnswerAnswerTextField.FieldId));
                        }
                    }

                    changedRecords.Add(record);
                }
            }

            changedRecords.AddRange(recordsToDelete.Select(deleteRecordId => new UPCRMRecord(deleteRecordId, "Delete")));
            return(changedRecords);
        }
Exemplo n.º 11
0
        /// <summary>
        /// Singles the answer changed records.
        /// </summary>
        /// <param name="rootRecord">The root record.</param>
        /// <param name="data">The data.</param>
        /// <param name="ignoreExisting">if set to <c>true</c> [ignore existing].</param>
        /// <param name="ignoreDefault">if set to <c>true</c> [ignore default].</param>
        /// <returns></returns>
        public List <UPCRMRecord> SingleAnswerChangedRecords(UPCRMRecord rootRecord, Dictionary <string, object> data, bool ignoreExisting, bool ignoreDefault)
        {
            if (this.Changed)
            {
                UPCRMRecord record;
                string      infoAreaId   = this.Root.SurveyAnswerSearchAndList.InfoAreaId;
                bool        existsRecord = false;
                if (!ignoreExisting && !string.IsNullOrEmpty(this.RecordIdentification))
                {
                    record       = new UPCRMRecord(this.RecordIdentification);
                    existsRecord = true;
                }
                else if (!ignoreDefault || !this.IsDefaultAnswer)
                {
                    record = new UPCRMRecord(infoAreaId);
                    record.AddLink(new UPCRMLink(rootRecord, -1));
                    if (this.Root.AnswerQuestionNumberField != null)
                    {
                        record.AddValue(new UPCRMFieldValue(this.Question.QuestionId, infoAreaId, this.Root.AnswerQuestionNumberField.FieldId));
                    }

                    if (this.Question.Questionnaire.Manager.LinkAnswerToQuestionnaire)
                    {
                        record.AddLink(new UPCRMLink(this.Question.Questionnaire.RecordIdentification));
                    }

                    if (this.Question.Questionnaire.Manager.LinkAnswerToQuestion)
                    {
                        record.AddLink(new UPCRMLink(this.Question.RecordIdentification));
                    }
                }
                else
                {
                    return(null);
                }

                if (this.Root.SurveyAnswerTemplateFilter != null)
                {
                    UPConfigFilter filter = this.Root.SurveyAnswerTemplateFilter.FilterByApplyingValueDictionaryDefaults(data, true);
                    record.ApplyValuesFromTemplateFilter(filter);
                }

                if (this.Root.AnswerAnswerNumberField != null)
                {
                    record.AddValue(new UPCRMFieldValue(this.AnswerNumber, infoAreaId, this.Root.AnswerAnswerNumberField.FieldId));
                }

                if (this.Root.AnswerAnswerTextField != null)
                {
                    string text = this.AnswerText;
                    if (this.Question.AnswersFromCatalog && this.Question.Questionnaire.Manager.SaveCatalogValuesAsText)
                    {
                        text = this.Question.TextForAnswerId(this.AnswerText) ?? string.Empty;
                    }

                    record.AddValue(new UPCRMFieldValue(text, infoAreaId, this.Root.AnswerAnswerTextField.FieldId));
                }

                if (this.Question.Questionnaire.Manager.LinkAnswerToQuestionAnswer && this.Question.HasAnswerOptions)
                {
                    IQuestionnaireAnswerOption answerOption = this.Question.AnswerForId(this.AnswerNumber);
                    if (answerOption != null)
                    {
                        if (existsRecord && this.Question.Questionnaire.Manager.DeleteAndInsertOnAnswerOptionChange)
                        {
                            UPCRMRecord        deleteRecord   = new UPCRMRecord(this.RecordIdentification, "Delete");
                            List <UPCRMRecord> createdRecords = this.SingleAnswerChangedRecords(rootRecord, data, true, ignoreDefault);
                            List <UPCRMRecord> changedRecords = new List <UPCRMRecord> {
                                deleteRecord
                            };
                            changedRecords.AddRange(createdRecords);
                            return(changedRecords);
                        }

                        record.AddLink(new UPCRMLink(answerOption.RecordIdentification));
                    }
                    else if (this.Question.Questionnaire.Manager.DeleteSingleAnswerOptionIfEmpty)
                    {
                        return(existsRecord ? new List <UPCRMRecord> {
                            new UPCRMRecord(record.RecordIdentification, "Delete")
                        } : null);
                    }
                }

                return(new List <UPCRMRecord> {
                    record
                });
            }

            return(null);
        }
        /// <summary>
        /// Changeds the records.
        /// </summary>
        /// <returns></returns>
        public List <UPCRMRecord> ChangedRecords()
        {
            UPCRMRecord changedRecord = null;

            if (this.Deleted && this.Record != null)
            {
                changedRecord = new UPCRMRecord(this.Record.RecordIdentification, "Delete");
            }
            else
            {
                if (this.Created && this.Record == null)
                {
                    UPObjectives objectives = this.Group.Objectives;
                    changedRecord = new UPCRMRecord(this.Group.Configuration.DestinationFieldControl.InfoAreaId);
                    changedRecord.AddLink(new UPCRMLink(objectives.RecordIdentification));
                    for (int i = 0; i < this.AdditionalFields.Count; i++)
                    {
                        string newValue = this.values[i];
                        if (!string.IsNullOrEmpty(newValue))
                        {
                            UPConfigFieldControlField field = this.AdditionalFields[i];
                            changedRecord.NewValueFieldId(newValue, field.FieldId);
                        }
                    }
                }
                else if (this.Changed && this.Record != null)
                {
                    changedRecord = new UPCRMRecord(this.Record.RecordIdentification);
                    changedRecord.AddLink(new UPCRMLink(this.Group.Objectives.RecordIdentification));
                    for (int i = 0; i < this.AdditionalFields.Count; i++)
                    {
                        string originalValue = this.OriginalValues[i];
                        string newValue      = this.values[i];
                        if (originalValue != newValue)
                        {
                            UPConfigFieldControlField field = this.AdditionalFields[i];
                            changedRecord.NewValueFromValueFieldId(newValue, originalValue, field.FieldId);
                        }
                    }

                    if (this.completed != this.originalCompleted)
                    {
                        string sCompleted         = StringExtensions.CrmValueFromBool(this.completed);
                        string sOriginalCompleted = StringExtensions.CrmValueFromBool(this.originalCompleted);
                        if (this.Group.Configuration.FieldForFunction(Constants.FieldCompletedFunction) != null)
                        {
                            changedRecord.NewValueFromValueFieldId(sCompleted, sOriginalCompleted, this.Group.Configuration.FieldForFunction(Constants.FieldCompletedFunction).FieldId);
                        }

                        if (this.completed)
                        {
                            if (this.Group.Configuration.FieldForFunction(Constants.FieldCompletedOnFunction) != null)
                            {
                                changedRecord.NewValueFromValueFieldId(StringExtensions.CrmValueFromDate(DateTime.UtcNow), string.Empty, this.Group.Configuration.FieldForFunction(Constants.FieldCompletedOnFunction).FieldId);
                            }

                            if (this.Group.Configuration.FieldForFunction(Constants.FieldCompletedByFunction) != null)
                            {
                                changedRecord.NewValueFieldId(ServerSession.CurrentSession.CurRep, this.Group.Configuration.FieldForFunction(Constants.FieldCompletedByFunction).FieldId);
                            }
                        }
                    }
                }
            }

            return(changedRecord != null ? new List <UPCRMRecord> {
                changedRecord
            } : null);
        }
Exemplo n.º 13
0
        /// <summary>
        /// Gets the changed records.
        /// </summary>
        /// <param name="rootTemplateFilter">The root template filter.</param>
        /// <param name="baseTemplateFilter">The base template filter.</param>
        /// <param name="ignoreDefault">if set to <c>true</c> [ignore default].</param>
        /// <returns></returns>
        public List <UPCRMRecord> ChangedRecords(UPConfigFilter rootTemplateFilter, UPConfigFilter baseTemplateFilter, bool ignoreDefault)
        {
            UPCRMRecord rootRecord;
            bool        changedRoot = false;

            if (!string.IsNullOrEmpty(this.AnswerRootRecordIdentification))
            {
                rootRecord = new UPCRMRecord(this.AnswerRootRecordIdentification);
            }
            else
            {
                rootRecord = new UPCRMRecord(this.SurveySearchAndList.InfoAreaId);
                rootRecord.AddLink(new UPCRMLink(this.RootRecordIdentification));
                if (this.Questionnaire.Manager.LinkSurveyToQuestionnaire)
                {
                    rootRecord.AddLink(new UPCRMLink(this.Questionnaire.RecordIdentification));
                }

                if (this.SurveyTemplateFilter != null)
                {
                    UPConfigFilter filter = this.SurveyTemplateFilter.FilterByApplyingValueDictionaryDefaults(this.Parameters, true);
                    rootRecord.ApplyValuesFromTemplateFilter(filter);
                }

                changedRoot = true;
            }

            Dictionary <string, UPCRMRecord> foreignFieldDictionary = new Dictionary <string, UPCRMRecord>();
            List <UPCRMRecord> answerRecords = new List <UPCRMRecord>();

            foreach (UPQuestionnaireQuestion question in this.Questionnaire.Questions)
            {
                UPSurveyAnswer     answer = this.surveyAnswers[question.QuestionId];
                List <UPCRMRecord> currentAnswerRecords = answer.ChangedRecords(rootRecord, this.Parameters, ignoreDefault);
                if (currentAnswerRecords.Count > 0)
                {
                    answerRecords.AddRange(currentAnswerRecords);
                }

                if (question.Save)
                {
                    UPSurveyForeignField foreignField = answer.SurveyForeignField;
                    if (!string.IsNullOrEmpty(foreignField.RecordIdentification) && !string.IsNullOrEmpty(foreignField.Value) &&
                        !string.IsNullOrEmpty(answer.Answer) && foreignField.Value != answer.Answer)
                    {
                        UPCRMRecord foreignRecord = foreignFieldDictionary.ValueOrDefault(foreignField.RecordIdentification);
                        if (foreignRecord == null)
                        {
                            foreignRecord = new UPCRMRecord(foreignField.RecordIdentification);
                            foreignFieldDictionary[foreignField.RecordIdentification] = foreignRecord;
                        }

                        UPCRMFieldValue fieldValue = new UPCRMFieldValue(answer.Answer, foreignRecord.InfoAreaId, foreignField.FieldInfo.FieldId, this.Questionnaire.Manager.AutomaticOnlineSaveOfForeignFields);
                        foreignRecord.AddValue(fieldValue);
                    }
                }
            }

            List <UPCRMRecord> changedRecords = new List <UPCRMRecord>();

            if (changedRoot)
            {
                changedRecords.Add(rootRecord);
            }

            if (answerRecords.Count > 0)
            {
                changedRecords.AddRange(answerRecords);
            }

            if (changedRecords.Count > 0)
            {
                UPCRMRecord rootSyncRecord = new UPCRMRecord(rootRecord, "Sync");
                changedRecords.Add(rootSyncRecord);
            }

            if (foreignFieldDictionary.Count > 0)
            {
                changedRecords.AddRange(foreignFieldDictionary.Values);
            }

            if (rootTemplateFilter != null)
            {
                rootTemplateFilter = rootTemplateFilter.FilterByApplyingValueDictionaryDefaults(this.Parameters, true);
                if (rootTemplateFilter != null)
                {
                    UPCRMRecord record = new UPCRMRecord(rootRecord);
                    record.ApplyValuesFromTemplateFilter(rootTemplateFilter);
                    changedRecords.Add(record);
                }
            }

            if (baseTemplateFilter != null)
            {
                baseTemplateFilter = baseTemplateFilter.FilterByApplyingValueDictionaryDefaults(this.Parameters, true);
                if (baseTemplateFilter != null)
                {
                    UPCRMRecord record = new UPCRMRecord(this.RecordIdentification);
                    record.ApplyValuesFromTemplateFilter(baseTemplateFilter);
                    changedRecords.Add(record);
                }
            }

            return(changedRecords);
        }