コード例 #1
0
        public SyndicationFeed GetRssViewModel()
        {
            var items    = new List <SyndicationItem>();
            var products =
                from p in Database.Products
                select new
            {
                p.Id, p.Name, p.QuantityPerUnit, p.UnitPrice, CategoryName = p.Category.Name, CategoryId = p.CategoryID
            }

            ;

            foreach (var p in products)
            {
                var contentString = string.Format("Quantity per unit: {0} - Unit Price: {1:0.00}", p.QuantityPerUnit, p.UnitPrice);
                var content       = new TextSyndicationContent(contentString);
                var item          = new SyndicationItem();
                item.Categories.Add(new SyndicationCategory(p.CategoryName));
                item.Title           = new TextSyndicationContent(p.Name, TextSyndicationContentKind.Plaintext);
                item.BaseUri         = new Uri(UrlBuilder.BuildProductPageUrl(p.Id, p.Name), UriKind.Relative);
                item.LastUpdatedTime = DateTime.Now;
                item.Summary         = content;
                item.Content         = content;
                items.Add(item);
            }

            var feed = new SyndicationFeed(items);

            feed.Title           = new TextSyndicationContent("NSK Online Store product catalog");
            feed.LastUpdatedTime = DateTime.Now;
            return(feed);
        }