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

namespace GridDetailsWithSharedDataSource.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,
				ShipName = "ShipName " + i,
				ShipCity = "ShipCity " + i
			});

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

        public ActionResult OrdersDetails_Read([DataSourceRequest]DataSourceRequest request, int orderID)
        {
            var result = Enumerable.Range(1, 5).Select(i => new OrderDetailViewModel
            {
                OrderID = orderID,
                OrderDate = DateTime.Now.AddDays(i),
                ClientName = "Client " + orderID
            });

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