using System;
using System.Collections.Generic;
using System.Linq;
using System.Xml.Linq;
using Composite.Data;
using Composite.Data.Types;

namespace Demo
{
	public static class InlineMethodFunction
	{
		public static IEnumerable<XElement> GetEventXmlByQuarter(DataReference<Demo.Quarter> quarterRef)
		{            
			using (DataConnection connection = new DataConnection())
			{
				return 	from quarter in connection.Get<Demo.Quarter>()
						join month in connection.Get<Demo.Month>() on quarter.Id equals month.Quarter
						join anEvent in connection.Get<Demo.Event>() on month.Id equals anEvent.Month		
						where quarter.Id == (Guid)quarterRef.KeyValue
						select new XElement("Event", 
								    new XAttribute( "Id", anEvent.Id ),
								    new XAttribute( "Name", anEvent.Name ),
								   		new XElement("Month",
											    new XAttribute("Name", month.Name)));
			}           
		}
	}
}
