public static RDN.Library.Classes.Controls.Calendar.CalendarEvent GetEvent(Guid eventId, Guid currentMemberId, Guid calendarId = new Guid())
        {
            RDN.Library.Classes.Controls.Calendar.CalendarEvent ev = new RDN.Library.Classes.Controls.Calendar.CalendarEvent();
            try
            {
                var dc = new ManagementContext();
                var e = (from xx in dc.CalendarEvents.Include("Location").Include("Location.Contact").Include("Location.Contact.Addresses").Include("Location.Contact.Communications")
                         where xx.Calendar.CalendarId == calendarId
                         where xx.CalendarItemId == eventId
                         where xx.IsRemovedFromCalendar == false
                         select new
                         {
                             xx.TicketUrl,
                             xx.IsInUTCTime,
                             xx.Calendar.TimeZone,
                             xx.Calendar.IsCalendarInUTC,
                             xx.AllowSelfCheckIn,
                             xx.CalendarItemId,
                             xx.Calendar.LeagueOwners,
                             xx.EndDate,
                             xx.Link,
                             xx.Name,
                             xx.Notes,
                             xx.StartDate,
                             xx.Attendees,
                             xx.Location,
                             xx.IsPublicEvent,
                             contactCart = xx.Location.Contact,
                             addresses = xx.Location.Contact.Addresses,
                             coms = xx.Location.Contact.Communications,
                             xx.PointsForEvent,
                             xx.EventType,
                             xx.ReocurringEvent,
                             nextEventId = dc.CalendarEvents.Where(x => x.Calendar.CalendarId == calendarId && x.IsRemovedFromCalendar == false && x.StartDate >= xx.StartDate && x.CalendarItemId != eventId).OrderBy(x => x.StartDate).Select(x => x.CalendarItemId).FirstOrDefault(),
                             previousEventId = dc.CalendarEvents.Where(x => x.Calendar.CalendarId == calendarId && x.IsRemovedFromCalendar == false && x.StartDate <= xx.StartDate && x.CalendarItemId != eventId).OrderByDescending(x => x.StartDate).Select(x => x.CalendarItemId).FirstOrDefault(),
                             nextStartDate = dc.CalendarEvents.Where(x => x.Calendar.CalendarId == calendarId && x.IsRemovedFromCalendar == false && x.StartDate >= xx.StartDate && x.CalendarItemId != eventId).OrderBy(x => x.StartDate).Select(x => x.StartDate).FirstOrDefault(),
                             previousStartDate = dc.CalendarEvents.Where(x => x.Calendar.CalendarId == calendarId && x.IsRemovedFromCalendar == false && x.StartDate <= xx.StartDate && x.CalendarItemId != eventId).OrderByDescending(x => x.StartDate).Select(x => x.StartDate).FirstOrDefault(),
                             xx.LastModified,
                             xx.Created,
                             xx.Color,
                             xx.Groups
                         }).FirstOrDefault();
                if (calendarId == new Guid() && e == null)
                {
                    e = (from xx in dc.CalendarEvents.Include("Location").Include("Location.Contact").Include("Location.Contact.Addresses").Include("Location.Contact.Communications")
                         where xx.CalendarItemId == eventId
                         where xx.IsRemovedFromCalendar == false
                         select new
                         {
                             xx.TicketUrl,
                             xx.IsInUTCTime,
                             xx.Calendar.TimeZone,
                             xx.Calendar.IsCalendarInUTC,
                             xx.AllowSelfCheckIn,
                             xx.CalendarItemId,
                             xx.Calendar.LeagueOwners,
                             xx.EndDate,
                             xx.Link,
                             xx.Name,
                             xx.Notes,
                             xx.StartDate,
                             xx.Attendees,
                             xx.Location,
                             xx.IsPublicEvent,
                             contactCart = xx.Location.Contact,
                             addresses = xx.Location.Contact.Addresses,
                             coms = xx.Location.Contact.Communications,
                             xx.PointsForEvent,
                             xx.EventType,
                             xx.ReocurringEvent,
                             nextEventId = dc.CalendarEvents.Where(x => x.Calendar.CalendarId == calendarId && x.IsRemovedFromCalendar == false && x.StartDate >= xx.StartDate && x.CalendarItemId != eventId).OrderBy(x => x.StartDate).Select(x => x.CalendarItemId).FirstOrDefault(),
                             previousEventId = dc.CalendarEvents.Where(x => x.Calendar.CalendarId == calendarId && x.IsRemovedFromCalendar == false && x.StartDate <= xx.StartDate && x.CalendarItemId != eventId).OrderByDescending(x => x.StartDate).Select(x => x.CalendarItemId).FirstOrDefault(),
                             nextStartDate = dc.CalendarEvents.Where(x => x.Calendar.CalendarId == calendarId && x.IsRemovedFromCalendar == false && x.StartDate >= xx.StartDate && x.CalendarItemId != eventId).OrderBy(x => x.StartDate).Select(x => x.StartDate).FirstOrDefault(),
                             previousStartDate = dc.CalendarEvents.Where(x => x.Calendar.CalendarId == calendarId && x.IsRemovedFromCalendar == false && x.StartDate <= xx.StartDate && x.CalendarItemId != eventId).OrderByDescending(x => x.StartDate).Select(x => x.StartDate).FirstOrDefault(),
                             xx.LastModified,
                             xx.Created,
                             xx.Color,
                             xx.Groups
                         }).FirstOrDefault();

                }

                if (e == null)
                {
                    return GetEventReocurring(calendarId, eventId);
                }
                //need to get the league first for the calendar.
                foreach (var owner in e.LeagueOwners)
                {
                    if (owner.League != null)
                    {
                        ev.OrganizersId = owner.League.LeagueId;
                        ev.OrganizersName = owner.League.Name;
                        break;
                    }
                }
                //adding the members of the event to it.
                foreach (var g in e.Groups)
                {
                    var gTemp = League.Classes.LeagueGroupFactory.DisplayGroup(g.Group);
                    ev.GroupsForEvent.Add(gTemp);
                    foreach (var mem in gTemp.GroupMembers)
                    {
                        if (ev.MembersApartOfEvent.Where(x => x.MemberId == mem.MemberId).FirstOrDefault() == null)
                        {
                            RDN.Portable.Classes.Controls.Calendar.CalendarAttendance a = new RDN.Portable.Classes.Controls.Calendar.CalendarAttendance();
                            a.MemberId = mem.MemberId;
                            a.MemberName = mem.DerbyName;
                            a.IsCheckedIn = false;
                            a.FullName = mem.Firstname + " " + mem.LastName;
                            a.MemberNumber = mem.PlayerNumber;
                            ev.MembersApartOfEvent.Add(a);
                            ev.MembersToCheckIn.Add(a);
                        }
                    }
                }
                //if the event had no groups attached, we add the league members to the event.
                if (ev.MembersApartOfEvent.Count == 0)
                {
                    var members = League.LeagueFactory.GetLeagueMembers(ev.OrganizersId);
                    for (int i = 0; i < members.Count; i++)
                    {
                        RDN.Portable.Classes.Controls.Calendar.CalendarAttendance a = new Portable.Classes.Controls.Calendar.CalendarAttendance();
                        a.MemberId = members[i].MemberId;
                        a.MemberName = members[i].DerbyName;
                        a.IsCheckedIn = false;
                        a.FullName = members[i].Firstname + " " + members[i].LastName;
                        a.MemberNumber = members[i].PlayerNumber;
                        ev.MembersApartOfEvent.Add(a);
                        ev.MembersToCheckIn.Add(a);
                    }
                }
                //event type needs to stay above attendees since attendees relies on event type.
                ev.EventType = new Portable.Classes.Controls.Calendar.CalendarEventType();
                if (e.EventType != null)
                {
                    ev.EventType.EventTypeName = e.EventType.EventTypeName;
                    ev.EventType.PointsForExcused = e.EventType.PointsForExcused;
                    ev.EventType.PointsForNotPresent = e.EventType.PointsForNotPresent;
                    ev.EventType.PointsForPartial = e.EventType.PointsForPartial;
                    ev.EventType.PointsForPresent = e.EventType.PointsForPresent;
                    ev.EventType.PointsForTardy = e.EventType.PointsForTardy;
                    ev.EventType.CalendarEventTypeId = e.EventType.CalendarEventTypeId;
                }


                //add the attendees to the event.
                foreach (var att in e.Attendees)
                {
                    RDN.Portable.Classes.Controls.Calendar.CalendarAttendance a = new Portable.Classes.Controls.Calendar.CalendarAttendance()
                    {
                        AttedanceId = att.CalendarAttendanceId,
                        MemberId = att.Attendant.MemberId,
                        FullName = att.Attendant.Firstname + " " + att.Attendant.Lastname,
                        MemberName = att.Attendant.DerbyName,
                        Note = att.Note,
                        PointType = (CalendarEventPointTypeEnum)Enum.Parse(typeof(CalendarEventPointTypeEnum), att.PointTypeEnum.ToString()),
                        SecondaryPointType = (CalendarEventPointTypeEnum)Enum.Parse(typeof(CalendarEventPointTypeEnum), att.SecondaryPointTypeEnum.ToString()),
                        MemberNumber = att.Attendant.PlayerNumber,
                        AdditionalPoints = att.AdditionalPoints,
                        Availability = (AvailibilityEnum)Enum.Parse(typeof(AvailibilityEnum), att.AvailibityEnum.ToString()),
                        AvailableNotes = att.AvailabilityNote,
                    };

                    switch (a.PointType)
                    {
                        case CalendarEventPointTypeEnum.Present:
                            if (a.SecondaryPointType == CalendarEventPointTypeEnum.Tardy && a.AdditionalPoints == 0)
                                a.PointsStringForReading = ev.EventType.PointsForPresent + " + " + ev.EventType.PointsForTardy + " = " + (ev.EventType.PointsForPresent + ev.EventType.PointsForTardy);
                            else if (a.SecondaryPointType == CalendarEventPointTypeEnum.Tardy)
                                a.PointsStringForReading = ev.EventType.PointsForPresent + " + " + a.AdditionalPoints + " + " + ev.EventType.PointsForTardy + " = " + (ev.EventType.PointsForPresent + ev.EventType.PointsForTardy + a.AdditionalPoints);
                            else if (a.AdditionalPoints != 0)
                                a.PointsStringForReading = ev.EventType.PointsForPresent + " + " + a.AdditionalPoints + " = " + (ev.EventType.PointsForPresent + a.AdditionalPoints);
                            else
                                a.PointsStringForReading = ev.EventType.PointsForPresent.ToString();
                            break;
                        case CalendarEventPointTypeEnum.Partial:
                            if (a.SecondaryPointType == CalendarEventPointTypeEnum.Tardy && a.AdditionalPoints == 0)
                                a.PointsStringForReading = ev.EventType.PointsForPartial + " + " + ev.EventType.PointsForTardy + " = " + (ev.EventType.PointsForPartial + ev.EventType.PointsForTardy);
                            else if (a.SecondaryPointType == CalendarEventPointTypeEnum.Tardy)
                                a.PointsStringForReading = ev.EventType.PointsForPartial + " + " + a.AdditionalPoints + " + " + ev.EventType.PointsForTardy + " = " + (ev.EventType.PointsForPartial + ev.EventType.PointsForTardy + a.AdditionalPoints);
                            else if (a.AdditionalPoints != 0)
                                a.PointsStringForReading = ev.EventType.PointsForPartial + " + " + a.AdditionalPoints + " = " + (ev.EventType.PointsForPartial + a.AdditionalPoints);
                            else
                                a.PointsStringForReading = ev.EventType.PointsForPartial.ToString();
                            break;
                        case CalendarEventPointTypeEnum.Not_Present:
                            if (a.SecondaryPointType == CalendarEventPointTypeEnum.Tardy && a.AdditionalPoints == 0)
                                a.PointsStringForReading = ev.EventType.PointsForNotPresent + " + " + ev.EventType.PointsForTardy + " = " + (ev.EventType.PointsForNotPresent + ev.EventType.PointsForTardy);
                            else if (a.SecondaryPointType == CalendarEventPointTypeEnum.Tardy)
                                a.PointsStringForReading = ev.EventType.PointsForNotPresent + " + " + a.AdditionalPoints + " + " + ev.EventType.PointsForTardy + " = " + (ev.EventType.PointsForNotPresent + ev.EventType.PointsForTardy + a.AdditionalPoints);
                            else if (a.AdditionalPoints != 0)
                                a.PointsStringForReading = ev.EventType.PointsForNotPresent + " + " + a.AdditionalPoints + " = " + (ev.EventType.PointsForNotPresent + a.AdditionalPoints);
                            else
                                a.PointsStringForReading = ev.EventType.PointsForNotPresent.ToString();
                            break;
                        case CalendarEventPointTypeEnum.Excused:
                            if (a.SecondaryPointType == CalendarEventPointTypeEnum.Tardy && a.AdditionalPoints == 0)
                                a.PointsStringForReading = ev.EventType.PointsForExcused + " + " + ev.EventType.PointsForTardy + " = " + (ev.EventType.PointsForExcused + ev.EventType.PointsForTardy);
                            else if (a.SecondaryPointType == CalendarEventPointTypeEnum.Tardy)
                                a.PointsStringForReading = ev.EventType.PointsForExcused + " + " + a.AdditionalPoints + " + " + ev.EventType.PointsForTardy + " = " + (ev.EventType.PointsForExcused + ev.EventType.PointsForTardy + a.AdditionalPoints);
                            else if (a.AdditionalPoints != 0)
                                a.PointsStringForReading = ev.EventType.PointsForExcused + " + " + a.AdditionalPoints + " = " + (ev.EventType.PointsForExcused + a.AdditionalPoints);
                            else
                                a.PointsStringForReading = ev.EventType.PointsForExcused.ToString();
                            break;
                    }

                    if (a.PointType != CalendarEventPointTypeEnum.None)
                        a.IsCheckedIn = true;

                    //since the member is attending the event, we remove them from having members to check in.
                    var checkedInMember = ev.MembersToCheckIn.Where(x => x.MemberId == a.MemberId).FirstOrDefault();
                    if (checkedInMember != null)
                        ev.MembersToCheckIn.Remove(checkedInMember);

                    ev.Attendees.Add(a);
                }

                var avail = ev.Attendees.Where(x => x.MemberId == currentMemberId && x.Availability != AvailibilityEnum.None).FirstOrDefault();
                if (avail != null)
                    ev.HasCurrentMemberSetAvailability = true;
                var attend = ev.Attendees.Where(x => x.MemberId == currentMemberId && x.IsCheckedIn == true).FirstOrDefault();
                if (attend != null)
                    ev.IsCurrentMemberCheckedIn = true;
                if (e.Color != null)
                {
                    var c = Color.FromArgb(e.Color.ColorIdCSharp);
                    ev.ColorTempSelected = ColorTranslator.ToHtml(c);
                }
                ev.IsCalendarInUTC = e.IsCalendarInUTC;
                ev.IsInUTCTime = e.IsInUTCTime;
                ev.CalendarTimeZone = e.TimeZone;
                ev.AllowSelfCheckIn = e.AllowSelfCheckIn;
                ev.CalendarItemId = e.CalendarItemId;
                ev.CalendarId = calendarId;
                ev.RDNationLink = ServerConfig.WEBSITE_EVENT_URL + "/" + RDN.Utilities.Strings.StringExt.ToSearchEngineFriendly(e.Name) + "/" + e.CalendarItemId.ToString().Replace("-", "");
                if (!ev.IsInUTCTime)
                {
                    ev.EndDate = e.EndDate;
                    ev.StartDate = e.StartDate;
                }
                else
                {
                    ev.StartDate = (e.StartDate + new TimeSpan(e.TimeZone, 0, 0));
                    ev.EndDate = (e.EndDate + new TimeSpan(e.TimeZone, 0, 0));
                }
                if (!String.IsNullOrEmpty(e.Link) && !e.Link.Contains("http://"))
                    ev.Link = "http://" + e.Link;
                else
                    ev.Link = e.Link;
                ev.IsPublicEvent = e.IsPublicEvent;
                ev.TicketUrl = e.TicketUrl;
                if (e.ReocurringEvent != null)
                {
                    ev.CalendarReoccurringId = e.ReocurringEvent.CalendarItemId;
                    ev.IsReoccurring = true;
                }

                GoogleCalendar gc = new GoogleCalendar();
                if (e.Location != null)
                {
                    ev.Location.LocationName = e.Location.LocationName;
                    ev.Location.LocationId = e.Location.LocationId;
                    gc.Location = ev.Location.LocationName + ", ";
                }

                if (e.addresses.FirstOrDefault() != null)
                {
                    Address address = new Address();

                    address.Address1 = e.addresses.FirstOrDefault().Address1;
                    address.Address2 = e.addresses.FirstOrDefault().Address2;
                    address.AddressId = e.addresses.FirstOrDefault().AddressId;
                    address.CityRaw = e.addresses.FirstOrDefault().CityRaw;
                    if (e.addresses.FirstOrDefault().Country != null)
                        address.Country = e.addresses.FirstOrDefault().Country.Code;
                    address.StateRaw = e.addresses.FirstOrDefault().StateRaw;
                    address.Zip = e.addresses.FirstOrDefault().Zip;
                    gc.Location += address.Address1 + " " + address.Address2 + ", " + address.CityRaw + ", " + address.StateRaw + " " + address.Zip;
                    ev.Location.Contact.Addresses.Add(address);
                }
                ev.Name = e.Name;
                ev.NextEventId = e.nextEventId;
                ev.PreviousEventId = e.previousEventId;

                //if two or more events lay on the same StartDate and Time, we do this to Sort them
                //into previous and next so that we can walk through them one by one.
                //before this, if we hit next, we would skip over dates with the same datetime.
                if (ev.NextEventId != ev.PreviousEventId)
                {
                    var oneDateManyEvents = (from xx in dc.CalendarEvents
                                             where xx.Calendar.CalendarId == calendarId
                                             where xx.IsRemovedFromCalendar == false
                                             where xx.StartDate == e.previousStartDate
                                             select xx.CalendarItemId).OrderBy(x => x).ToList();
                    if (oneDateManyEvents.Count > 1)
                    {
                        var indexOfCurrentEvent = oneDateManyEvents.IndexOf(oneDateManyEvents.Where(x => x == ev.PreviousEventId).FirstOrDefault());
                        //if we get to this point, the event always gets the first event with the same times.  
                        //We we need to reverse it to make it get the last event in the sequence.
                        if (indexOfCurrentEvent == 0)
                        {
                            ev.NextEventId = dc.CalendarEvents.Where(x => x.Calendar.CalendarId == calendarId && x.IsRemovedFromCalendar == false && x.StartDate > e.StartDate).OrderBy(x => x.StartDate).Select(x => x.CalendarItemId).FirstOrDefault();
                            ev.PreviousEventId = oneDateManyEvents[oneDateManyEvents.Count - 1];
                        }
                    }
                }
                else
                {
                    try
                    {
                        var oneDateManyEvents = (from xx in dc.CalendarEvents
                                                 where xx.Calendar.CalendarId == calendarId
                                                 where xx.IsRemovedFromCalendar == false
                                                 where xx.StartDate == e.StartDate
                                                 select xx.CalendarItemId).OrderBy(x => x).ToList();
                        var indexOfCurrentEvent = oneDateManyEvents.IndexOf(oneDateManyEvents.Where(x => x == eventId).FirstOrDefault());
                        if (indexOfCurrentEvent == 0)
                        {
                            try
                            {
                                ev.PreviousEventId = dc.CalendarEvents.Where(x => x.Calendar.CalendarId == calendarId && x.IsRemovedFromCalendar == false && x.StartDate < e.StartDate && x.CalendarItemId != eventId).OrderByDescending(x => x.StartDate).Select(x => x.CalendarItemId).FirstOrDefault();
                                if (oneDateManyEvents.Count > indexOfCurrentEvent && oneDateManyEvents.Count > 1)
                                    ev.NextEventId = oneDateManyEvents[indexOfCurrentEvent + 1];
                            }
                            catch (Exception exception)
                            {
                                ErrorDatabaseManager.AddException(exception, exception.GetType(), additionalInformation: indexOfCurrentEvent + " " + oneDateManyEvents.Count);
                            }
                        }
                        else if (indexOfCurrentEvent >= oneDateManyEvents.Count - 1)
                        {
                            if (oneDateManyEvents.Count > 1)
                                ev.PreviousEventId = oneDateManyEvents[indexOfCurrentEvent - 1];
                            ev.NextEventId = dc.CalendarEvents.Where(x => x.Calendar.CalendarId == calendarId && x.IsRemovedFromCalendar == false && x.StartDate > e.StartDate && x.CalendarItemId != eventId).OrderBy(x => x.StartDate).Select(x => x.CalendarItemId).FirstOrDefault();
                        }
                        else
                        {
                            ev.PreviousEventId = oneDateManyEvents[indexOfCurrentEvent - 1];
                            ev.NextEventId = oneDateManyEvents[indexOfCurrentEvent + 1];
                        }
                    }
                    catch (Exception exception)
                    {
                        ErrorDatabaseManager.AddException(exception, exception.GetType());
                    }
                }

                ev.Notes = e.Notes;

                if (e.LastModified > new DateTime(2013, 11, 23) || e.Created > new DateTime(2013, 11, 23))
                {
                    ev.NotesHtml = e.Notes;
                }
                else if (e.Created < new DateTime(2013, 11, 23))
                {
                    if (!String.IsNullOrEmpty(e.Notes))
                    {
                        RDN.Library.Util.MarkdownSharp.Markdown markdown = new RDN.Library.Util.MarkdownSharp.Markdown();
                        markdown.AutoHyperlink = true;
                        markdown.LinkEmails = true;
                        ev.NotesHtml = HtmlSanitize.FilterHtmlToWhitelist(markdown.Transform(e.Notes)).Replace("</p>", "</p><br/>");
                    }
                }

                gc.Description = ev.Notes;
                gc.EndDate = ev.EndDate.ToUniversalTime();
                gc.StartDate = ev.StartDate.ToUniversalTime();
                gc.Website = ev.Link;
                gc.WebsiteName = ev.Link;
                gc.What = ev.Name;


                ev.GoogleCalendarUrl = gc.GetGoogleUrl();
            }
            catch (Exception exception)
            {
                ErrorDatabaseManager.AddException(exception, exception.GetType());
            }
            return ev;
        }
        public static RDN.Library.Classes.Controls.Calendar.CalendarEvent GetEventReocurring(Guid eventId, Guid calendarId = new Guid())
        {
            RDN.Library.Classes.Controls.Calendar.CalendarEvent ev = new RDN.Library.Classes.Controls.Calendar.CalendarEvent();
            try
            {
                var dc = new ManagementContext();
                var e = (from xx in dc.CalendarEventsReocurring.Include("Location").Include("Location.Contact").Include("Location.Contact.Addresses").Include("Location.Contact.Communications")
                         where xx.Calendar.CalendarId == calendarId
                         where xx.CalendarItemId == eventId
                         where xx.IsRemovedFromCalendar == false
                         select new
                         {
                             xx.TicketUrl,
                             xx.IsInUTCTime,
                             xx.Calendar.IsCalendarInUTC,
                             xx.Calendar.TimeZone,
                             xx.AllowSelfCheckIn,
                             xx.CalendarItemId,
                             xx.EndDate,
                             xx.Link,
                             xx.Calendar.LeagueOwners,
                             xx.Name,
                             xx.Notes,
                             xx.StartDate,
                             xx.Location,
                             contactCart = xx.Location.Contact,
                             addresses = xx.Location.Contact.Addresses,
                             coms = xx.Location.Contact.Communications,
                             xx.PointsForEvent,
                             xx.EventType,
                             xx.DaysOfWeekReocurring,
                             xx.StartReocurring,
                             xx.EndReocurring,
                             xx.FrequencyReocurring,
                             xx.IsPublic,
                             xx.MonthlyIntervalReocurring,
                             xx.LastModified,
                             xx.Created,
                             xx.Color,
                             xx.Groups
                         }).FirstOrDefault();
                if (calendarId == new Guid() && e == null)
                {
                    e = (from xx in dc.CalendarEventsReocurring.Include("Location").Include("Location.Contact").Include("Location.Contact.Addresses").Include("Location.Contact.Communications")
                         where xx.Calendar.CalendarId == calendarId
                         where xx.CalendarItemId == eventId
                         where xx.IsRemovedFromCalendar == false
                         select new
                         {
                             xx.TicketUrl,
                             xx.IsInUTCTime,
                             xx.Calendar.IsCalendarInUTC,
                             xx.Calendar.TimeZone,
                             xx.AllowSelfCheckIn,
                             xx.CalendarItemId,
                             xx.EndDate,
                             xx.Link,
                             xx.Calendar.LeagueOwners,
                             xx.Name,
                             xx.Notes,
                             xx.StartDate,
                             xx.Location,
                             contactCart = xx.Location.Contact,
                             addresses = xx.Location.Contact.Addresses,
                             coms = xx.Location.Contact.Communications,
                             xx.PointsForEvent,
                             xx.EventType,
                             xx.DaysOfWeekReocurring,
                             xx.StartReocurring,
                             xx.EndReocurring,
                             xx.FrequencyReocurring,
                             xx.IsPublic,
                             xx.MonthlyIntervalReocurring,
                             xx.LastModified,
                             xx.Created,
                             xx.Color,
                             xx.Groups
                         }).FirstOrDefault();
                }

                if (e == null)
                    return null;

                ev.AllowSelfCheckIn = e.AllowSelfCheckIn;
                ev.CalendarItemId = e.CalendarItemId;
                if (e.Color != null)
                {
                    var c = Color.FromArgb(e.Color.ColorIdCSharp);
                    ev.ColorTempSelected = ColorTranslator.ToHtml(c);
                }

                ev.Link = e.Link;

                var aEvent = new ScheduleWidget.ScheduledEvents.Event()
                {
                    Title = e.Name,
                    FrequencyTypeOptions = (FrequencyTypeEnum)Enum.Parse(typeof(FrequencyTypeEnum), e.FrequencyReocurring.ToString()),
                    DaysOfWeek = e.DaysOfWeekReocurring,
                    MonthlyInterval = e.MonthlyIntervalReocurring
                };
                if (e.EndReocurring.HasValue)
                {
                    ev.EndDateReoccurring = e.EndReocurring.GetValueOrDefault();
                    ev.EndDateReoccurringDisplay = e.EndReocurring.GetValueOrDefault().ToShortDateString();
                }
                ev.StartDateReoccurring = e.StartReocurring;
                ev.StartDateReoccurringDisplay = e.StartReocurring.ToShortDateString() + " " + e.StartReocurring.ToShortTimeString();
                ev.EventReoccurring = aEvent;
                ev.TicketUrl = e.TicketUrl;
                ev.RDNationLink = ServerConfig.WEBSITE_EVENT_URL + "/" + RDN.Utilities.Strings.StringExt.ToSearchEngineFriendly(e.Name) + "/" + e.CalendarItemId.ToString().Replace("-", "");

                foreach (var owner in e.LeagueOwners)
                {
                    if (owner.League != null)
                    {
                        ev.OrganizersId = owner.League.LeagueId;
                        ev.OrganizersName = owner.League.Name;
                        break;
                    }
                }
                GoogleCalendar gc = new GoogleCalendar();
                if (e.Location != null)
                {
                    ev.Location.LocationName = e.Location.LocationName;
                    ev.Location.LocationId = e.Location.LocationId;
                }
                gc.Location = ev.Location.LocationName + ", ";
                if (e.addresses.FirstOrDefault() != null)
                {
                    RDN.Portable.Classes.ContactCard.Address address = new RDN.Portable.Classes.ContactCard.Address();
                    address.Address1 = e.addresses.FirstOrDefault().Address1;
                    address.Address2 = e.addresses.FirstOrDefault().Address2;
                    address.AddressId = e.addresses.FirstOrDefault().AddressId;
                    address.CityRaw = e.addresses.FirstOrDefault().CityRaw;
                    if (e.addresses.FirstOrDefault().Country != null)
                        address.Country = e.addresses.FirstOrDefault().Country.Code;
                    address.StateRaw = e.addresses.FirstOrDefault().StateRaw;
                    address.Zip = e.addresses.FirstOrDefault().Zip;
                    gc.Location += address.Address1 + " " + address.Address2 + ", " + address.CityRaw + ", " + address.StateRaw + " " + address.Zip;
                    ev.Location.Contact.Addresses.Add(address);
                }
                ev.EventType = new Portable.Classes.Controls.Calendar.CalendarEventType();
                if (e.EventType != null)
                {
                    ev.EventType.EventTypeName = e.EventType.EventTypeName;
                    ev.EventType.PointsForExcused = e.EventType.PointsForExcused;
                    ev.EventType.PointsForNotPresent = e.EventType.PointsForNotPresent;
                    ev.EventType.PointsForPartial = e.EventType.PointsForPartial;
                    ev.EventType.PointsForPresent = e.EventType.PointsForPresent;
                    ev.EventType.PointsForTardy = e.EventType.PointsForTardy;
                    ev.EventType.CalendarEventTypeId = e.EventType.CalendarEventTypeId;
                }
                ev.Name = e.Name;
                ev.Notes = e.Notes;

                foreach (var g in e.Groups)
                {
                    var gTemp = League.Classes.LeagueGroupFactory.DisplayGroup(g.Group);
                    ev.GroupsForEvent.Add(gTemp);
                    foreach (var mem in gTemp.GroupMembers)
                    {
                        if (ev.MembersApartOfEvent.Where(x => x.MemberId == mem.MemberId).FirstOrDefault() == null)
                        {
                            RDN.Portable.Classes.Controls.Calendar.CalendarAttendance a = new Portable.Classes.Controls.Calendar.CalendarAttendance();
                            a.MemberId = mem.MemberId;
                            a.MemberName = mem.DerbyName;
                            a.IsCheckedIn = false;
                            a.FullName = mem.Firstname + " " + mem.LastName;
                            a.MemberNumber = mem.PlayerNumber;
                            ev.MembersApartOfEvent.Add(a);
                            ev.MembersToCheckIn.Add(a);
                        }
                    }
                }

                if (e.LastModified > new DateTime(2013, 11, 23) || e.Created > new DateTime(2013, 11, 23))
                {
                    ev.NotesHtml = e.Notes;
                }
                else if (e.Created < new DateTime(2013, 11, 23))
                {
                    if (!String.IsNullOrEmpty(e.Notes))
                    {
                        RDN.Library.Util.MarkdownSharp.Markdown markdown = new RDN.Library.Util.MarkdownSharp.Markdown();
                        markdown.AutoHyperlink = true;
                        markdown.LinkEmails = true;
                        ev.NotesHtml = HtmlSanitize.FilterHtmlToWhitelist(markdown.Transform(e.Notes)).Replace("</p>", "</p><br/>");
                    }
                }
                ev.IsPublicEvent = e.IsPublic;

                gc.Description = ev.Notes;
                if (!e.IsInUTCTime)
                {
                    ev.EndDate = e.EndDate;
                    ev.StartDate = e.StartDate;
                }
                else
                {
                    ev.StartDate = (e.StartDate + new TimeSpan(e.TimeZone, 0, 0));
                    ev.EndDate = (e.EndDate + new TimeSpan(e.TimeZone, 0, 0));
                }
                gc.EndDate = ev.EndDate.ToUniversalTime();
                gc.StartDate = ev.StartDate.ToUniversalTime();
                gc.Website = ev.Link;
                gc.WebsiteName = ev.Link;
                gc.What = ev.Name;

                ev.GoogleCalendarUrl = gc.GetGoogleUrl();
            }
            catch (Exception exception)
            {
                ErrorDatabaseManager.AddException(exception, exception.GetType());
            }
            return ev;
        }