Skip to content

Instantly share code, notes, and snippets.

View PaulStovell's full-sized avatar

Paul Stovell PaulStovell

View GitHub Profile
public class InMemoryDataContext : IDataContext
{
static int lastId;
readonly IList<object> entities;
public InMemoryDataContext(params object[] preexistingEntities)
{
entities = preexistingEntities.ToList();
SaveChanges();
}
// GET: /Projects/Show/13
public ActionResult Show(int id)
{
var project = DataContext.Set<Project>()
.Include("Steps")
.Include("Steps.Destinations")
.Include("Releases")
.Include("Releases.Deployments")
.Where(p => p.Id == id)
.FirstOrDefault();
using System;
using System.Collections.Generic;
using System.ComponentModel.Composition;
using System.ComponentModel.Composition.Hosting;
using System.Linq;
using System.Text;
namespace MefDemo
{
class Program
using System;
using System.Collections.Generic;
using System.Runtime.InteropServices;
namespace TaskOverlapped
{
class Program
{
static void Main(string[] args)
{
@PaulStovell
PaulStovell / Permissions.cs
Created March 27, 2012 11:58
A permissions model
using System;
using System.Collections.Generic;
using System.Linq;
using NUnit.Framework;
namespace Auth
{
[TestFixture]
public class RuleSetFixture
{
@PaulStovell
PaulStovell / Group.cs
Created March 31, 2012 11:15
Hierarchies in RavenDB
public class Group
{
public Group()
{
Users = new List<string>();
ChildGroups = new List<string>();
}
public string Id { get; set; }
public string Name { get; set; }
public class UsersInGroups : AbstractMultiMapIndexCreationTask<UsersInGroups.Result>
{
public UsersInGroups()
{
AddMap<Group>(groups => from g in groups
from user in g.Users
select new Result { UserId = user, GroupId = g.Id, Parents = new string[0] });
AddMap<GroupTree>(tree => from t in tree
from g in t.Lineages
@PaulStovell
PaulStovell / License.cs
Created April 1, 2012 20:16
FastSpring license generation validation
public void Validate(HttpRequestBase request)
{
var providedHash = request.Form["security_request_hash"];
if (string.IsNullOrWhiteSpace(providedHash))
throw new HttpRequestValidationException("Expected a value for 'security_request_hash'.");
var pairs =
from key in request.Form.AllKeys
let value = request.Form[key]
where key != "security_request_hash"
@PaulStovell
PaulStovell / Edit.cshtml
Created April 13, 2012 19:19
How can I clean up this simple ASP.NET MVC pattern?
@model EditUserModel
@using (Html.BeginForm())
{
<div>
@Html.HiddenFor(m => m.Id)
@Html.TextBoxFor(m => m.FirstName)
@Html.TextBoxFor(m => m.LastName)
@Html.DropDownListFor(m => m.CountryId, Model.Countries.Select(c => new SelectListItem { Value = c.Id, Text = c.Name })
@model EditUserModel
@using (Html.BeginForm())
{
<div>
@Html.HiddenFor(m => m.Id)
@Html.TextBoxFor(m => m.FirstName)
@Html.TextBoxFor(m => m.LastName)
@Html.DropDownListFor(m => m.CountryId, Model.Countries)