using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using _2._1.Sample.Models;
using Sample.Models;
using WebApplication3.Models;
using Kendo.Mvc.UI;
using Kendo.Mvc.Extensions;


namespace _2._1.Sample.Controllers
{
    public class HomeController : Controller
    {

        public static ICollection<Student> students = new List<Student>();
        public static List<string> names = new List<string> { "John", "Jane", "Jeremy", "James" };

        public HomeController()
        {

            var lastNames = new List<string> { "Hammont", "Clarkson", "May", "Hennethon" };
            var random = new Random();
            if (students.Count == 0)
            {
                for (int i = 1; i < 20; i++)
                {
                    students.Add(new Student
                    {
                        Age = random.Next(1, 20),
                        Birthday = new DateTime(random.Next(1950, 2018), random.Next(1, 12), random.Next(1, 27)),
                        FirstName = random.Next(1, 5),
                        LastName = lastNames[random.Next(0, 4)],
                        Id = i
                    });
                }
            }



        }

        public ActionResult Index()
        {
            var keyNames = new List<object>();

            for (int i = 0; i < names.Count; i++)
            {
                keyNames.Add(new { Id = i + 1, Name = names[i] });
            }

            ViewData["names"] = keyNames;

            return View();
        }



        public ActionResult GetStudents([DataSourceRequest] DataSourceRequest request)
        {

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

        public ActionResult EditStudent(Student student)
        {
            students.Add(student);
            return Json(student);
        }
    }
}
