Esempio n. 1
0
        /// <summary>
        /// Gets the contents of a code list
        /// </summary>
        /// <param name="name">The name of the code list to get</param>
        /// <param name="codelistSource">
        /// Where to get the code list from, if not set the following search order will be used:
        /// 1. Service edition
        /// 2. Service
        /// 3. Service owner
        /// </param>
        /// <returns>The requested code list if found</returns>
        public string GetCodelist(string name, CodeListSourceType codelistSource = CodeListSourceType.Unspecified)
        {
            switch (codelistSource)
            {
            case CodeListSourceType.Edition:
            {
                return(_execution.GetCodelist(Org, Service, Edition, name));
            }

            case CodeListSourceType.Service:
            {
                return(_execution.GetCodelist(Org, Service, null, name));
            }

            case CodeListSourceType.Owner:
            {
                return(_execution.GetCodelist(Org, null, null, name));
            }

            case CodeListSourceType.Platform:
            {
                throw new NotImplementedException();
            }

            default:
            {
                string codelist = _execution.GetCodelist(Org, Service, Edition, name);
                if (!string.IsNullOrEmpty(codelist))
                {
                    return(codelist);
                }

                codelist = _execution.GetCodelist(Org, Service, null, name);
                if (!string.IsNullOrEmpty(codelist))
                {
                    return(codelist);
                }

                codelist = _execution.GetCodelist(Org, null, null, name);
                if (!string.IsNullOrEmpty(codelist))
                {
                    return(codelist);
                }

                return(null);
            }
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Gets contents of a code list in a format which can be used in asp .net tag helpers for dropdowns
        /// </summary>
        /// <param name="name">The name of the code list</param>
        /// <param name="textKey">The key of the code list value to use as the display text</param>
        /// <param name="valueKey">The key of the code list value to use as the item value</param>
        /// <param name="codelistSource">
        /// Where to get the code list from, if not set the following search order will be used:
        /// 1. Service
        /// 2. Service owner
        /// </param>
        /// <returns>A list which can be used for populating dropdowns etc. using tag helpers</returns>
        public List <SelectListItem> GetPresentationCodelist(string name, string textKey, string valueKey, CodeListSourceType codelistSource = CodeListSourceType.Unspecified)
        {
            string  codelist     = GetCodelist(name, codelistSource);
            JObject codelistJson = JObject.Parse(codelist);

            if (string.IsNullOrEmpty(valueKey))
            {
                // Set to default key if no specific is choosen
                valueKey = "key";
            }

            List <SelectListItem> list = new List <SelectListItem>();

            foreach (JObject item in codelistJson["codes"])
            {
                list.Add(new SelectListItem {
                    Text = (string)item[textKey], Value = (string)item[valueKey]
                });
            }

            return(list);
        }