Skip to content

Instantly share code, notes, and snippets.

@Cacodaimon
Created October 2, 2012 19:30
Show Gist options
  • Save Cacodaimon/3822750 to your computer and use it in GitHub Desktop.
Save Cacodaimon/3822750 to your computer and use it in GitHub Desktop.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Web.Mvc.Ajax;
using System.Web.Routing;
using MongoDB.Driver;
using MongoDB.Bson;
namespace Blog
{
public class BlogController : Controller
{
//[OutputCache(Duration = 30, VaryByParam = "None")]
public ActionResult Index ()
{
return View(Article.FindMany(new QueryDocument()));
}
public ActionResult ShowArticle (string id)
{
return View(Article.Find(id));
}
public ActionResult AddComment ()
{
string id = Request.Params.Get("Id");
string autor = Request.Params.Get("Autor");
string text = Request.Params.Get("Text");
Article article;
try
{
if ((article = Article.Find(id)) == null)
{
return RedirectToAction("Index", "Blog");
}
}
catch (FormatException exception)
{
return RedirectToAction("Index", "Blog");
}
article = Article.Find(id);
article.Comments.Add(new Comment() {
Autor = autor,
Text = text,
Date = new BsonDateTime(DateTime.Now)
});
article.Save();
return RedirectToAction("ShowArticle", "Blog", new RouteValueDictionary(new { id = id }));
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment