예제 #1
0
        public static List<OptionSetItem> GetOptionSetValues(string entityLogicalName, string attributeLogicalName, bool? allowEmpty)
        {
            if (allowEmpty == null) allowEmpty = false;
            string cacheKey = entityLogicalName + "." + attributeLogicalName + "." + allowEmpty.ToString();

            if (_optionsCache.ContainsKey(cacheKey))
                return _optionsCache[cacheKey];
            else
            {
                AttributeMetadata attribute = LoadAttributeMetadata(entityLogicalName, attributeLogicalName);
                PicklistAttributeMetadata pickList = (PicklistAttributeMetadata)attribute;
                List<OptionSetItem> opts = new List<OptionSetItem>();
                if (allowEmpty.Value)
                    opts.Add(new OptionSetItem());

                foreach (OptionMetadata o in pickList.OptionSet.Options)
                {
                    OptionSetItem a = new OptionSetItem();
                    a.Name = o.Label.UserLocalizedLabel.Label;
                    a.Value = o.Value.Value;
                    opts.Add(a);
                }

                return opts;
            }
        }
예제 #2
0
        public static List <OptionSetItem> GetOptionSetValues(string entityLogicalName, string attributeLogicalName, bool?allowEmpty)
        {
            if (allowEmpty == null)
            {
                allowEmpty = false;
            }
            string cacheKey = entityLogicalName + "." + attributeLogicalName + "." + allowEmpty.ToString();


            if (_optionsCache.ContainsKey(cacheKey))
            {
                return(_optionsCache[cacheKey]);
            }
            else
            {
                AttributeMetadata         attribute = LoadAttributeMetadata(entityLogicalName, attributeLogicalName);
                PicklistAttributeMetadata pickList  = (PicklistAttributeMetadata)attribute;
                List <OptionSetItem>      opts      = new List <OptionSetItem>();
                if (allowEmpty.Value)
                {
                    opts.Add(new OptionSetItem());
                }

                foreach (OptionMetadata o in pickList.OptionSet.Options)
                {
                    OptionSetItem a = new OptionSetItem();
                    a.Name  = o.Label.UserLocalizedLabel.Label;
                    a.Value = o.Value.Value;
                    opts.Add(a);
                }
                _optionsCache[cacheKey] = opts;
                return(opts);
            }
        }
        public List<OptionSetItem> GetFormats(object viewModel)
        {
            OptionSetItem paperBack = new OptionSetItem();
            paperBack.Name = "Paper Back";
            paperBack.Value = 1;

            OptionSetItem hardBack = new OptionSetItem();
            hardBack.Name = "Hard Back";
            hardBack.Value = 2;
            return new List<OptionSetItem>(paperBack, hardBack);
        }
예제 #4
0
        public static void AddOptionsetMetadata(string entityLogicalName, string attributeLogicalName, bool allowEmpty, List<Dictionary<string, object>> metatdata)
        {
            string cacheKey = entityLogicalName + "." + attributeLogicalName + "." + allowEmpty.ToString();

            List<OptionSetItem> opts = new List<OptionSetItem>();

            if (allowEmpty)
                opts.Add(new OptionSetItem());

            foreach (Dictionary<string, object> o in metatdata)
            {
                OptionSetItem a = new OptionSetItem();
                a.Name = (string)o["label"];
                a.Value = (int)o["value"];
                opts.Add(a);
            }

            OptionsetMetaData[cacheKey] = opts;
        }
예제 #5
0
        public static void AddOptionsetMetadata(string entityLogicalName, string attributeLogicalName, bool allowEmpty, List <Dictionary <string, object> > metatdata)
        {
            string cacheKey = entityLogicalName + "." + attributeLogicalName + "." + allowEmpty.ToString();

            List <OptionSetItem> opts = new List <OptionSetItem>();

            if (allowEmpty)
            {
                opts.Add(new OptionSetItem());
            }

            foreach (Dictionary <string, object> o in metatdata)
            {
                OptionSetItem a = new OptionSetItem();
                a.Name  = (string)o["label"];
                a.Value = (int)o["value"];
                opts.Add(a);
            }

            OptionsetMetaData[cacheKey] = opts;
        }