Skip to content

Instantly share code, notes, and snippets.

namespace MvcApplication.Database
{
public class MyAppContext : DbContext
{
public DbSet<CordBloodUnit> CordBloodUnits { get; set; }
}
}
namespace MvcApplication1.Models
{
public class CordBloodUnit
{
public int ID { get; set; }
public int HLA_A1 { get; set; }
public int HLA_A2 { get; set; }
public int HLA_B1 { get; set; }
public int HLA_B2 { get; set; }
@gprasant
gprasant / SampleController.cs
Created May 11, 2012 17:44
A CustomController with a
[Authorize(Roles="ACustomRole")]
public class SomeController : Controller
{
}
@gprasant
gprasant / Global.asax.cs
Created May 11, 2012 17:22
Setting HttpContext.User to a custom Domain rather that System.Security.Identity.User
void WindowsAuthentication_OnAuthenticate(object sender, WindowsAuthenticationEventArgs e)
{
// Instantiate a user repository so as to get User information
IRepository<User> userRepository = new Repository<User>();
if (e.Identity != null && e.Identity.IsAuthenticated)
{
WindowsIdentity wi = e.Identity;
User user = userRepository.GetBy(u => u.Name == wi.Name).FirstOrDefault();
user.Identity = wi;
HttpContext.Current.User = user;
@gprasant
gprasant / User_Principal.cs
Created May 11, 2012 17:15
A user class implementing IPrincipal
public class User : IPrincipal
{
public string Name { get; set; }
public string EMail { get; set; }
public string Phone1 { get; set; }
public string Phone2 { get; set; }
public virtual IEnumerable<Permission> Permissions { get; set; }
public User()
@gprasant
gprasant / User_1.cs
Created May 11, 2012 17:07
A user class
public class User
{
public string Name { get; set; }
public string EMail { get; set; }
public string Phone1 { get; set; }
public string Phone2 { get; set; }
public virtual IEnumerable<Permission> Permissions { get; set; }
public User()
@gprasant
gprasant / TestAggregate.cs
Created May 1, 2012 14:19
Shows how Enumerable.Aggregate can be used
namespace IEnumerable.Tests
{
[TestClass]
public class TestAggregate
{
Func<int, int, int> sum = (a, b) => a + b;
[TestMethod]
public void ShouldAggregateAllElementsInASequence()
{
var sequence = Enumerable.Range(1, 2);
@gprasant
gprasant / duckable.cs
Created October 22, 2011 04:13
shows how the foreach does not necessarily require an IEnumerable. Demonstrates the use of Duck typing in C#
// resembles a IEnumerator. has Current and MoveNext
public class Duckerator
{
public bool MoveNext()
{
return false;
}
public Object Current { get; private set; }
}