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

namespace NetMagazine_MVC3_Parte3.Controllers
{
    public class OutputCacheController : Controller
    {
        public ActionResult Index()
        {
            return View();
        }

        [OutputCache(Duration = 10, VaryByParam = "none")]
        public string ObterDataHora()
        {
            return DateTime.Now.ToString();
        }

        [OutputCache(Duration = 20, VaryByParam = "postId")]
        public PartialViewResult VerPost(int postId)
        {
            var post = new Post("Título " + postId.ToString(), DateTime.Now, "Cached");
            return PartialView(post);
        }

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

        public class Post
        {
            public Post(string title, DateTime published, string body)
            {
                this.Body = body;
                this.Published = published;
                this.Title = title;
            }

            public string Body { get; private set; }

            public DateTime Published { get; private set; }

            public string Title { get; private set; }
        }
    }
}
