using System.Collections.Generic;
using System.Web.Mvc;
using Telerik.Web.Mvc;
using TelerikAjaxTest.Models;

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

            return View();
        }

        [GridAction]
        public ActionResult _GetWidgets()
        {
            return View("Index", new GridModel<Widget>(GetWidgetsList()));
        }

        [GridAction]
        public ActionResult _SaveWidget(Widget w)
        {
            // Intentionally empty to test AJAX calls
            return _GetWidgets();
        }

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

        private List<Widget> GetWidgetsList()
        {
            var widgetList = new List<Widget>{
                new Widget{
                    WidgetId = 1,
                    WidgetDescription = "Thingamabob"
                },
                new Widget{
                    WidgetId = 2,
                    WidgetDescription = "Thingamajingy"
                }
            };

            return widgetList;
        }
    }
}