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

namespace TreeListResizeAndExpand.Controllers
{
    public class EmployeeModel
    {
        public int EmployeeId { get; set; }
        public string FirstName { get; set; }
        public int? ReportsTo { get; set; }
    }

    public class HomeController : Controller
    {
        public ActionResult Index()
        {
            return View();
        }


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

        public JsonResult Read([DataSourceRequest] DataSourceRequest request, string user)
        {
            var viewModel = new List<EmployeeModel>();

            for (int i = 0; i < 100; i++)
            {
                var model = new EmployeeModel();
                model.EmployeeId = i;
                model.FirstName = "John" + 1;
                model.ReportsTo = null;

                if (i == 0)
                {
                    model.ReportsTo = null;
                }
                else
                {
                    model.ReportsTo = i - 1;
                }
                viewModel.Add(model);
            }

            return Json(viewModel.ToTreeDataSourceResult(request));
        }
    }
}
