using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using Kendo.Mvc.UI;
using Sample.Models;
using Kendo.Mvc.Extensions;

namespace Sample.Controllers
{
    public class GridController : Controller
    {
        public static List<OrderViewModel> orders = new List<OrderViewModel>();
        public GridController()
        {
            if (orders.Count == 0)
            {
                orders.Add(new OrderViewModel() { OrderID = 1, Tag_Property = Tag.Value1 });
                orders.Add(new OrderViewModel() { OrderID = 2, Tag_Property = Tag.Value2 });
                orders.Add(new OrderViewModel() { OrderID = 3, Tag_Property = Tag.Value3 });
            }
        }
        public ActionResult Orders_Read([DataSourceRequest]DataSourceRequest request)
        {
            var dsResult = orders.ToDataSourceResult(request);
            return Json(dsResult);
        }

        public ActionResult Orders_Update([DataSourceRequest]DataSourceRequest request, OrderViewModel order)
        {
            var dsResult = new[] { order}.ToDataSourceResult(request);
            return Json(dsResult);
        }
        public ActionResult Orders_Create([DataSourceRequest]DataSourceRequest request, OrderViewModel order)
        {
            //order.OrderID = orders.Count + 1;
            var dsResult = new[] { order }.ToDataSourceResult(request);
            return Json(dsResult);
        }

    }
}
