コード例 #1
0
ファイル: Product.cs プロジェクト: xhute/Kooboo
        public object GetValue(string FieldName, string Lang = null)
        {
            if (FieldName == null)
            {
                return(null);
            }

            string lower = FieldName.ToLower();

            if (lower == "key")
            {
                return(this.UserKey);
            }
            else if (lower == "id")
            {
                return(this.Id);
            }


            MultilingualContent content = GetContentStore(Lang);

            if (content != null && content.FieldValues.ContainsKey(FieldName))
            {
                return(content.FieldValues[FieldName]);
            }


            else if (lower == "ProductTypeId")
            {
                return(this.ProductTypeId);
            }

            else if (lower == "online")
            {
                return(this.Online);
            }
            else if (lower == "lastmodify" || lower == "lastmodified")
            {
                return(this.LastModified);
            }


            foreach (var item in this.Contents)
            {
                if (item.FieldValues.ContainsKey(FieldName))
                {
                    return(item.FieldValues[FieldName]);
                }
            }

            return(null);
        }
コード例 #2
0
ファイル: Product.cs プロジェクト: xhute/Kooboo
        internal MultilingualContent GetContentStore(string Lang, bool createNew = false)
        {
            MultilingualContent content = null;

            if (!string.IsNullOrEmpty(Lang))
            {
                content = this.Contents.Find(o => o.Lang == Lang);
            }
            if (content == null && this.Contents.Count() > 0)
            {
                content = this.Contents.Find(o => string.IsNullOrEmpty(o.Lang));
            }

            if (content == null && this.Contents.Count() > 0 && !string.IsNullOrEmpty(Lang))
            {
                string lower = Lang.ToLower();
                if (lower.Length > 2)
                {
                    lower = lower.Substring(0, 2);
                }
                foreach (var item in this.Contents)
                {
                    if (item.Lang.ToLower().StartsWith(lower))
                    {
                        return(item);
                    }
                }
            }

            if (content == null)
            {
                if (createNew)
                {
                    content      = new MultilingualContent();
                    content.Lang = Lang;
                    this.Contents.Add(content);
                }
                else if (this.Contents.Count() > 0)
                {
                    return(this.Contents.First());
                }
            }
            return(content);
        }