Skip to content

Instantly share code, notes, and snippets.

@SuperJMN
Created November 5, 2014 19:43
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 SuperJMN/aa2cd20da38a705df7c3 to your computer and use it in GitHub Desktop.
Save SuperJMN/aa2cd20da38a705df7c3 to your computer and use it in GitHub Desktop.
MenuOption2
public class Course : ValueObject<Course>
{
private string name;
private int defaultPriority;
public Course(string name, int defaultPriority)
{
this.name = name;
this.defaultPriority = defaultPriority;
}
public int DefaultPriority
{
get { return defaultPriority; }
private set { defaultPriority = value; }
}
public string Name
{
get { return name; }
}
}
public class Menu : Entity<Guid>
{
private readonly IDictionary<Product, Course> products = new Dictionary<Product, Course>();
public void AddProduct(Product product, Course course)
{
try
{
products.Add(product, course);
}
catch (ArgumentException e)
{
throw new InvalidOperationException("The product has already been added", e);
}
}
public void RemoveProduct(Product product)
{
products.Remove(product);
}
public IEnumerable<Product> Products
{
get { return products.Keys; }
}
public IEnumerable<Course> Courses
{
get { return products.Values.Distinct(); }
}
public IEnumerable<Product> GetProductsForCourse(Course course)
{
return products.Where(pair => pair.Value == course).Select(pair => pair.Key);
}
}
public class Product : Entity<Guid>
{
private readonly string name;
public Product(string name) : base(Guid.NewGuid())
{
this.name = name;
}
public string Name
{
get { return name; }
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment