namespace GridPopUpEditing.Controllers
{
    using System;
    using System.Linq;
    using Kendo.Mvc.UI;
    using Kendo.Mvc.Extensions;
    using GridPopUpEditing.Models;
    using Microsoft.AspNetCore.Mvc;
    public class GridController : Controller
    {
        public ActionResult LoadPopup([FromBody]OrderViewModel model)
        {
            return PartialView("MyNewCustomPopup", model);
        }
        public ActionResult Orders_Read([DataSourceRequest] DataSourceRequest request)
        {
            var result = Enumerable.Range(1, 50).Select(i => new OrderViewModel
            {
                OrderID = i,
                Freight = i * 10,
                OrderDate = new DateTime(2016, 9, 15).AddDays(i % 7),
                ShipName = "ShipName " + i,
                ShipCity = "ShipCity " + i,
                Discontinued = i % 2 == 0 ? true : false
            }) ;

            var dsResult = result.ToDataSourceResult(request);
            return Json(dsResult);
        }
        [AcceptVerbs("Post")]
        public IActionResult Orders_Update([DataSourceRequest] DataSourceRequest request, OrderViewModel order)
        {
            //update 
            return Json(new[] { order }.ToDataSourceResult(request, ModelState));
        }
        [AcceptVerbs("Post")]
        public IActionResult Orders_Create([DataSourceRequest] DataSourceRequest request, OrderViewModel order)
        {
            //create 
            return Json(new[] { order }.ToDataSourceResult(request, ModelState));
        }
        [AcceptVerbs("Post")]
        public IActionResult Orders_Destroy([DataSourceRequest] DataSourceRequest request, OrderViewModel order)
        {
            //delete 
            return Json(new[] { order }.ToDataSourceResult(request, ModelState));
        }
    }
}
