using Kendo.Mvc.Extensions;
using Kendo.Mvc.UI;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.Filters;
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Threading.Tasks;
using TestGridDateTimeEditor.Models;

namespace TestGridDateTimeEditor.Controllers
{
    public class HomeController : Controller
    {

        public override void OnActionExecuting(ActionExecutingContext context)
        {
            if (!string.IsNullOrEmpty(context.HttpContext.Request.Query["culture"]))
            {
                CultureInfo.DefaultThreadCurrentCulture = CultureInfo.DefaultThreadCurrentUICulture = new CultureInfo(context.HttpContext.Request.Query["culture"]);
            }
            base.OnActionExecuting(context);
        }

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

        public IActionResult About()
        {
            ViewData["Message"] = "Your application description page.";

            return View();
        }

        public IActionResult Contact()
        {
            ViewData["Message"] = "Your contact page.";

            return View();
        }

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

        public ActionResult ReadCakes([DataSourceRequest] DataSourceRequest request)
        {
            var Cakes = new List<Cake>();

            Cakes.Add(new Cake { Id = 1, Name = "Chocolate", Expiry = null });
            Cakes.Add(new Cake { Id = 2, Name = "Vanilla", Expiry = DateTime.Now.AddDays(47) });
            Cakes.Add(new Cake { Id = 3, Name = "Tiramisu", Expiry = DateTime.Now.AddDays(12) });

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