Exemplo n.º 1
0
        public string[] GetValue(CodeGroupType groupType, string language, string code)
        {
            if (!CodeGroups.Any())
            {
                return(null);
            }
            if (string.IsNullOrEmpty(language))
            {
                return(null);
            }
            if (string.IsNullOrEmpty(code))
            {
                return(null);
            }

            var codeGroup = CodeGroups.FirstOrDefault(cg => cg.Type == groupType &&
                                                      cg.Translations.Any(t => t.Language.Equals(language, StringComparison.OrdinalIgnoreCase)));

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

            var translations = codeGroup.Translations.Where(t => t.Language.Equals(language, StringComparison.OrdinalIgnoreCase));

            return(translations.Select(t => t.Value).ToArray());
        }
Exemplo n.º 2
0
        public CodeGroup(CodeGroupType type, string code, string value)
        {
            _type = type;
            _code = code;

            _translations.Add(new CodeGroupTranslation(culture: CurrentCulture, language: CurrentLanguage, value: value));
        }
Exemplo n.º 3
0
        public string GetValue(CodeGroupType groupType, string culture, string language, string code)
        {
            if (!CodeGroups.Any())
            {
                return(null);
            }
            if (string.IsNullOrEmpty(culture))
            {
                return(null);
            }
            if (string.IsNullOrEmpty(language))
            {
                return(null);
            }
            if (string.IsNullOrEmpty(code))
            {
                return(null);
            }

            var codeGroup = CodeGroups.FirstOrDefault(cg => cg.Type == groupType &&
                                                      cg.Translations.Any(t => t.Culture.Equals(culture, StringComparison.OrdinalIgnoreCase) &&
                                                                          t.Language.Equals(language, StringComparison.OrdinalIgnoreCase)));

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

            var translation = codeGroup.Translations.FirstOrDefault(t => t.Culture.Equals(culture, StringComparison.OrdinalIgnoreCase) &&
                                                                    t.Language.Equals(language, StringComparison.OrdinalIgnoreCase));

            return(translation != null ? translation.Value : null);
        }
Exemplo n.º 4
0
        public ObservableCollection <CodeGroup> GetCodeGroups(CodeGroupType type)
        {
            var codeGroups = new ObservableCollection <CodeGroup>();

            if (!CodeGroups.Any())
            {
                return(codeGroups);
            }

            return(CodeGroups.Where(cg => cg.Type == type)
                   .ToObservableCollection());
        }
Exemplo n.º 5
0
        public CodeGroup(CodeGroupType type, string code, IEnumerable <CodeGroupTranslation> translations)
        {
            _type = type;
            _code = code;

            if (translations == null || !translations.Any())
            {
                return;
            }

            foreach (var translation in translations)
            {
                _translations.Add(translation);
            }
        }
Exemplo n.º 6
0
        public string GetValue(CodeGroupType groupType, string code)
        {
            if (!CodeGroups.Any())
            {
                return(null);
            }
            if (string.IsNullOrEmpty(code))
            {
                return(null);
            }

            var codeGroup = CodeGroups.FirstOrDefault(cg => cg.Type == groupType &&
                                                      cg.Code.Equals(code, StringComparison.OrdinalIgnoreCase));

            return(codeGroup != null ? codeGroup.Value : null);
        }
Exemplo n.º 7
0
        public string GetCode(CodeGroupType groupType, string value)
        {
            if (!CodeGroups.Any())
            {
                return(null);
            }
            if (string.IsNullOrEmpty(value))
            {
                return(null);
            }

            var codeGroup = CodeGroups.FirstOrDefault(cg => cg.Type == groupType &&
                                                      cg.Translations.Any(t => t.Value != null &&
                                                                          t.Value.Contains(value)));

            return(codeGroup != null ? codeGroup.Code : null);
        }
Exemplo n.º 8
0
        public CodeGroup(string name, string code, IEnumerable <CodeGroupTranslation> translations)
        {
            CodeGroupType type;

            if (Enum.TryParse(name, true, out type))
            {
                _type = type;
                _code = code;

                if (translations == null || !translations.Any())
                {
                    return;
                }

                foreach (var translation in translations)
                {
                    _translations.Add(translation);
                }
                return;
            }
            throw new InvalidCastException("No enumeration defined for" + name);
        }