using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using TelerikMvcApplication1.Models;
using Telerik.Web.Mvc;

namespace TelerikMvcApplication1.Controllers
{
    public class HomeController : Controller
    {
        public ActionResult Index()
        {
            ViewBag.Message = "Welcome to ASP.NET MVC!";

            return View();
        }

        public ActionResult About()
        {
            return View();
        }

        public ActionResult Queue()
        {
            var viewModel = this.BuildViewModel2();

            return View(viewModel);
        }

        [GridAction(EnableCustomBinding = true, GridName = "QueueGrid")]
        public ActionResult QueueCustomBinding(GridCommand gridCommand)
        {
            // gridCommand is NOT populated when the query string parameters are QueueGrid-size=2&QueueGrid-page=3
            // gridCommand is populated when the query string parameters are size=2&page=3

            // The paging links are rendered with query string parameters are QueueGrid-size and QueueGrid-page

            var viewModel = this.BuildViewModel2();

            return View("Queue", viewModel);
        }

        public ViewModel2 BuildViewModel2()
        {
            var viewModel2 = new ViewModel2();

            viewModel2.ViewModel1List.Add(new ViewModel1 { ID = 1, Name = "Name1", Description = "Description1" });
            viewModel2.ViewModel1List.Add(new ViewModel1 { ID = 2, Name = "Name2", Description = "Description2" });
            viewModel2.ViewModel1List.Add(new ViewModel1 { ID = 3, Name = "Name3", Description = "Description3" });
            viewModel2.ViewModel1List.Add(new ViewModel1 { ID = 4, Name = "Name4", Description = "Description4" });
            viewModel2.ViewModel1List.Add(new ViewModel1 { ID = 5, Name = "Name5", Description = "Description5" });

            viewModel2.PageSize = 2;
            viewModel2.TotalCount = viewModel2.ViewModel1List.Count;

            return viewModel2;
        }
    }
}
