Skip to content

Instantly share code, notes, and snippets.

@diegodfsd
Created January 15, 2012 17:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save diegodfsd/1616565 to your computer and use it in GitHub Desktop.
Save diegodfsd/1616565 to your computer and use it in GitHub Desktop.
using System;
using System.Linq;
using System.Security.Cryptography;
using System.Text;
using Norm.Attributes;
namespace Projector.Site.Models
{
//Reference:http://pt.gravatar.com/site/implement/images/
public class Attendee
{
public Guid Id { get; set; }
public string Name { get; set; }
public string Email { get; set; }
public string Password { get; set; }
public bool Speaker { get; set; }
[MongoIgnore]
public string GravatarUrl
{
get { return string.Format("http://www.gravatar.com/avatar/{0}?s=30d=mm", ComputeHash()); }
}
public Attendee()
{
Id = Guid.NewGuid();
}
private string ComputeHash()
{
byte[] data = MD5.Create().ComputeHash(Encoding.ASCII.GetBytes(Email));
return data.Aggregate("", (hash, item) => hash += item.ToString("x2"));
}
public override int GetHashCode()
{
return Id.GetHashCode();
}
public override bool Equals(object other)
{
var instance = other as Attendee;
return instance != null && Email == instance.Email;
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text.RegularExpressions;
using Norm.Attributes;
namespace Projector.Site.Models
{
public class Presentation
{
private readonly IList<Attendee> attendees;
public Guid Id { get; set; }
public string Title { get; set; }
[MongoIgnore]
public string Permanent
{
get { return Regex.Replace(Title, @"[^(\w|0-9)]+", ""); }
}
public string Description { get; set; }
public int QtdSlides { get; set; }
public IEnumerable<Attendee> Attendees
{
get { return attendees; }
}
public Presentation()
{
Id = Guid.NewGuid();
attendees = new List<Attendee>();
}
public void AddAttendee(Attendee attendee)
{
if (!attendees.Any(attendee.Equals))
{
attendees.Add(attendee);
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment