Exemplo n.º 1
0
        private string GetValue(Entity attributeAuditHistoryDetail, string fieldKey)
        {
            string value = string.Empty;

            if (attributeAuditHistoryDetail.Contains(fieldKey))
            {
                bool isOldValueAnEntityReference = attributeAuditHistoryDetail[fieldKey].GetType().Equals(typeof(EntityReference));
                bool isOldValueTypeMoney         = attributeAuditHistoryDetail[fieldKey].GetType().Equals(typeof(Money));
                bool isTypeOptionSet             = attributeAuditHistoryDetail[fieldKey].GetType().Equals(typeof(OptionSetValue));


                if (isOldValueAnEntityReference)
                {
                    value = GetValueEntityReference(attributeAuditHistoryDetail[fieldKey] as EntityReference);
                }
                else if (isOldValueTypeMoney)
                {
                    value = (attributeAuditHistoryDetail[fieldKey] as Money).Value.ToString();
                }
                else if (isTypeOptionSet)
                {
                    OptionSetValue optSetValue = (attributeAuditHistoryDetail[fieldKey] as OptionSetValue);


                    //if the field was called before, the value will be taken from dictionary
                    if (optionSetsManagersDict.ContainsKey(fieldKey))
                    {
                        optionSetManager = optionSetsManagersDict[fieldKey];
                    }
                    else// otherwise a new optionSetManager object will be created and added to the dictionary
                    {
                        optionSetManager = new OptionSetManager(_service);
                        optionSetManager.SetupOptionSetValues(attributeAuditHistoryDetail.LogicalName, fieldKey);
                        optionSetsManagersDict.Add(fieldKey, optionSetManager);
                    }
                }
                else
                {
                    value = attributeAuditHistoryDetail[fieldKey].ToString();
                }
            }
            return(value);
        }
        private string GetValue(Entity attributeAuditHistoryDetail, string fieldKey)
        {
            string value = string.Empty;

            if (attributeAuditHistoryDetail.Contains(fieldKey))
            {
                bool isOldValueAnEntityReference = attributeAuditHistoryDetail[fieldKey] is EntityReference;
                bool isOldValueTypeMoney         = attributeAuditHistoryDetail[fieldKey] is Money;
                bool isTypeOptionSet             = attributeAuditHistoryDetail[fieldKey] is OptionSetValue;


                if (isOldValueAnEntityReference)
                {
                    value = GetValueEntityReference(attributeAuditHistoryDetail[fieldKey] as EntityReference);
                }
                else if (isOldValueTypeMoney)
                {
                    value = (attributeAuditHistoryDetail[fieldKey] as Money)?.Value.ToString();
                }
                else if (isTypeOptionSet)
                {
                    OptionSetValue optSetValue = (attributeAuditHistoryDetail[fieldKey] as OptionSetValue);

                    if (!optionSetManagerDictionary.ContainsKey(fieldKey))
                    {
                        var optionSetManager = new OptionSetManager(_service);
                        optionSetManager.SetupOptionSetValues(attributeAuditHistoryDetail.LogicalName, fieldKey);
                        optionSetManagerDictionary.Add(fieldKey, optionSetManager);
                    }

                    value = optionSetManagerDictionary[fieldKey].GetDescriptionOptionSetValue(optSetValue.Value);
                }
                else
                {
                    value = attributeAuditHistoryDetail[fieldKey].ToString();
                }
            }
            return(value);
        }
Exemplo n.º 3
0
        private string GetValue(Entity attributeAuditHistoryDetail, string fieldKey)
        {
            string value = string.Empty;

            if (attributeAuditHistoryDetail.Contains(fieldKey))
            {
                bool isOldValueAnEntityReference = attributeAuditHistoryDetail[fieldKey].GetType().Equals(typeof(EntityReference));
                bool isOldValueTypeMoney         = attributeAuditHistoryDetail[fieldKey].GetType().Equals(typeof(Money));
                bool isTypeOptionSet             = attributeAuditHistoryDetail[fieldKey].GetType().Equals(typeof(OptionSetValue));


                if (isOldValueAnEntityReference)
                {
                    value = GetValueEntityReference(attributeAuditHistoryDetail[fieldKey] as EntityReference);
                }
                else if (isOldValueTypeMoney)
                {
                    value = (attributeAuditHistoryDetail[fieldKey] as Money).Value.ToString();
                }
                else if (isTypeOptionSet)
                {
                    OptionSetValue optSetValue = (attributeAuditHistoryDetail[fieldKey] as OptionSetValue);

                    if (optionSetManager == null)
                    {
                        optionSetManager = new OptionSetManager(_service);
                    }

                    optionSetManager.SetupOptionSetValues(attributeAuditHistoryDetail.LogicalName, fieldKey);

                    value = optionSetManager.GetDescriptionOptionSetValue(optSetValue.Value);
                }
                else
                {
                    value = attributeAuditHistoryDetail[fieldKey].ToString();
                }
            }
            return(value);
        }