コード例 #1
0
        public ArticleItem GetItemById(int id)
        {
            var key = string.Format("ArticleRepositoryGetItemById{0}", id);

            var article = new ArticleItem();

            if (!this.TryGetCache<ArticleItem>(out article, key))
            {
                var result = (from p in web365db.tblArticle
                              where p.ID == id
                              orderby p.ID descending
                              select p).FirstOrDefault();

                article = new ArticleItem()
                {
                    ID = result.ID,
                    TypeID = result.TypeID,
                    Title = result.Title,
                    TitleAscii = result.TitleAscii,
                    SEOTitle = result.SEOTitle,
                    SEODescription = result.SEODescription,
                    SEOKeyword = result.SEOKeyword,
                    DateCreated = result.DateCreated,
                    DateUpdated = result.DateUpdated,
                    Number = result.Number,
                    PictureID = result.PictureID,
                    Summary = result.Summary,
                    Detail = result.Detail,
                    IsShow = result.IsShow
                };

                this.SetCache(key, article, 10);
            }

            return article;
        }
コード例 #2
0
        public ArticleItem GetItemByNameAscii(string nameAscii, bool isShow = true, bool isDeleted = false)
        {
            var key = string.Format("ArticleRepositoryGetItemByNameAscii{0}{1}", nameAscii, LanguageId);

            var article = new ArticleItem();

            if (!this.TryGetCache<ArticleItem>(out article, key))
            {
                var result = (from p in web365db.tblArticle
                              where p.TitleAscii == nameAscii && p.tblTypeArticle.LanguageId == LanguageId && p.IsShow == isShow && p.IsDeleted == isDeleted
                              orderby p.ID descending
                              select p).FirstOrDefault();

                article = new ArticleItem()
                          {
                              ID = result.ID,
                              TypeID = result.TypeID,
                              Title = result.Title,
                              TitleAscii = result.TitleAscii,
                              SEOTitle = result.SEOTitle,
                              SEODescription = result.SEODescription,
                              SEOKeyword = result.SEOKeyword,
                              DateCreated = result.DateCreated,
                              DateUpdated = result.DateUpdated,
                              Number = result.Number,
                              PictureID = result.PictureID,
                              Summary = result.Summary,
                              Detail = result.Detail,
                              IsShow = result.IsShow,
                              ArticleType = new ArticleTypeItem()
                              {
                                  ID = result.tblTypeArticle.ID,
                                  Name = result.tblTypeArticle.Name,
                                  NameAscii = result.tblTypeArticle.NameAscii
                              },
                              ListPicture = result.tblPicture1.Select(p => new PictureItem()
                              {
                                  FileName = p.FileName
                              }).ToList()
                          };

                this.SetCache(key, article, 10);
            }

            return article;
        }