示例#1
0
        /// <summary>
        /// Get an individual category based on a provided id
        /// </summary>
        /// <param name="categoryId">Category id</param>
        /// <returns>Details about the Category</returns>
        public CategoryInfo GetCategory(string categoryId)
        {
            MSPetShop4DataContext db = new MSPetShop4DataContext();
            var category = db.Categories.Single(c => c.Id == categoryId);

            return category;
        }
示例#2
0
        /// <summary>
        /// Query for a product
        /// </summary>
        /// <param name="productId">Product Id</param>
        /// <returns>ProductInfo object for requested product</returns>
        public ProductInfo GetProduct(string productId)
        {
            MSPetShop4DataContext db = new MSPetShop4DataContext();

            var product = db.Products.Single(p => p.Id == productId);

            return product;
        }
示例#3
0
        /// <summary>
        /// Method to get all categories
        /// </summary>	    	 
        public IList<CategoryInfo> GetCategories()
        {
            MSPetShop4DataContext db = new MSPetShop4DataContext();
            IEnumerable<CategoryInfo> categories = from c in db.Categories
                                                   select c;

            return categories.ToList<CategoryInfo>();
        }
示例#4
0
        /// <summary>
        /// Query for products by category
        /// </summary>
        /// <param name="category">category name</param>  
        /// <returns>A Generic List of ProductInfo</returns>
        public IList<ProductInfo> GetProductsByCategory(string category)
        {
            MSPetShop4DataContext db = new MSPetShop4DataContext();

            IEnumerable<ProductInfo> products = from p in db.Products
                                                where p.Category.Id == category
                                                select p;
            return products.ToList<ProductInfo>();
        }
示例#5
0
        /// <summary>
        /// Get Product List
        /// </summary>
        /// <param name="category">Category Id</param>
        /// <returns></returns>
        public SyndicationFeedFormatter GetProducts(string category)
        {
            Uri uri = GetRootUri();
            SyndicationFeed feed = new SyndicationFeed(
                Resource.FeedTitle,
                Resource.FeedContent,
                uri
                );

            MSPetShop4DataContext db = new MSPetShop4DataContext();

            IEnumerable<SyndicationItem> items = from p in db.Products
                         where p.Category.Id == category
                         orderby p.Id descending
                         select CreateSyndicationItem(p, uri, category);

            feed.Items = items.Take(10);
            return new Rss20FeedFormatter(feed);
        }