本文整理汇总了C#中MongoServer.FindOne方法的典型用法代码示例。如果您正苦于以下问题:C# MongoServer.FindOne方法的具体用法?C# MongoServer.FindOne怎么用?C# MongoServer.FindOne使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MongoServer
的用法示例。
在下文中一共展示了MongoServer.FindOne方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: EditUser
public ActionResult EditUser(string key)
{
MongoCollection<User> userColl = new MongoServer().GetDatabase("MongoWiki").GetCollection<User>("User");
User user = userColl.FindOne(new { UserName = key });
return View("EditUser", user);
}
示例2: EditPage
public ActionResult EditPage(string page)
{
page = Utility.ScrubPageUrl(page);
MongoCollection<WikiPage> pages = new MongoServer().GetDatabase("MongoWiki").GetCollection<WikiPage>("WikiPage");
WikiPage wikiPage = pages.FindOne(new { URL = page });
// If the page isn't found, lets create it
if (wikiPage == null)
return this.RedirectToAction("CreatePage", new { page = page });
else
return View("EditWikiPage", wikiPage);
}
示例3: ViewPage
public ActionResult ViewPage(string page)
{
page = Utility.ScrubPageUrl(page);
MongoCollection<WikiPage> pages = new MongoServer().GetDatabase("MongoWiki").GetCollection<WikiPage>("WikiPage");
WikiPage wikiPage = pages.FindOne(new { URL = page });
// If the page isn't found, lets create it
if (wikiPage == null)
return this.RedirectToAction("CreatePage", new { page = page });
else
{
// If the page is found, let's parse it for auto-links
StringBuilder sb = new StringBuilder(wikiPage.Body);
List<KeyValuePair<string,string>> links = Utility.ParseWordLinks(wikiPage.Body);
foreach (KeyValuePair<string, string> link in links)
{
string format = "<a href=\"/wiki/{0}\">{1}</a>";
// While parsing, let's see if the page exists already
WikiPage checkPage = pages.FindOne(new { URL = link.Value });
// If not, we'll format the link and point it at the create page
if (checkPage == null)
format = "<a href=\"/wiki/create/{0}\" class=\"newlink\" title=\"This page does not exist. Click here to create it!\"><font color=\"red\">{1}</font></a>";
else
format = "<a href=\"/wiki/{0}\" title=\"" + checkPage.Body.Substring(0, (checkPage.Body.Length >= 30 ? 30 : checkPage.Body.Length)) + "...\">{1}</a>";
sb.Replace(link.Key, string.Format(format, link.Value, link.Key));
}
// Converty crlf's to <br>'s
sb.Replace("\n", "<br/>");
// Set it back to the model
wikiPage.Body = sb.ToString();
return View("ViewWikiPage", wikiPage);
}
}