using Kendo.Mvc.Extensions;
using Kendo.Mvc.UI;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.Filters;
using System.Globalization;

namespace TelerikAspNetCoreApp10.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();
        }

        [HttpPost]
        public JsonResult Read(string target)
        {
            var entries = new List<FileManagerEntry>();

            entries.Add(new FileManagerEntry
            {
                Name = "TestFile.txt",
                Path = "TestFile.txt",
                Size = 1024,
                IsDirectory = false,
                Extension = ".txt"   
            });

            return Json(entries);
        }

        public ActionResult Destroy([DataSourceRequest] DataSourceRequest request, FileManagerEntry entry)
        {
            ModelState.AddModelError("delete", "This folder is mapped in the database and cannot be deleted.");

            return Json(new[] { entry }.ToDataSourceResult(request, ModelState));
        }

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

            return View();
        }

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

            return View();
        }
    }
}
