- ScrollingSample.zip
- ScrollingSample
- packages
- AspNetWebApi.4.0.20505.0
- AspNetWebApi.4.0.20505.0.nupkg
- jQuery.1.7.2
- Content
- Scripts
- jQuery.1.7.2.nupkg
- Tools
- Microsoft.AspNet.WebApi.4.0.20505.0
- Microsoft.AspNet.WebApi.4.0.20505.0.nupkg
- Microsoft.AspNet.WebApi.Client.4.0.20505.0
- lib
- net40
- Microsoft.AspNet.WebApi.Client.4.0.20505.0.nupkg
- Microsoft.AspNet.WebApi.Core.4.0.20505.0
- lib
- net40
- Microsoft.AspNet.WebApi.Core.4.0.20505.0.nupkg
- Microsoft.AspNet.WebApi.WebHost.4.0.20505.0
- lib
- net40
- Microsoft.AspNet.WebApi.WebHost.4.0.20505.0.nupkg
- Microsoft.Net.Http.2.0.20505.0
- lib
- net40
- Microsoft.Net.Http.2.0.20505.0.nupkg
- Microsoft.Web.Infrastructure.1.0.0.0
- lib
- net40
- Microsoft.Web.Infrastructure.dll
- Microsoft.Web.Infrastructure.1.0.0.0.nupkg
- Newtonsoft.Json.4.5.7
- lib
- net20
- net35
- net40
- sl3-wp
- sl4
- sl4-windowsphone71
- winrt45
- Newtonsoft.Json.4.5.7.nupkg
- repositories.config
- ScrollingSample.sln
- ScrollingSample.suo
- ScrollingSample
- ScrollingSample-noexe.zip
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Xml.Linq;
using ScrollingSample.Data;
using System.Web.Http;
namespace ScrollingSample.Controllers
{
public class ProductController : ApiController
{
NorthWindDataContext _context = new NorthWindDataContext();
/// <summary>
/// Gets the specified page size.
/// </summary>
/// <param name="pageSize">Size of the page.</param>
/// <param name="currentPage">The current page.</param>
/// <param name="mode">The mode.</param>
/// <returns></returns>
public List<Model.Product> Get()
{
List<Model.Product> products = new List<Model.Product>();
products = (from e in _context.Products
select new Model.Product
{
ProductID = e.ProductID,
ProductName = e.ProductName,
SupplierName = e.Supplier.CompanyName,
CategoryName = e.Category.CategoryName,
UnitPrice = Convert.ToDecimal(e.UnitPrice)
}).ToList();
return products;
}
/// <summary>
/// Gets the specified page size.
/// </summary>
/// <param name="pageSize">Size of the page.</param>
/// <param name="currentPage">The current page.</param>
/// <param name="mode">The mode.</param>
/// <returns></returns>
public List<Model.Product> GetProductsByPage(int pageSize, int currentPage, string mode)
{
List<Model.Product> products = new List<Model.Product>();
if (string.Equals("XML", mode, StringComparison.OrdinalIgnoreCase)) //if XML
{
string xmlPath = HttpContext.Current.Server.MapPath(@"/Data/Product.xml");
XElement xml = XElement.Load(xmlPath);
products = xml.Descendants("Product")
.Select(e => new Model.Product
{
ProductID = Convert.ToInt32(e.Descendants("ProductID").FirstOrDefault().Value),
ProductName = e.Descendants("ProductName").FirstOrDefault().Value,
SupplierName = e.Descendants("SupplierName").FirstOrDefault().Value,
CategoryName = e.Descendants("CategoryName").FirstOrDefault().Value,
UnitPrice = Convert.ToDecimal(e.Descendants("UnitPrice").FirstOrDefault().Value)
}).Skip(pageSize * currentPage).Take(pageSize).ToList();
}
else //if SQL
{
products = (from e in _context.Products
select new Model.Product
{
ProductID = e.ProductID,
ProductName = e.ProductName,
SupplierName = e.Supplier.CompanyName,
CategoryName = e.Category.CategoryName,
UnitPrice = Convert.ToDecimal(e.UnitPrice)
}).Skip(pageSize * currentPage).Take(pageSize).ToList();
}
return products;
}
}
}
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.
9+ plus years of experience in IT industry. This includes experience in architecting, designing and developing solutions on Web and desktop application platforms