public static CodeNameSelectorModel ConvertToCodeNameModel <T>(this T data, Func <T, string> GetId, Func <T, string> GetName = null)
        {
            if (data == null)
            {
                return(null);
            }

            var id   = GetId(data);
            var name = GetName != null?GetName(data) : id;

            if (id == null)
            {
                return(null);
            }

            var model = new CodeNameSelectorModel
            {
                Id   = id,
                Name = name
            };

            model.SourceColor = (model.Source.IsNotEmpty() && TerminologyConstants.ColorForRecordSource.ContainsKey(model.Source.ToUpper())) ? TerminologyConstants.ColorForRecordSource[model.Source.ToUpper()] : string.Empty;

            return(model);
        }
        public static CodeNameSelectorModel ConvertToCodeNameModel <T>(this T data, Func <T, string> GetId, Func <T, string> GetName = null, Func <T, string> GetSource = null, Func <T, bool> GetReadOnly = null)
        {
            if (data == null)
            {
                return(null);
            }

            var id   = GetId(data);
            var name = GetName != null?GetName(data) : id;

            if (id == null)
            {
                return(null);
            }

            var srcOfData = GetSource?.Invoke(data);

            var model = new CodeNameSelectorModel
            {
                Id         = id,
                Name       = name,
                Source     = srcOfData,
                IsReadonly = GetReadOnly != null?GetReadOnly(data) : (srcOfData.IsEmpty()) ? false : (string.Compare(srcOfData, TerminologyConstants.MANUAL_DATA_SOURCE, true) != 0)
            };

            model.SourceColor = (model.Source.IsNotEmpty() && TerminologyConstants.ColorForRecordSource.ContainsKey(model.Source.ToUpper())) ? TerminologyConstants.ColorForRecordSource[model.Source.ToUpper()] : string.Empty;
            return(model);
        }
        public static void SafeAssignCodeNameFromSession(this CodeNameSelectorModel codeNameModel, string sessionKey, HttpContext httpContext)
        {
            if (codeNameModel == null || codeNameModel.Id == null || httpContext == null || sessionKey.IsEmpty())
            {
                return;
            }
            var lkp = httpContext.Session.GetObject <Dictionary <string, string> >(sessionKey);

            codeNameModel.Name = (lkp.IsCollectionValid() && lkp.ContainsKey(codeNameModel.Id)) ? lkp[codeNameModel.Id] : codeNameModel.Name;
        }
        public static string SerializeCodeNameItemToJsonArray(this CodeNameSelectorModel codeName)
        {
            var list = new List <CodeNameSelectorModel>();

            if (codeName == null)
            {
                return(JsonConvert.SerializeObject(list));
            }

            list.Add(codeName);
            return(JsonConvert.SerializeObject(list));
        }