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

            try
            {
                topic = new ForumTopicModel();

                //(App.Current as App).SecondPageObject = null;
                progressIndicator = SystemTray.ProgressIndicator;
                progressIndicator = new ProgressIndicator();
                SystemTray.SetProgressIndicator(this, progressIndicator);
                progressIndicator.IsIndeterminate = true;
                progressIndicator.Text = "Pulling Topic...";
                if (SettingsMobile.Instance.User == null)
                {
                    SqlFactory fact = new SqlFactory();
                    SettingsMobile.Instance.User = fact.GetProfile();
                }
                topic.TopicId = Convert.ToInt64(this.NavigationContext.QueryString["tid"]);
                PullTopic();
            }
            catch (Exception exception)
            {
                ErrorHandler.Save(exception, MobileTypeEnum.WP8);
            }

        }
        public ReplyToPost()
        {
            InitializeComponent();
            try
            {
                progressIndicator = SystemTray.ProgressIndicator;
                progressIndicator = new ProgressIndicator();

                SystemTray.SetProgressIndicator(this, progressIndicator);
                progressIndicator.IsIndeterminate = true;
                progressIndicator.Text = "Posting Reply...";

                forumModel = (ForumTopicModel)(App.Current as App).SecondPageObject;
                (App.Current as App).SecondPageObject = null;

                TopicName.Text = forumModel.TopicName;

            }
            catch (Exception exception)
            {
                ErrorHandler.Save(exception, MobileTypeEnum.WP8);
            }
        }
        void ReturnForumTopic(ForumTopicModel model)
        {
            try
            {
                topic = model;
                MessageList.ItemsSource = topic.Posts;

                Dispatcher.BeginInvoke(delegate
                {
                    topicName.Title = topic.TopicName;
                    if (topic.IsLocked)
                    {
                        ApplicationBarIconButton b = (ApplicationBarIconButton)ApplicationBar.Buttons[0];
                        b.IsEnabled = false;
                    }
                    for (int i = 0; i < topic.TopicInbox.Count; i++)
                        Unread.Text += topic.TopicInbox[i].DerbyName + ", ";
                    Category.Text = topic.Category;
                    Locked.Text = topic.IsLocked.ToString();
                    Pinned.Text = topic.IsPinned.ToString();
                    Watching.Text = topic.IsWatching.ToString();
                    StartedBy.Text = topic.StartedByName;
                    ViewCount.Text = topic.ViewCount.ToString();
                    if (topic.IsWatching)
                    {
                        ApplicationBarIconButton b = (ApplicationBarIconButton)ApplicationBar.Buttons[1];
                        b.Text = "UnWatch";
                    }
                    MessageList.ItemsSource = topic.Posts;
                    progressIndicator.IsVisible = false;
                });
            }
            catch (Exception exception)
            {
                ErrorHandler.Save(exception, MobileTypeEnum.WP8);
            }
        }
 public ForumTopicViewController(ForumTopicModel forumTopic)
 {
     initialModel = forumTopic;
     initialArray = new List<ForumPostModel>();
 }
        void UpdateAdapter(ForumTopicModel skaters)
        {
            initialModel = skaters;
            initialArray.Clear();
            initialArray.AddRange(skaters.Posts);
            InvokeOnMainThread(() =>
            {
                try
                {
                    table.ReloadData();
                    loading.Hide();
                }
                catch (Exception exception)
                {
                    ErrorHandler.Save(exception, MobileTypeEnum.iPhone);
                }
            });



        }
        public JsonResult Posts(string mid, string uid, string t, string gid, string cid, int p, int c)
        {
            ForumModel model = new ForumModel();
            try
            {
                var mem = MemberCache.GetMemberDisplay(new Guid(mid));
                if (new Guid(uid) == mem.UserId)
                {

                    long gId = 0;
                    if (!String.IsNullOrEmpty(gid))
                        gId = Convert.ToInt64(gid);

                    Guid forumId = MemberCache.GetForumIdForMemberLeague(new Guid(mid));
                    var topics = Forum.GetForumTopics(new Guid(mid), forumId, (ForumOwnerTypeEnum)Enum.Parse(typeof(ForumOwnerTypeEnum), t), gId, c, p, false);

                    model.ForumId = forumId;
                    model.GroupId = gId;

                    for (int i = 0; i < topics.GroupTopics.Count; i++)
                    {
                        ForumGroupModel group = new ForumGroupModel();
                        group.GroupId = topics.GroupTopics[i].GroupId;
                        group.GroupName = topics.GroupTopics[i].GroupName;
                        group.Categories = topics.Categories;

                        for (int j = 0; j < topics.GroupTopics[i].Topics.Count; j++)
                        {
                            ForumTopicModel topic = new ForumTopicModel();
                            if (topics.GroupTopics[i].Topics[j].Category != null)
                            {
                                topic.Category = topics.GroupTopics[i].Topics[j].Category.CategoryName;
                                topic.CategoryId = topics.GroupTopics[i].Topics[j].Category.CategoryId;
                            }
                            if (topics.GroupTopics[i].Topics[j].LastPostByMember != null)
                            {
                                topic.LastPostById = topics.GroupTopics[i].Topics[j].LastPostByMember.MemberId;
                                topic.LastPostByName = topics.GroupTopics[i].Topics[j].LastPostByMember.DerbyName;
                            }
                            topic.PostCount = topics.GroupTopics[i].Topics[j].Replies;
                            if (topics.GroupTopics[i].Topics[j].CreatedByMember != null)
                            {
                                topic.StartedById = topics.GroupTopics[i].Topics[j].CreatedByMember.MemberId;
                                topic.StartedByName = topics.GroupTopics[i].Topics[j].CreatedByMember.DerbyName;
                            }
                            topic.StartedRelativeTime = topics.GroupTopics[i].Topics[j].CreatedHuman;
                            topic.TopicId = topics.GroupTopics[i].Topics[j].TopicId;
                            topic.ForumId = forumId;
                            topic.HasRead = topics.GroupTopics[i].Topics[j].IsRead;
                            topic.IsLocked = topics.GroupTopics[i].Topics[j].IsLocked;
                            topic.IsManagerOfTopic = topics.GroupTopics[i].Topics[j].IsManagerOfTopic;
                            topic.IsPinned = topics.GroupTopics[i].Topics[j].IsPinned;
                            topic.IsWatching = topics.GroupTopics[i].Topics[j].IsWatching;
                            topic.TopicName = topics.GroupTopics[i].Topics[j].TopicTitle;
                            topic.ViewCount = topics.GroupTopics[i].Topics[j].ViewCount;
                            topic.LastPostRelativeTime = topics.GroupTopics[i].Topics[j].LastModifiedHuman;
                            group.Topics.Add(topic);
                        }
                        group.UnreadTopicsCount = group.Topics.Where(x => x.HasRead == false).Count();
                        model.Groups.Add(group);
                    }


                    if (!String.IsNullOrEmpty(cid))
                        model.CategoryId = Convert.ToInt64(cid);
                }
            }
            catch (Exception exception)
            {
                ErrorDatabaseManager.AddException(exception, exception.GetType());
            }

            return Json(model, JsonRequestBehavior.AllowGet);
        }
        public JsonResult Topic(string mid, string uid, string tid)
        {
            ForumTopicModel model = new ForumTopicModel();
            try
            {
                var mem = MemberCache.GetMemberDisplay(new Guid(mid));
                if (new Guid(uid) == mem.UserId)
                {
                    long tId = 0;
                    if (!String.IsNullOrEmpty(tid))
                        tId = Convert.ToInt64(tid);

                    Guid forumId = MemberCache.GetForumIdForMemberLeague(new Guid(mid));
                    Forum.UpdatePostViewCount(forumId, tId, new Guid(mid));
                    Forum.MarkAsRead(forumId, tId, new Guid(mid));


                    var topic = ForumTopicCache.GetTopic(forumId, tId);

                    var isWatching = topic.Watchers.Where(x => x.MemberId == mem.MemberId).FirstOrDefault();
                    if (isWatching != null)
                        model.IsWatching = true;
                    else
                        model.IsWatching = false;

                    if (topic.Category != null)
                    {
                        model.Category = topic.Category.CategoryName;
                        model.CategoryId = topic.Category.CategoryId;
                    }
                    if (topic.LastPostByMember != null)
                    {
                        model.LastPostById = topic.LastPostByMember.MemberId;
                        model.LastPostByName = topic.LastPostByMember.DerbyName;
                    }
                    model.LastPostRelativeTime = topic.LastModifiedHuman;
                    model.PostCount = topic.Replies;
                    if (topic.CreatedByMember != null)
                    {
                        model.StartedById = topic.CreatedByMember.MemberId;
                        model.StartedByName = topic.CreatedByMember.DerbyName;
                    }
                    model.StartedRelativeTime = topic.CreatedHuman;
                    model.TopicId = topic.TopicId;
                    model.TopicName = topic.TopicTitle;
                    model.ViewCount = topic.ViewCount;
                    model.IsLocked = topic.IsLocked;
                    model.IsPinned = topic.IsPinned;
                    model.HasRead = topic.IsRead;
                    model.IsManagerOfTopic = topic.IsManagerOfTopic;
                    model.TopicInbox = topic.TopicInbox;
                    model.ForumId = forumId;

                    for (int i = 0; i < topic.Messages.Count; i++)
                    {
                        ForumPostModel post = new ForumPostModel();
                        post.DatePosted = topic.Messages[i].Created;
                        if (topic.Messages[i].Member != null)
                        {
                            post.PostedById = topic.Messages[i].Member.MemberId;
                            post.PostedByName = topic.Messages[i].Member.DerbyName;
                            if (topic.Messages[i].Member.Photos.FirstOrDefault() != null)
                                post.PostedByPictureUrl = topic.Messages[i].Member.Photos.FirstOrDefault().ImageThumbUrl;
                        }
                        post.Text = topic.Messages[i].MessagePlain;
                        post.DatePostedByHuman = topic.Messages[i].CreatedHumanRelative;
                        model.Posts.Add(post);
                    }

                }
            }
            catch (Exception exception)
            {
                ErrorDatabaseManager.AddException(exception, exception.GetType());
            }

            return Json(model, "application/json", JsonRequestBehavior.AllowGet);
        }