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

namespace DropDownTreeEditorDefaultValue.Controllers
{
    public partial class GridController : Controller
    {
        public ActionResult Orders_Read([DataSourceRequest]DataSourceRequest request)
        {
            var result = Enumerable.Range(1, 5).Select(i => new OrderViewModel
            {
                OrderID = i,
                ShipName = "ShipName " + i,
                Employee = new Employee() { EmployeeID = i, EmployeeName = "Employee " + i}

            });

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

        public ActionResult Update([DataSourceRequest]DataSourceRequest request, OrderViewModel model)
        {
            return Json(new List<OrderViewModel>() { model }.ToDataSourceResult(request));
        }

        private List<Employee> GetEmployees()
        {

            return GetEmployeeList();
        }

        public List<Employee> GetEmployeeList()
        {
            List<Employee> employees = new List<Employee>()
            {
                new Employee(){EmployeeID=1,OrderID=1,EmployeeName="aa"},
                new Employee(){EmployeeID=2,OrderID=1,EmployeeName="bb"},
                new Employee(){EmployeeID=3,OrderID=2,EmployeeName="cc"},
                new Employee(){EmployeeID=4,OrderID=3,EmployeeName="dd"},
                new Employee(){EmployeeID=5,OrderID=4,EmployeeName="ff"},
                new Employee(){EmployeeID=6,OrderID=4,EmployeeName="gg"},

            };

            return employees;
        }
    }
}
