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
defaults: &defaults | |
autocreate_indexes: true | |
max_retries_on_connection_failure: 3 | |
allow_dynamic_fields: false | |
development: | |
host: localhost | |
database: taq_development |
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
namespace mongohq_csharp.Models.DTO | |
{ | |
public class DeveloperDTO | |
{ | |
public BsonObjectId id { get; set; } | |
public string name { get; set; } | |
public string languages { get; set; } | |
public string company { get; set; } | |
} | |
} |
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.Collections.Generic; | |
using mongohq_csharp.Models.DTO; | |
namespace mongohq_csharp.Models | |
{ | |
public class DeveloperModel | |
{ | |
public IList<DeveloperDTO> developers { get; set; } | |
} | |
} |
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.Collections.Generic; | |
using mongohq_csharp.Models.DTO; | |
namespace mongohq_csharp.Models | |
{ | |
public class DeveloperModel | |
{ | |
public IList<DeveloperDTO> developers { get; set; } | |
} | |
} |
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
<connectionStrings> | |
<add name="ApplicationServices" | |
connectionString="data source=.\SQLEXPRESS;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|aspnetdb.mdf;User Instance=true" | |
providerName="System.Data.SqlClient" /> | |
<add name="MongoHQ" | |
connectionString="your mongo uri"/> | |
</connectionStrings> |
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
public class DeveloperController : Controller | |
{ | |
readonly MongoDatabase mongo_db; | |
public DeveloperController() | |
{ | |
mongo_db = retreive_mongohq_db(); | |
} | |
} |
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
static MongoDatabase retreive_mongohq_db() | |
{ | |
return MongoServer.Create( | |
ConfigurationManager.ConnectionStrings["MongoHQ"].ConnectionString) | |
.GetDatabase("t2"); | |
} |
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.Linq; | |
using System.Web.Mvc; | |
using System.Configuration; | |
using MongoDB.Driver; | |
using mongohq_csharp.Models; | |
using mongohq_csharp.Models.DTO; | |
namespace mongohq_csharp.Controllers | |
{ | |
public class DeveloperController : Controller |
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
<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage<mongohq_csharp.Models.DeveloperModel>" %> | |
<asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server"> | |
Index | |
</asp:Content> | |
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server"> | |
<h2>Developers</h2> |
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
public ActionResult Index() | |
{ | |
var model = new DeveloperModel(); | |
var developers_collection = mongo_db.GetCollection("developers").FindAll().AsEnumerable(); | |
model.developers = (from developer in developers_collection | |
select new DeveloperDTO | |
{ | |
id = developer["_id"].AsObjectId, | |
name = developer["name"].AsString, |
OlderNewer