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

namespace TelerikMvcApp27.Controllers
{
    public partial class GridController : Controller
    {

        public ActionResult Orders_Read([DataSourceRequest]DataSourceRequest request)
        {
            var result = Enumerable.Range(1, 50).Select(i => new OrderViewModel
            {
                OrderID = i,
                Freight = i * 10,
                OrderDate = DateTime.Now.AddDays(i),
                Shipment = new ShipmentInfo()
                {
                    ShipName = "ShipName " + i,
                    ShipCity = "ShipCity " + i,
                    ShipCountry = "ShipCountry " + i
                }
            });

            return Json(result.ToDataSourceResult(request), JsonRequestBehavior.AllowGet);

        }

        [AcceptVerbs(HttpVerbs.Post)]
        public ActionResult Editing_Create([DataSourceRequest] DataSourceRequest request, [Bind(Prefix = "models")]IEnumerable<OrderViewModel> products)
        {
            var results = new List<OrderViewModel>();

            if (products != null && ModelState.IsValid)
            {
            }

            return Json(results.ToDataSourceResult(request, ModelState));
        }

        [AcceptVerbs(HttpVerbs.Post)]
        public ActionResult Editing_Update([DataSourceRequest] DataSourceRequest request, [Bind(Prefix = "models")]IEnumerable<OrderViewModel> products)
        {
            if (products != null && ModelState.IsValid)
            {
            }

            return Json(products.ToDataSourceResult(request, ModelState));
        }

        [AcceptVerbs(HttpVerbs.Post)]
        public ActionResult Editing_Destroy([DataSourceRequest] DataSourceRequest request, [Bind(Prefix = "models")]IEnumerable<OrderViewModel> products)
        {
            if (products.Any())
            {
            }

            return Json(products.ToDataSourceResult(request, ModelState));
        }
    }
}
