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

namespace Grid_Basic_MVC.Controllers
{
	public partial class GridController : Controller
    {
		public ActionResult Orders_Read([DataSourceRequest]DataSourceRequest request)
		{
            var result = Enumerable.Range(1, 600).Select(i => new OrderViewModel
            {
                OrderID = i,
                Freight = i * 10,
                ShipName = "ShipName " + i,
                ShipCity = "ShipCity " + i,
                IsActive = i%2 == 0 ? true: false

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

        [AcceptVerbs(HttpVerbs.Post)]
        public ActionResult Orders_Create([DataSourceRequest] DataSourceRequest request, OrderViewModel orders)
        {          

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

        [AcceptVerbs(HttpVerbs.Post)]
        public ActionResult Orders_Update([DataSourceRequest] DataSourceRequest request, OrderViewModel orders)
        {

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

    }
}
