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

namespace AjaxTestMvc.Controllers {

    public class HomeController : Controller {

        private AjaxTestMvc.Models.Person person;

        public ActionResult Index() {
            ViewBag.Message = DateTime.Now.ToLocalTime();
            return View();
        }

        public ActionResult About() {
            ViewBag.Message = "Your app description page.";
            return View();
        }

        public ActionResult Contact() {
            ViewBag.Message = "Your contact page.";
            return View();
        }

        public ActionResult Person() {
            return View(person);
        }

        [HttpPost]
        public ActionResult Person(AjaxTestMvc.Models.Person person, string url) {

            person.FirstName += " - POSTED";
            return new AjaxTestMvc.App_Start.TransferResult("Person");

        }

        public JsonResult JsonPerson() {
            AjaxTestMvc.Models.Person p = new Models.Person { FirstName = "Marco", LastName = "Baccaro" };
            return this.Json(p, JsonRequestBehavior.AllowGet);
        }

        public RedirectResult GoGoogle() {
            //ViewResult, RedirectResult, JsonResult, FileResult, JavaScriptResult, ContentResult            
            return new RedirectResult("http://www.google.com");
        }

        public JavaScriptResult Js() {
            //var obj = eval('(' + msg + ')');
            return JavaScript("alert('Marco')");
        }

    }

}