Skip to content

Instantly share code, notes, and snippets.

@aidanmorgan
Created June 22, 2011 12:15
Show Gist options
  • Save aidanmorgan/1039956 to your computer and use it in GitHub Desktop.
Save aidanmorgan/1039956 to your computer and use it in GitHub Desktop.
public class WhiskeyDTO
{
public static WhiskeyDTO Create(Whiskey w)
{
WhiskeyDTO dto = new WhiskeyDTO();
dto.Name = w.Name;
dto.Id = w.Id;
dto.Description = w.Description;
dto.Type = WhiskeyTypeDTO.Create(w.Type);
if(w.Distillery != null)
{
dto.Distillery = w.Distillery.Id;
}
foreach(Rating r in w.Ratings)
{
dto.Ratings.Add(r.Id);
}
if(w.Ratings.Count > 0)
{
dto.AverageScore = w.AverageRating;
}
dto.Score = w.TotalRating;
return dto;
}
public double Score { get; private set; }
public string Name { get; set; }
public string Description { get; set; }
public Guid Id { get; set; }
public Guid Distillery { get; set; }
public IList<Guid> Ratings { get; set; }
public WhiskeyTypeDTO Type { get; set; }
public double? AverageScore { get; set; }
private WhiskeyDTO()
{
Ratings = new List<Guid>();
}
public void Update(Whiskey whiskey)
{
whiskey.Name = Name;
whiskey.Description = Description;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment