using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.Text;
using System.ServiceModel.Activation;
using Telerik.Web.UI;

[DataContract]
public class Product
{
    [DataMember]
    public int ProductID { get; set; }
    [DataMember]
    public string ProductName { get; set; }
    [DataMember]
    public decimal? UnitPrice { get; set; }
    [DataMember]
    public short? ReorderLevel { get; set; }
    [DataMember]
    public bool Discontinued { get; set; }
}

public class ResultData
{
    public int Count { get; set; }
    public List<Product> Data { get; set; }
}

[ServiceKnownType(typeof(Product))]
[ServiceContract]
[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
public class Service
{
   [OperationContract]
    public ResultData GetDataAndCount(int startRowIndex, int maximumRows, string sortExpression, string filterExpression)
    {
        GridBindingData data = RadGrid.GetBindingData("LinqToSql.NorthwindDataContext", "Products", startRowIndex, maximumRows, sortExpression, filterExpression);
        ResultData result = new ResultData();

        result.Data = data.Data.OfType<LinqToSql.Product>().Select(p => new Product()
            {ProductID = p.ProductID, ProductName = p.ProductName, UnitPrice = p.UnitPrice,
                ReorderLevel = p.ReorderLevel, Discontinued = p.Discontinued}).ToList();
        result.Count = data.Count;
        return result;
    }
   [OperationContract]
   public ResultData Test(int startRowIndex, int maximumRows, string sortExpression, string filterExpression)
   {
       GridBindingData data = RadGrid.GetBindingData("LinqToSql.NorthwindDataContext", "Products", startRowIndex, 3, sortExpression, filterExpression);
       ResultData result = new ResultData();

       result.Data = data.Data.OfType<LinqToSql.Product>().Select(p => new Product()
       {
           ProductID = p.ProductID,
           ProductName = p.ProductName,
           UnitPrice = p.UnitPrice,
           ReorderLevel = p.ReorderLevel,
           Discontinued = p.Discontinued
       }).ToList();
       result.Count = data.Count;
       return result;
   }
}
