using System;
﻿using System.Collections.Generic;
using System.Linq;
using System.Web.Mvc;
using KendoUIApp3.Models;

namespace KendoUIApp3.Controllers
{
	public partial class GridController : Controller
    {
        public static List<OrderViewModel> orders = Enumerable.Range(1, 50).Select(i => new OrderViewModel
        {
            OrderID = i,
            Freight = i * 10,
            OrderDate = DateTime.Now.AddDays(i),
            ShipName = "ShipName " + i,
            ShipCity = "ShipCity " + i
        }).ToList();

        public ActionResult Orders_Read()
		{
			return Json(orders);
		}

        public ActionResult Orders_Create(OrderViewModel order)
        {
            order.OrderID = orders.Count + 1;

            return Json(new []{ order });
        }

        [HttpPut]
        public ActionResult Orders_Update(OrderViewModel order)
        {
            for (int i = 0; i < orders.Count; i++)
            {
                if (orders[i].OrderID == order.OrderID) {
                    orders[i] = order;
                }
            }

            return Json(new []{ order });
        }
    }
}