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 CalendarEvent DisplayEvent(DataModels.Calendar.CalendarEvent ev, Guid currentMemberId, bool isAttendanceManagerOrBetter)
        {
            CalendarEvent calEvent = new CalendarEvent();
            try
            {
                calEvent.IsAttendanceManagerOrBetter = isAttendanceManagerOrBetter;
                foreach (var att in ev.Attendees)
                {
                    RDN.Portable.Classes.Controls.Calendar.CalendarAttendance a = new Portable.Classes.Controls.Calendar.CalendarAttendance();
                    a.MemberId = att.Attendant.MemberId;
                    a.MemberName = att.Attendant.DerbyName;
                    a.FullName = att.Attendant.Firstname + " " + att.Attendant.Lastname;
                    a.AttedanceId = att.CalendarAttendanceId;
                    a.Note = att.Note;
                    a.PointType = (CalendarEventPointTypeEnum)Enum.Parse(typeof(CalendarEventPointTypeEnum), att.PointTypeEnum.ToString());
                    a.SecondaryPointType = (CalendarEventPointTypeEnum)Enum.Parse(typeof(CalendarEventPointTypeEnum), att.SecondaryPointTypeEnum.ToString());
                    a.Availability = (AvailibilityEnum)Enum.Parse(typeof(AvailibilityEnum), att.AvailibityEnum.ToString());
                    a.AvailableNotes = att.AvailabilityNote;
                    if (a.PointType != CalendarEventPointTypeEnum.None)
                        a.IsCheckedIn = true;
                    calEvent.Attendees.Add(a);
                }

                if (ev.Groups.Count == 0)
                    calEvent.IsCurrentMemberApartOfEvent = true;
                else
                {
                    foreach (var g in ev.Groups)
                    {
                        var gTemp = League.Classes.LeagueGroupFactory.DisplayGroup(g.Group);
                        foreach (var mem in gTemp.GroupMembers)
                        {
                            RDN.Portable.Classes.Controls.Calendar.CalendarAttendance a = new RDN.Portable.Classes.Controls.Calendar.CalendarAttendance();
                            a.MemberId = mem.MemberId;
                            a.MemberName = mem.DerbyName;
                            if (calEvent.MembersApartOfEvent.Where(x => x.MemberId == a.MemberId).FirstOrDefault() == null)
                                calEvent.MembersApartOfEvent.Add(a);
                        }
                    }
                }

                if (ev.EventType != null)
                {
                    calEvent.EventType.CalendarEventTypeId = ev.EventType.CalendarEventTypeId;
                    calEvent.EventType.PointsForExcused = ev.EventType.PointsForExcused;
                    calEvent.EventType.PointsForNotPresent = ev.EventType.PointsForNotPresent;
                    calEvent.EventType.PointsForPartial = ev.EventType.PointsForPartial;
                    calEvent.EventType.PointsForPresent = ev.EventType.PointsForPresent;
                    calEvent.EventType.PointsForTardy = ev.EventType.PointsForTardy;
                }
                foreach (var owner in ev.Calendar.LeagueOwners)
                {
                    if (owner.League != null)
                    {
                        calEvent.OrganizersId = owner.League.LeagueId;
                        calEvent.OrganizersName = owner.League.Name;
                        if (owner.League.Logo != null)
                            calEvent.ImageUrl = owner.League.Logo.ImageUrlThumb;
                        calEvent.OrganizerUrl = ServerConfig.WEBSITE_DEFAULT_LOCATION + "/roller-derby-league/" + RDN.Utilities.Strings.StringExt.ToSearchEngineFriendly(calEvent.OrganizersName) + "/" + calEvent.OrganizersId.ToString().Replace("-", "");
                        break;
                    }
                }
                GoogleCalendar gc = new GoogleCalendar();
                if (ev.Location != null)
                {
                    calEvent.Location.LocationName = ev.Location.LocationName;
                    gc.Location = calEvent.Location.LocationName + " ";
                }
                if (ev.Location != null)
                {
                    calEvent.Location.LocationName = ev.Location.LocationName;
                    calEvent.Location.LocationId = ev.Location.LocationId;

                    if (ev.Location.Contact != null && ev.Location.Contact.Addresses.FirstOrDefault() != null)
                    {
                        Address address = new Address();
                        address.Address1 = ev.Location.Contact.Addresses.FirstOrDefault().Address1;
                        address.Address2 = ev.Location.Contact.Addresses.FirstOrDefault().Address2;
                        address.AddressId = ev.Location.Contact.Addresses.FirstOrDefault().AddressId;
                        address.CityRaw = ev.Location.Contact.Addresses.FirstOrDefault().CityRaw;
                        if (ev.Location.Contact.Addresses.FirstOrDefault().Country != null)
                            address.Country = ev.Location.Contact.Addresses.FirstOrDefault().Country.Code;
                        address.StateRaw = ev.Location.Contact.Addresses.FirstOrDefault().StateRaw;
                        address.Zip = ev.Location.Contact.Addresses.FirstOrDefault().Zip;
                        gc.Location += address.Address1 + " " + address.Address2 + ", " + address.CityRaw + ", " + address.StateRaw + " " + address.Zip;
                        address.Coords = new Portable.Classes.Location.GeoCoordinate();
                        address.Coords.Longitude = ev.Location.Contact.Addresses.FirstOrDefault().Coords.Longitude;
                        address.Coords.Latitude = ev.Location.Contact.Addresses.FirstOrDefault().Coords.Latitude;

                        if (!String.IsNullOrEmpty(address.CityRaw))
                            calEvent.Address += address.CityRaw + ", ";
                        if (!String.IsNullOrEmpty(address.StateRaw))
                            calEvent.Address += address.StateRaw + ",";
                        calEvent.Address += address.Country;
                        calEvent.AddressUrl += "http://www.bing.com/maps/default.aspx?q=";
                        calEvent.AddressUrl += address.Address1 + address.Address2;

                        calEvent.AddressUrl += " ," + address.CityRaw;
                        calEvent.AddressUrl += "," + address.StateRaw;
                        calEvent.AddressUrl += " " + address.Zip;
                        calEvent.AddressUrl += address.Country;

                        calEvent.Location.Contact.Addresses.Add(address);
                    }
                }
                if (ev.ReocurringEvent != null)
                    calEvent.CalendarReoccurringId = ev.ReocurringEvent.CalendarItemId;
                calEvent.Name = ev.Name;
                calEvent.NameUrl = ServerConfig.WEBSITE_DEFAULT_LOCATION + "/roller-derby-event/" + RDN.Utilities.Strings.StringExt.ToSearchEngineFriendly(ev.Name) + "/" + ev.CalendarItemId.ToString().Replace("-", "");
                calEvent.TicketUrl = ev.TicketUrl;
                calEvent.CalendarItemId = ev.CalendarItemId;

                var avail = calEvent.Attendees.Where(x => x.MemberId == currentMemberId && x.Availability != AvailibilityEnum.None).FirstOrDefault();
                if (avail != null)
                    calEvent.HasCurrentMemberSetAvailability = true;
                var attend = calEvent.Attendees.Where(x => x.MemberId == currentMemberId && x.IsCheckedIn == true).FirstOrDefault();
                if (attend != null)
                    calEvent.IsCurrentMemberCheckedIn = true;

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

                if (!ev.IsInUTCTime)
                {
                    calEvent.StartDate = ev.StartDate;
                    calEvent.EndDate = ev.EndDate;
                }
                else
                {
                    calEvent.StartDate = (ev.StartDate + new TimeSpan(ev.Calendar.TimeZone, 0, 0));
                    calEvent.EndDate = (ev.EndDate + new TimeSpan(ev.Calendar.TimeZone, 0, 0));
                }

                calEvent.StartDateDisplay = calEvent.StartDate.ToShortDateString();
                calEvent.EndDateDisplay = calEvent.EndDate.ToShortDateString();
                calEvent.Link = ev.Link;
                if (!String.IsNullOrEmpty(ev.Link) && !ev.Link.Contains("http://") && !ev.Link.Contains("https://"))
                    calEvent.Link = "http://" + ev.Link;
                else
                    calEvent.Link = ev.Link;
                calEvent.Notes = ev.Notes;

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

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

                calEvent.AllowSelfCheckIn = ev.AllowSelfCheckIn;
                var isApartOfEvent = calEvent.MembersApartOfEvent.Where(x => x.MemberId == currentMemberId).FirstOrDefault();
                if (calEvent.AllowSelfCheckIn && calEvent.IsCurrentMemberApartOfEvent || (calEvent.AllowSelfCheckIn && isApartOfEvent != null))
                    calEvent.CanCurrentUserCheckIn = true;
            }
            catch (Exception exception)
            {
                ErrorDatabaseManager.AddException(exception, exception.GetType());
            }
            return calEvent;
        }