Ejemplo n.º 1
0
        public static List<DropDownEnumModel> GetCustomEnumByIdEnumType(int idEnumType, int idLanguageType)
        {
            List<DropDownEnumModel> lstRecueilCMs = new List<DropDownEnumModel>();

            List<CustomEnum> lstCE = CustomEnumBL.GetAllCustomEnums().Where(e => e.idCustomEnumType == idEnumType).OrderBy(e => e.OrderType).ToList();

            foreach (var e in lstCE)
            {
                LanguageContent objLangue = LanguageContentBL.GetAllLanguageContents().Where(l => l.NameKey == e.NameKey && l.idLanguageType == idLanguageType).FirstOrDefault<LanguageContent>();

                DropDownEnumModel objRCM = new DropDownEnumModel();
                objRCM.NameKey = e.NameKey;
                objRCM.Text = objLangue.LanguageContentString;
                objRCM.Value = e.Value;
                objRCM.OrderType = e.OrderType;
                objRCM.idCustomEnumType = e.idCustomEnumType;

                lstRecueilCMs.Add(objRCM);
            }

            return lstRecueilCMs;
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Optimization : get all enums in dictionary
        /// Fetch enum languages once, not in loop
        /// </summary>
        /// <param name="idLanguageType"></param>
        /// <returns></returns>
        public static IDictionary<int, List<DropDownEnumModel>> GetCustomEnums(int idLanguageType)
        {
            IDictionary<int, List<DropDownEnumModel>> dicoDropDownEnumModels = new Dictionary<int, List<DropDownEnumModel>>();
            string currentHostCode = Upsilab.Business.Utility.SessionManager.GetHostCodeSession();

            //Get all ENUMs
            IList<CustomEnum> lstCustomEnums = CustomEnumBL.GetAllCustomEnums().Where(c => string.IsNullOrEmpty(c.HostCodes) || (!string.IsNullOrEmpty(c.HostCodes) && c.HostCodes.Contains(currentHostCode))).OrderBy(c => c.idCustomEnumType).OrderBy(c => c.OrderType).ToList();
            IList<int> lstCustomEnumTypes = lstCustomEnums.Select(c => c.idCustomEnumType).Distinct().ToList();

            //Get language regarding ENUMs here not in loop
            IList<LanguageContent> lstEnumLangues = LanguageContentBL.GetAllLanguageContents().Where(l => l.NameKey.Contains("_Enum_") && l.idLanguageType == idLanguageType).ToList<LanguageContent>();

            foreach (var customEnumType in lstCustomEnumTypes)
            {
                dicoDropDownEnumModels.Add(customEnumType, new List<DropDownEnumModel>());
            }

            //Fill dictionnary
            foreach (var customEnum in lstCustomEnums)
            {
                IList<DropDownEnumModel> lstDropDownEnumModels = dicoDropDownEnumModels[customEnum.idCustomEnumType];

                LanguageContent language = lstEnumLangues.Where(l => l.NameKey == customEnum.NameKey).FirstOrDefault<LanguageContent>();

                DropDownEnumModel dropDownEnumModel = new DropDownEnumModel()
                {
                    NameKey = customEnum.NameKey,
                    Text = (language != null) ? language.LanguageContentString : string.Empty,
                    Value = customEnum.Value,
                    OrderType = customEnum.OrderType,
                    idCustomEnumType = customEnum.idCustomEnumType
                };

                lstDropDownEnumModels.Add(dropDownEnumModel);
            }

            return dicoDropDownEnumModels;
        }