protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e)
        {
            base.OnNavigatedTo(e);

            try
            {
                ev = new CalendarEventPortable();
                var ob = (App.Current as App).SecondPageObject;
                if (ob != null)
                    ev = (CalendarEventPortable)ob;
                (App.Current as App).SecondPageObject = null;
                progressIndicator = SystemTray.ProgressIndicator;
                progressIndicator = new ProgressIndicator();
                SystemTray.SetProgressIndicator(this, progressIndicator);
                progressIndicator.IsIndeterminate = true;
                progressIndicator.Text = "Saving Checkin...";
                if (SettingsMobile.Instance.User == null)
                {
                    SqlFactory fact = new SqlFactory();
                    SettingsMobile.Instance.User = fact.GetProfile();
                }
                CheckInTypeSelect.ItemsSource = CalendarEventPointTypeEnumHelper.CalendarEventPointTypes;
                ev.CalendarItemId = new Guid(this.NavigationContext.QueryString["evId"]);
                ev.CalendarId = new Guid(this.NavigationContext.QueryString["calId"]);
                ev.Name = this.NavigationContext.QueryString["name"];
                if (!String.IsNullOrEmpty(ev.Name))
                    EventName.Text = ev.Name;
            }
            catch (Exception exception)
            {
                ErrorHandler.Save(exception, MobileTypeEnum.WP8);
            }

        }
        protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e)
        {
            base.OnNavigatedTo(e);

            try
            {
                if (e.NavigationMode == NavigationMode.New)
                {
                    calendarModel = new CalendarEventPortable();

                    //(App.Current as App).SecondPageObject = null;
                    progressIndicator = SystemTray.ProgressIndicator;
                    progressIndicator = new ProgressIndicator();
                    SystemTray.SetProgressIndicator(this, progressIndicator);
                    progressIndicator.IsIndeterminate = true;
                    progressIndicator.Text = "Pulling Info...";
                    if (SettingsMobile.Instance.User == null)
                    {
                        SqlFactory fact = new SqlFactory();
                        SettingsMobile.Instance.User = fact.GetProfile();
                    }
                    StartTime.Value = new DateTime(DateTime.UtcNow.Year, DateTime.UtcNow.Month, DateTime.UtcNow.Day, DateTime.UtcNow.Hour, 0, 0);
                    EndTime.Value = new DateTime(DateTime.UtcNow.Year, DateTime.UtcNow.Month, DateTime.UtcNow.Day, DateTime.UtcNow.Hour, 0, 0);
                    calendarModel.CalendarId = SettingsMobile.Instance.AccountSettings.CalendarId;
                    calendarModel.MemberId = SettingsMobile.Instance.User.MemberId;
                    calendarModel.UserId = SettingsMobile.Instance.User.LoginId;
                    LoadInitialData();
                }
            }
            catch (Exception exception)
            {
                ErrorHandler.Save(exception, MobileTypeEnum.WP8);
            }
        }
 public static CalendarEventPortable CreateNewEvent(CalendarEventPortable ev)
 {
     Random r = new Random();
     var response = Network.SendPackage(Network.ConvertObjectToStream(ev), MobileConfig.LEAGUE_CALENDAR_CREATE_NEW_EVENT_URL + "?r=" + r.Next());
     var stream = response.GetResponseStream();
     StreamReader read = new StreamReader(stream);
     string json = read.ReadToEnd();
     return Json.DeserializeObject<CalendarEventPortable>(json);
 }
        protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e)
        {
            base.OnNavigatedTo(e);

            try
            {
                if (e.NavigationMode == NavigationMode.New)
                {
                    calendarModel = new CalendarEventPortable();

                    //(App.Current as App).SecondPageObject = null;
                    progressIndicator = SystemTray.ProgressIndicator;
                    progressIndicator = new ProgressIndicator();
                    SystemTray.SetProgressIndicator(this, progressIndicator);
                    progressIndicator.IsIndeterminate = true;
                    progressIndicator.Text = "Pulling Event...";
                    if (SettingsMobile.Instance.User == null)
                    {
                        SqlFactory fact = new SqlFactory();
                        SettingsMobile.Instance.User = fact.GetProfile();
                    }
                    //if (SettingsMobile.Instance.AccountSettings.IsEventsCoordinatorOrBetter)
                    //{
                    //    ApplicationBar.IsVisible = true;
                    //}
                    calendarModel.CalendarItemId = new Guid(this.NavigationContext.QueryString["evId"]);
                    PullDues();
                }
            }
            catch (Exception exception)
            {
                ErrorHandler.Save(exception, MobileTypeEnum.WP8);
            }



        }
        void PullDues()
        {
            Dispatcher.BeginInvoke(delegate
            {
                progressIndicator.IsVisible = true;
            });
            try
            {
                Task.Run(new Action(() =>
                {
                    calendarModel = CalendarMobile.GetCalendarEvent(SettingsMobile.Instance.User.MemberId, SettingsMobile.Instance.User.LoginId, SettingsMobile.Instance.AccountSettings.CalendarId, calendarModel.CalendarItemId);

                    Members = new ObservableCollection<CalendarAttendance>();
                    for (int i = 0; i < calendarModel.Attendees.Count; i++)
                        Members.Add(calendarModel.Attendees[i]);
                    for (int i = 0; i < calendarModel.MembersToCheckIn.Count; i++)
                        Members.Add(calendarModel.MembersToCheckIn[i]);

                    Dispatcher.BeginInvoke(delegate
                    {
                        try
                        {
                            pivotTitle.Title = calendarModel.Name;
                            Description.Text = StringExt.HtmlDecode(calendarModel.NotesHtml);
                            StartDate.Text = calendarModel.StartDate.ToLongDateString();
                            StartTime.Text = calendarModel.StartDate.ToShortTimeString();
                            EndTime.Text = calendarModel.EndDate.ToShortDateString();
                            if (calendarModel.Location != null)
                            {
                                Location.Text = calendarModel.Location.LocationName;
                                if (calendarModel.Location.Contact.Addresses.FirstOrDefault() != null)
                                {
                                    Address1.Text = calendarModel.Location.Contact.Addresses.FirstOrDefault().Address1;
                                    if (!String.IsNullOrEmpty(calendarModel.Location.Contact.Addresses.FirstOrDefault().Address2))
                                    {
                                        Address1.Text += "," + calendarModel.Location.Contact.Addresses.FirstOrDefault().Address2;
                                    }
                                    if (!String.IsNullOrEmpty(calendarModel.Location.Contact.Addresses.FirstOrDefault().CityRaw))
                                    {
                                        Address2.Text = calendarModel.Location.Contact.Addresses.FirstOrDefault().CityRaw;
                                    }
                                    if (!String.IsNullOrEmpty(calendarModel.Location.Contact.Addresses.FirstOrDefault().StateRaw))
                                    {
                                        Address2.Text += ", " + calendarModel.Location.Contact.Addresses.FirstOrDefault().StateRaw;
                                    }
                                    if (!String.IsNullOrEmpty(calendarModel.Location.Contact.Addresses.FirstOrDefault().Zip))
                                    {
                                        Address2.Text += " " + calendarModel.Location.Contact.Addresses.FirstOrDefault().Zip;
                                    }
                                    if (!String.IsNullOrEmpty(calendarModel.Location.Contact.Addresses.FirstOrDefault().Country))
                                    {
                                        Address3.Text = calendarModel.Location.Contact.Addresses.FirstOrDefault().Country;
                                    }
                                }
                            }
                            RDNationUrl.Text = calendarModel.RDNationLink;
                            TicketUrl.Text = calendarModel.TicketUrl;
                            WebsiteUrl.Text = calendarModel.Link;
                            RosterList.ItemsSource = Members;
                            progressIndicator.IsVisible = false;
                        }
                        catch (Exception exception)
                        {
                            ErrorHandler.Save(exception, MobileTypeEnum.WP8);
                        }



                    });

                }));

            }
            catch (Exception exception)
            {
                ErrorHandler.Save(exception, MobileTypeEnum.WP8);
            }
        }
        void PullDues()
        {
            Dispatcher.BeginInvoke(delegate
            {
                progressIndicator.IsVisible = true;
            });
            try
            {
                Task.Run(new Action(() =>
                {
                    try
                    {
                        calendarModel = CalendarMobile.GetCalendarEvent(SettingsMobile.Instance.User.MemberId, SettingsMobile.Instance.User.LoginId, SettingsMobile.Instance.AccountSettings.CalendarId, calendarModel.CalendarItemId);


                        var checkedIn = calendarModel.Attendees.Where(x => x.PointType != CalendarEventPointTypeEnum.None).ToList();
                        var available = calendarModel.Attendees.Where(x => x.Availability != AvailibilityEnum.None).ToList();


                        Dispatcher.BeginInvoke(delegate
                        {
                            try
                            {
                                pivotTitle.Title = calendarModel.Name;
                                Description.Text = StringExt.HtmlDecode(calendarModel.NotesHtml);
                                StartDate.Text = calendarModel.StartDate.ToLongDateString();
                                StartTime.Text = calendarModel.StartDate.ToShortTimeString();
                                EndTime.Text = calendarModel.EndDate.ToShortDateString();
                                if (calendarModel.Location != null)
                                {
                                    Location.Text = calendarModel.Location.LocationName;
                                    if (calendarModel.Location.Contact.Addresses.FirstOrDefault() != null)
                                    {
                                        Address1.Text = calendarModel.Location.Contact.Addresses.FirstOrDefault().Address1;
                                        if (!String.IsNullOrEmpty(calendarModel.Location.Contact.Addresses.FirstOrDefault().Address2))
                                        {
                                            Address1.Text += "," + calendarModel.Location.Contact.Addresses.FirstOrDefault().Address2;
                                        }
                                        if (!String.IsNullOrEmpty(calendarModel.Location.Contact.Addresses.FirstOrDefault().CityRaw))
                                        {
                                            Address2.Text = calendarModel.Location.Contact.Addresses.FirstOrDefault().CityRaw;
                                        }
                                        if (!String.IsNullOrEmpty(calendarModel.Location.Contact.Addresses.FirstOrDefault().StateRaw))
                                        {
                                            Address2.Text += ", " + calendarModel.Location.Contact.Addresses.FirstOrDefault().StateRaw;
                                        }
                                        if (!String.IsNullOrEmpty(calendarModel.Location.Contact.Addresses.FirstOrDefault().Zip))
                                        {
                                            Address2.Text += " " + calendarModel.Location.Contact.Addresses.FirstOrDefault().Zip;
                                        }
                                        if (!String.IsNullOrEmpty(calendarModel.Location.Contact.Addresses.FirstOrDefault().Country))
                                        {
                                            Address3.Text = calendarModel.Location.Contact.Addresses.FirstOrDefault().Country;
                                        }
                                    }
                                }
                                RDNationUrl.Text = calendarModel.RDNationLink;
                                TicketUrl.Text = calendarModel.TicketUrl;
                                WebsiteUrl.Text = calendarModel.Link;
                                RosterList.ItemsSource = available;
                                checkedInList.ItemsSource = checkedIn;
                                progressIndicator.IsVisible = false;
                            }
                            catch (Exception exception)
                            {
                                ErrorHandler.Save(exception, MobileTypeEnum.WP8);
                            }
                        });
                    }
                    catch (Exception exception)
                    {
                        ErrorHandler.Save(exception, MobileTypeEnum.WP8);
                    }
                }));

            }
            catch (Exception exception)
            {
                ErrorHandler.Save(exception, MobileTypeEnum.WP8);
            }
        }
        public ActionResult EventCalendarExport(CalendarEventPortable cal)
        {
            try
            {
                var memId = RDN.Library.Classes.Account.User.GetMemberId();
                return new FileStreamResult(CalendarEventFactory.ExportEvent(cal.CalendarItemId, memId), "text/calendar") { FileDownloadName = RDN.Utilities.Strings.StringExt.ToSearchEngineFriendly(cal.Name) + ".ics" };

            }
            catch (Exception exception)
            {
                ErrorDatabaseManager.AddException(exception, exception.GetType());
            }
            return Redirect(Url.Content("~/?u=" + SiteMessagesEnum.sww));
        }
        public static CalendarEventPortable DisplayStartDate(MemberDisplay member)
        {
            CalendarEventPortable calEvent = new CalendarEventPortable();
            try
            {

                calEvent.EventType.EventType = CalendarEventTypeEnum.StartSkatingDate;

                calEvent.Name = member.DerbyName + " Started Skating Today";
                calEvent.NameUrl = ServerConfig.WEBSITE_DEFAULT_LOCATION + "/started-skating-roller-derby/" + member.MemberId.ToString().Replace("-", "") + "/" + RDN.Utilities.Strings.StringExt.ToSearchEngineFriendly(member.DerbyName);
                calEvent.CalendarItemId = member.MemberId;
                try
                {
                    //put this because some years don't allow a leap year for Feb.
                    DateTime dt = new DateTime(DateTime.UtcNow.Year, member.StartedSkating.Value.Month, member.StartedSkating.Value.Day);
                    calEvent.StartDate = dt;
                    calEvent.EndDate = dt;
                }
                catch { }
                calEvent.StartDateDisplay = member.StartedSkating.Value.Month + "/" + member.StartedSkating.Value.Day + "/" + DateTime.UtcNow.Year;
                calEvent.EndDateDisplay = member.StartedSkating.Value.Month + "/" + member.StartedSkating.Value.Day + "/" + DateTime.UtcNow.Year;
            }
            catch (Exception exception)
            {
                ErrorDatabaseManager.AddException(exception, exception.GetType(), additionalInformation: member.StartedSkating.Value.Month + ":" + member.StartedSkating.Value.Day);
            }
            return calEvent;
        }
        public static CalendarEventPortable DisplayBirthday(MemberDisplay member)
        {
            CalendarEventPortable calEvent = new CalendarEventPortable();
            try
            {

                calEvent.EventType.EventType = CalendarEventTypeEnum.Birthday;

                calEvent.Name = member.DerbyName + " Birthday";
                calEvent.NameUrl = ServerConfig.WEBSITE_DEFAULT_LOCATION + "/roller-derby-birthday/" + RDN.Utilities.Strings.StringExt.ToSearchEngineFriendly(member.DerbyName) + "/" + member.MemberId.ToString().Replace("-", "");
                calEvent.CalendarItemId = member.MemberId;
                DateTime dt = new DateTime(DateTime.UtcNow.Year, member.DOB.Month, member.DOB.Day);

                calEvent.StartDate = dt;
                calEvent.StartDateDisplay = dt.ToShortDateString();
                calEvent.EndDate = dt;
                calEvent.EndDateDisplay = dt.ToShortDateString();
            }
            catch (Exception exception)
            {
                ErrorDatabaseManager.AddException(exception, exception.GetType());
            }
            return calEvent;
        }