using System.Collections.Generic;
using System.Web.Mvc;
using TelerikMVC3Test.Models;

namespace TelerikMVC3Test.Controllers
{
    public class HomeController : Controller
    {
        public ActionResult Index()
        {
            this.PopulateViewData();
            return View( new SettingsViewModel() );
        }

        [HttpPost]
        public ActionResult Index( SettingsViewModel model )
        {
            if( !ModelState.IsValid )
            {
                this.PopulateViewData();
                return PartialView( "_IndexPartial", model );
            }
            return Json( new { Success = true }, JsonRequestBehavior.AllowGet );
        }

        private void PopulateViewData()
        {
            var timeUnits = new Dictionary<int, string>
            {
                { 0, "---Select---" },
                { 1, "Day" },
                { 2, "Month" }
            };
            ViewBag.TimeUnits = timeUnits;
        }
    }
}
