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

namespace VirtualScrolling.Controllers
{
    public class VirtualScrollingController : Controller
    {
        private const int Pages = 250;
        private const int PageSize = 100;

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

        public ActionResult VirtualScrolling_Read([DataSourceRequest] DataSourceRequest request, string FilterBy)
        {
            var data = new List<VirtualScrollingModel>();

            for (var i = 0; i < Pages * PageSize; i++)
            {
                data.Add(new VirtualScrollingModel{Id = i, Title = string.Format("Title {0:D5}", i)});
            }

            if (FilterBy != null)
            {
                data = data.Where(m => m.Title.Contains(FilterBy)).ToList();
            }

            return Json(data.ToDataSourceResult(request));
        }
    }
}
