Skip to content

Instantly share code, notes, and snippets.

View rofr's full-sized avatar

Robert Friberg rofr

View GitHub Profile
@rofr
rofr / gist:ca9a57cd79ed8ee4e1ba
Created September 17, 2014 04:11
Building a CMS with OrigoDB - snippet 6
[Serializable]
public class CmsModel : Model
{
private IDictionary<Guid, Page> _pages;
private Dictionary<string, Menu> _menus;
public CmsModel()
{
_pages = new Dictionary<Guid, Page>();
_menus = new Dictionary<string, Menu>();
@rofr
rofr / gist:b8d73a302d2ea08422b4
Created September 17, 2014 04:00
Building a CMS with OrigoDB - snippet 5
[ExpectedException(typeof(InvalidOperationException))]
[TestMethod()]
public void RemovePage_fails_unless_page_exists()
{
var target = new CmsModel();
target.RemovePage(Guid.NewGuid());
}
[TestMethod()]
@rofr
rofr / gist:d78202a17709e5d462d8
Created September 17, 2014 03:59
Building a CMS with OrigoDB - snippet 4
[Serializable]
public class RemovePageCommand : Command<CmsModel>
{
public readonly Guid PageId;
public RemovePageCommand(Guid pageId)
{
PageId = pageId;
}
@rofr
rofr / gist:90a1f6c2beab7fbc87da
Created September 17, 2014 03:58
Building a CMS with OrigoDB - snippet 3
[Serializable]
public class PutPageCommand : Command<CmsModel>
{
public readonly Page Page;
public PutPageCommand(Page page)
{
if (page == null) throw new ArgumentNullException("page");
Page = page;
@rofr
rofr / gist:a7e287063d23219af8bf
Created September 17, 2014 03:57
Building a CMS with OrigoDB - snippet 2
[Serializable]
public class CmsModel : Model
{
private IDictionary<Guid, Page> _pages;
public CmsModel()
{
_pages = new Dictionary<Guid, Page>();
}
@rofr
rofr / gist:d56cfe45a49b213ea879
Created September 17, 2014 03:56
Building a CMS with OrigoDB - snippet 1
[Serializable]
public class Page
{
public readonly Guid Id;
public readonly DateTime Created;
public string Title { get; set; }
public string Contents { get; set; }
public Page(Guid id, DateTime created)
[TestMethod()]
public void can_add_entity()
{
var engine = Engine.LoadOrCreate<MyRelationalModel>();
//Create the entity you want to insert
var category = new Category{ Name = "Beverages"};
//Create a generic command
var addCommand = new AddEntityCommand(category);
[Serializable]
public class MyRelationalModel : RelationalModel
{
public MyRelationalModel()
{
AddSetOf<Category>();
AddSetOf<User>();
AddSetOf<Task>();
}
}
[Serializable]
public class Category
{
public int Id { get; set; }
public string Name { get; set; }
}
[Serializable]
public class User
{
@rofr
rofr / gist:1ccb93d107d9ae16c7fd
Created September 17, 2014 03:17
OrigoDB document database example
public class Program
{
public static int CountCustomersQuery(Dictionary<object,object> docs)
{
return docs.OfType<Customer>().Count();
}
public static void Main(string[] args)
{
//Loads or creates a new database at the default location