Created
October 2, 2012 19:30
-
-
Save Cacodaimon/3822750 to your computer and use it in GitHub Desktop.
Used in: http://cacodaemon.de/index.php?id=16
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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