using Kendo.Mvc.UI;
using Kendo.Mvc.Extensions;
using KendoGridClientDetailTemplate.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace KendoGridClientDetailTemplate.Controllers
{
    public class HomeController : Controller
    {
        static List<Product> products = new List<Product>();

        static HomeController()
        {
            for (int i = 1; i < 100; i++)
            {
                products.Add(new Product()
                {
                    ProductID = i,
                    ProductName = "Product" + i
                });
            }
        }

        public ActionResult Index()
        {
            return View();
        }

        public ActionResult TabOnePartial()
        {
            return PartialView("TabOnePartial", products);
        }

        public ActionResult TabTwoPartial()
        {
            return PartialView();
        }

        public ActionResult Read([DataSourceRequest] DataSourceRequest request)
        {
            return Json(products.ToDataSourceResult(request), JsonRequestBehavior.AllowGet);
        }


        public ActionResult Products_Read([DataSourceRequest]DataSourceRequest request)
        {
            using (var northwind = new NorthwindEntities())
            {
                IQueryable<Product> products = northwind.Products;
                DataSourceResult result = products.ToDataSourceResult(request);
                return Json(result);
            }
        }
    }
}
