protected void Page_Load(object sender, EventArgs e)
        {
            if (IsUserLoggedIn)
            {
                ActivityLog log = new ActivityLog();
                if (log.FoundItemHelpful(context.ID.ToGuid(), CurrentMember.MemberId))
                {
                    btnYes.Attributes.Add("class", "button helpful-yes");
                    btnNo.Attributes.Add("class", "helpful-no");
                }
                else if (log.FoundItemNotHelpful(context.ID.ToGuid(), CurrentMember.MemberId))
                {
                    btnNo.Attributes.Add("class", "button helpful-no");
                    btnYes.Attributes.Add("class", "helpful-yes");
                }
                else
                {
                    btnNo.Attributes.Add("class", "helpful-no");
                    btnYes.Attributes.Add("class", "helpful-yes");

                }

            }
            else
            {
                btnNo.Attributes.Add("class", "helpful-no");
                btnYes.Attributes.Add("class", "helpful-yes");
            }


            ltlDidYouFindThisHelpful.Text = DictionaryConstants.DidYouFindThisHelpful;
            btnNo.InnerText = DictionaryConstants.NoButtonText;
            btnYes.InnerText = DictionaryConstants.YesButtonText;
        }
        public IEnumerable<DefaultArticlePageItem> GetPopularArticles(int page, out bool hasMoreResults)
        {
            var log = new ActivityLog();
            var articleIds = log.GetMostPopularArticleIdsBySubtopic(InnerItem, page, Constants.SUBTOPIC_LISTING_ARTICLES_PER_PAGE, out hasMoreResults);

            return articleIds.Select(x => (DefaultArticlePageItem)Sitecore.Context.Database.GetItem(Sitecore.Data.ID.Parse(x)))
                            .Where(x => x != null);
        }
        private void PopulateCount()
        {
            ActivityLog tempLog = new ActivityLog();
            
            int helpfulCount = tempLog.GetActivityCountByValue(Guid.Parse(this.model.ID.ToString()), Constants.UserActivity_Values.FoundHelpful_True);

            lblHelpfulCount.Text = lblHelpfulCountMobile.Text = helpfulCount.ToString();

            ltlFoundThisHelpful.Text = ltlFoundThisHelpfulMobile.Text = DictionaryConstants.FoundThisHelpful;
        }
        private void BindData(DefaultArticlePageItem page)
        {
            ActivityLog tempLog = new ActivityLog();
            //ContentId, ActivityValue
            int helpfulCount = tempLog.GetActivityCountByValue(new Guid(Sitecore.Context.Item.ID.ToString()), Constants.UserActivity_Values.FoundHelpful_True );

            lblHelpfulCount.Text = lblHelpfulCountMobile.Text = helpfulCount.ToString();

            ltlFoundThisHelpful.Text = ltlFoundThisHelpfulMobile.Text = DictionaryConstants.FoundThisHelpful;
        }
        protected void btnThisHelped_Click(object sender, EventArgs e)
        {
            if (IsUserLoggedIn)
            {
                var currentMember = this.CurrentMember;
                ActivityLog log = new ActivityLog();
                LinkButton btn = (LinkButton)(sender);
                string ids = btn.CommandArgument;
                string[] s = ids.Split('&');
                Guid? ContentId = s[0].AsNGuid();
                string contentTypeId = s[1];
                Guid MemberId = this.CurrentMember.MemberId;
                if (ContentId.HasValue && !(log.FoundItemHelpful(ContentId.Value, MemberId)))
                {
                    // instantiate MM
                    MembershipManager mgr = new MembershipManager();
                    // write to the DB
                    mgr.LogMemberHelpfulVote(MemberId, ContentId.Value, Constants.UserActivity_Values.FoundHelpful_True, Constants.UserActivity_Types.FoundHelpfulVote);
                    Response.Redirect(Request.RawUrl);
                    
                }
            }

            else
            {
                //this.ProfileRedirect(Constants.UserPermission.CommunityUser);
            }

            //var webClient = new WebClient();

            //// replace the "admin" and "Admin's API key" with your valid user and apikey!
            //var adminKey = String.Format("{0}:{1}", Settings.GetSetting(Constants.Settings.TelligentAdminApiKey), "admin");
            //var adminKeyBase64 = Convert.ToBase64String(Encoding.UTF8.GetBytes(adminKey));

            //webClient.Headers.Add("Rest-User-Token", adminKeyBase64);
            //webClient.Headers.Add("Rest-Impersonate-User", this.CurrentMember.ScreenName.Trim());
            //var requestUrl = String.Format("{0}api.ashx/v2/likes.xml", Settings.GetSetting(Constants.Settings.TelligentConfig));

            //var values = new NameValueCollection();
            //values.Add("ContentId", contentId);
            //values.Add("ContentTypeId", contentTypeId);

            //var xml = Encoding.UTF8.GetString(webClient.UploadValues(requestUrl, values));

            //Console.WriteLine(xml);
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            if (IsUserLoggedIn)
            {
                //ActivityLog log = new ActivityLog(CurrentMember.MemberId, Constants.UserActivity_Values.FoundHelpful_True);
                //ActivityItem temp = log.Activities.Where(i => i.ContentId == context.ID.ToGuid()).FirstOrDefault();
                ActivityLog log = new ActivityLog();
                if (log.FoundItemHelpful(context.ID.ToGuid(), CurrentMember.MemberId))
                {
                    btnYes.Attributes.Add("class", "button helpful-yes");
                    btnSmallYes.Attributes.Add("class", "button helpful-yes");
                    btnNo.Attributes.Add("class", "helpful-no");
                    btnSmallNo.Attributes.Add("class", "helpful-no");
                }
                else if (log.FoundItemNotHelpful(context.ID.ToGuid(), CurrentMember.MemberId))
                {
                    btnNo.Attributes.Add("class", "button helpful-no");
                    btnSmallNo.Attributes.Add("class", "button helpful-no");
                    btnYes.Attributes.Add("class", "helpful-yes");
                    btnSmallYes.Attributes.Add("class", "helpful-yes");
                }
                else
                {
                    btnNo.Attributes.Add("class", "helpful-no");
                    btnSmallNo.Attributes.Add("class", "helpful-no");
                    btnYes.Attributes.Add("class", "helpful-yes");
                    btnSmallYes.Attributes.Add("class", "helpful-yes");
           
                }

            }
            else
            {
                btnNo.Attributes.Add("class", "helpful-no");
                btnSmallNo.Attributes.Add("class", "helpful-no");
                btnYes.Attributes.Add("class", "helpful-yes");
                btnSmallYes.Attributes.Add("class", "helpful-yes");
            }
            ltlDidYouFindThisHelpful.Text = ltlDidYouFindThisHelpfulSmall.Text = DictionaryConstants.DidYouFindThisHelpful;
            btnNo.InnerText = btnSmallNo.InnerText = DictionaryConstants.NoButtonText;
            btnYes.InnerText = btnSmallYes.InnerText = DictionaryConstants.YesButtonText;
        }
 protected void btnYes_ServerClick(object sender, EventArgs e)
 {
     ActivityLog log = new ActivityLog();
     if (IsUserLoggedIn)
     {
         if (!(log.FoundItemHelpful(context.ID.ToGuid(), CurrentMember.MemberId)))
         {
             VoteYes();
         }
         else
         {
             VoteNeutral();
         }
     }
     else
     {
         Page.Session[Constants.SessionPreviousUrl] = null;
         this.ProfileRedirect(UnderstoodDotOrg.Common.Constants.UserPermission.RegisteredUser);
     }
 }
        protected void Page_Load(object sender, EventArgs e)
        {
            if (DataSource != null && DataSource.InheritsFromType(ContentPageItem.TemplateId))
            {
                BindData((ContentPageItem)DataSource);
            }

            UpdatePanel1.Attributes.Add("style", "display: inline-block;");

            if (IsUserLoggedIn)
            {
                ActivityLog log = new ActivityLog(CurrentMember.MemberId, Constants.UserActivity_Values.Favorited);
                ActivityItem temp = log.Activities.Where(i => i.ContentId == context.ID.ToGuid()).FirstOrDefault();
                if (temp != null)
                {
                    lbSave.Attributes.Add("class", "icon-plus active");
                    lbSave.ServerClick += lbUnsave_Click;
                    lbSave.ServerClick -= lbSave_Click;
                }
            }
        }
        private void BindData(Item thePage)
        {
            string BlogId = "";
            string BlogPostId = "";

            if (thePage.TemplateID.ToString() == DefaultArticlePageItem.TemplateId)
            {
                BlogId = new DefaultArticlePageItem(thePage).BlogId.Raw;
                BlogPostId = new DefaultArticlePageItem(thePage).BlogPostId.Raw;
            }
            else if (thePage.TemplateID.ToString() == BehaviorToolsAdvicePageItem.TemplateId)
            {
                BlogId = new BehaviorAdvicePageItem(thePage).BlogId.Raw;
                BlogPostId = new BehaviorAdvicePageItem(thePage).BlogPostId.Raw;
            }

            ActivityLog tempLog = new ActivityLog();
            //ContentId, ActivityValue
            int helpfulCount = tempLog.GetActivityCountByValue(new Guid(Sitecore.Context.Item.ID.ToString()), Constants.UserActivity_Values.FoundHelpful_True);
            int commentCount = 0;

            if (!string.IsNullOrEmpty(BlogId) && !string.IsNullOrEmpty(BlogPostId))
            {
                commentCount = CommunityHelper.GetTotalComments(BlogId, BlogPostId);
            }

            lblHelpfulCount.Text = lblHelpfulCountMobile.Text = helpfulCount.ToString();
            lblCommentCount.Text = lblCommentCountMobile.Text = commentCount.ToString();

            ltlFoundThisHelpful.Text = ltlFoundThisHelpfulMobile.Text = DictionaryConstants.FoundThisHelpful;

            string commentLabel = DictionaryConstants.PluralCommentLabel;
            if (commentCount == 1)
            {
                commentLabel = DictionaryConstants.SingleCommentLabel;
            }

            ltlComments.Text = ltlCommentsMobile.Text = commentLabel;
        }
        public Dictionary<string,string> GetArticleFilters()
        {
            var filters = new Dictionary<string, string>();

            filters.Add(string.Empty, DictionaryConstants.Featured);

            // Popular
            var log = new ActivityLog();
            if (log.HasPopularArticlesBySubtopic(InnerItem))
            {
                filters.Add(Guid.Empty.ToString(), DictionaryConstants.PopularLabel);
            }

            // Article type filter
            var articles = this.InnerItem
                                .Children
                                .FilterByContextLanguageVersion();
            if (articles.Any())
            {
                // Grab unique article template ids for this subtopic
                var templates = articles.Select(x => x.TemplateID)
                                    .Distinct();

                foreach (Sitecore.Data.ID templateId in templates)
                {
                    string label = DefaultArticlePageItem.GetArticleType(templateId);
                    if (!string.IsNullOrEmpty(label))
                    {
                        filters.Add(templateId.ToString(), label);
                    }
                    else
                    {
                        Sitecore.Diagnostics.Log.Info(String.Format("No article type found for template: {0}", templateId), this);
                    }
                }
            }

            return filters;
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            Guid? ContentId = new Guid(blogCig.ContentId.Raw);

            // Guid ContentId = new Guid(blogCig.ContentId.Raw);
            // Guid MemberId = this.CurrentMember.MemberId;
            ActivityLog log = new ActivityLog();

            //bool washelpful = log.FoundItemHelpful(ContentId, MemberId);
            int likeCount = log.GetActivityCountByValue(new Guid(blogCig.ContentId.Raw), Constants.UserActivity_Values.FoundHelpful_True);
            string commentCount = CommunityHelper.GetTotalComments(blogCig.BlogId, blogCig.BlogPostId).ToString();

            //to get if the content was NOT helpful
            //bool wasNOThelpful = log.FoundItemNotHelpful(ContentId, MemberId);
            //LikeCount.Text = CommunityHelper.GetTotalLikes(ContentId.ToString()).ToString();
            var blogId = blogCig.BlogId.Raw;
            var blogPostId = blogCig.BlogPostId.Raw;
            CommentCount.Text = commentCount;
            LikeCount.Text = likeCount.ToString();
            var blogPostInfo = CommunityHelper.ReadBlogBody(Int32.Parse(blogId), Int32.Parse(blogPostId));
            btnLike.CommandArgument = btnUnlike.CommandArgument = blogPostInfo.ContentId + "&" + blogPostInfo.ContentTypeId;
             
           
        }
        protected void btnDidntHelp_Click(object sender, EventArgs e)
        {
            if (IsUserLoggedIn)
            {
                var currentMember = this.CurrentMember;
                ActivityLog log = new ActivityLog();
                LinkButton btn = (LinkButton)(sender);
                string ids = btn.CommandArgument;
                string[] s = ids.Split('&');
                Guid? ContentId = s[0].AsNGuid();
                string contentTypeId = s[1];
                Guid MemberId = this.CurrentMember.MemberId;
                if (ContentId.HasValue && !(log.FoundItemNotHelpful(ContentId.Value, MemberId)))
                {
                    // instantiate MM
                    MembershipManager mgr = new MembershipManager();
                    // write to the DB
                    mgr.LogMemberHelpfulVote(MemberId, ContentId.Value, Constants.UserActivity_Values.FoundHelpful_False, Constants.UserActivity_Types.FoundHelpfulVote);
                    Response.Redirect(Request.RawUrl);
                }
                //ActivityLog log = new ActivityLog();
                //LinkButton btn = (LinkButton)(sender);
                //string ids = btn.CommandArgument;
                //string[] s = ids.Split('&');
                //Guid ContentId = new Guid(s[0]);
                //string contentTypeId = s[1];
                //Guid MemberId = this.CurrentMember.MemberId;


                //if ((log.FoundItemHelpful(ContentId, MemberId)))
                //{
                //    // instantiate MM
                //    MembershipManager mgr = new MembershipManager();
                //    // write to the DB
                //    mgr.LogMemberHelpfulVote(MemberId, ContentId, Constants.UserActivity_Values.FoundHelpful_False, Constants.UserActivity_Types.FoundHelpfulVote);
                //    Response.Redirect(Request.RawUrl);
                //}
            }
            else
            {
                //this.ProfileRedirect(Constants.UserPermission.CommunityUser);
            }

            //var like = new LikeModel();
            //if (!string.IsNullOrEmpty(username))
            //{
            //    like = CommunityHelper.GetLike(this.CurrentMember.ScreenName.Trim(), contentId, contentTypeId);
            //}
            //using (var webClient = new WebClient())
            //{
            //    try
            //    {
            //        // replace the "admin" and "Admin's API key" with your valid user and apikey!
            //        var adminKey = String.Format("{0}:{1}", Settings.GetSetting(Constants.Settings.TelligentAdminApiKey), "admin");
            //        var adminKeyBase64 = Convert.ToBase64String(Encoding.UTF8.GetBytes(adminKey));

            //        webClient.Headers.Add("Rest-User-Token", adminKeyBase64);
            //        webClient.Headers.Add("Rest-Method", "DELETE");

            //        var requestUrl = String.Format("{0}api.ashx/v2/likes.xml", Settings.GetSetting(Constants.Settings.TelligentConfig));

            //        var values = new NameValueCollection();
            //        values.Add("ContentUrl", like.ContentUrl);

            //        var xml = Encoding.UTF8.GetString(webClient.UploadValues(requestUrl, values));

            //        Console.WriteLine(xml);
            //    }
            //    catch { } //TODO: Add logging
            //}
        }
        protected void btnShowItems_Click(object sender, EventArgs e)
        {
            ActivityLog log = new ActivityLog();          
            List<Guid?> stuff = log.MostPopularItems(Guid.Parse("00000000-0000-0000-0000-000000000000"));

            foreach (Guid g in stuff)
            {
                Response.Write("<h1>" + g.ToString() + "</h1>" + Environment.NewLine);
            }

        } 
        protected void Page_Load(object sender, EventArgs e)
        {
            ActivityLog throwawaylog = new ActivityLog();
            //ContentId, ActivityValue
            lblActivityCount.Text = throwawaylog.GetActivityCountByValue(new Guid("ECEFA524-93F5-4CE3-817B-A6DBBDA7640F"),  
                                                                          Constants.UserActivity_Values.Favorited).ToString();

            //i read this page. now record it.
           // Guid MemberId = new Guid();
           // Guid ContentId = new Guid();
            /*
            //Create an instance of the Membership Manager
            MembershipManager mgr = new MembershipManager();
            //log that this member has skipped a blog:
            mgr.LogMemberActivity(MemberId, ContentId,
                Constants.UserActivity_Values.Skipped_Blog,
                Constants.UserActivity_Types.ContentSkipped);

            //log that this member has skipped a blog post:
            mgr.LogMemberActivity(MemberId, ContentId,
                Constants.UserActivity_Values.Skipped_BlogPost ,
                Constants.UserActivity_Types.ContentSkipped);

            //log that this member has skipped a :
            mgr.LogMemberActivity(MemberId, ContentId,
                Constants.UserActivity_Values.Skipped_Group ,
                Constants.UserActivity_Types.ContentSkipped);

            //log that this member has viewed this page 
            //bg: note: we are going to need views for some things and consider how this will behave when we have hundreds of millions of rows
            mgr.LogMemberActivity(MemberId, ContentId,
                Constants.UserActivity_Values.ItemViewed,
                Constants.UserActivity_Types.ContentRelated);


            mgr.LogMemberActivity(new Guid(), new Guid(), 
                                Constants.UserActivity_Values.ItemViewed , 
                                Constants.UserActivity_Types.Type_Blog);

            mgr.LogMemberActivity(new Guid(), new Guid(), 
                        Constants.UserActivity_Values.SharedWithTwitter, 
                        Constants.UserActivity_Types.Type_BlogPost);
           
            
   
            */
            /*
            mgr.LogMemberHelpfulVote(MemberIdValue, 
                ContentIdValue, 
                Constants.UserActivity_Values.FoundHelpful_True, 
                Constants.UserActivity_Types.FoundHelpfulVote);
            */

            //     MembershipManager mgr = new MembershipManager();
      
            ////to say something was helpful
            //mgr.LogMemberHelpfulVote(MemberId, ContentId, Constants.UserActivity_Values.FoundHelpful_True, Constants.UserActivity_Types.FoundHelpfulVote);
            //// to say something was not helpful
            //mgr.LogMemberHelpfulVote(MemberId, ContentId, Constants.UserActivity_Values.FoundHelpful_False , Constants.UserActivity_Types.FoundHelpfulVote);

            ////to get IF a content item was helpful to this user
            //ActivityLog log = new ActivityLog();
            //bool washelpful = log.FoundItemHelpful(ContentId, MemberId);
            ////to get if the content was NOT helpful
            //bool wasNOThelpful = log.FoundItemNotHelpful(ContentId, MemberId);




            ActivityLog log = new ActivityLog(new Guid("810EBB87-14E1-4DAF-8EAE-F69E1754C640"), Constants.UserActivity_Values.Favorited);

            foreach (ActivityItem item in log.Activities)
            {
                Response.Write("ContentId: " + item.ContentId  + Environment.NewLine);
                Response.Write("ActivityValue: " + item.ActivityValue + Environment.NewLine + "------------------" + Environment.NewLine);
            }

            string targetUrl = "http://www.somethinghostedonconvio.com/myarticle.php";
            txtActivityValue.Text  = targetUrl  ;
            txtActivityType.Text = UnderstoodDotOrg.Common.Constants.UserActivity_Types.Advocacy_Page.ToString();

            /*
            Quiz quiz = new Quiz();
            quiz.QuizID = new Guid();

            QuizItem answer = new QuizItem();

            answer.QuestionId = Guid.NewGuid();
            answer.AnswerValue = "I am the answer.";
            quiz.MemberAnswers.Add(answer);

            quiz.MemberAnswers.Add(new QuizItem(Guid.NewGuid(), "I am also an answer"));
            quiz.MemberAnswers.Add(new QuizItem(Guid.NewGuid(), "I am a third answer"));

            this.CurrentMember.CompletedQuizes.Add(quiz);
            */
             //member contains data. member manager will save data.

            //           this.CurrentMember.AgreedToSignUpTerms;


            /*

            Checklist cl = new Checklist();
            cl.MemberId = CurrentMember.MemberId ;
            ChecklistItem clItem  = new ChecklistItem();
            
            clItem.QuestionId = Guid.NewGuid();
            clItem.Checked = true;

            cl.MemberAnswers.Add(clItem);
            mgr = new MembershipManager();
            mgr.ChecklistResults_SaveToDb(cl.MemberId, cl);
            */
            
        }
        public static List<FavoritesModel> GetFavorites(Guid username)
        {
            List<FavoritesModel> favoritesList = new List<FavoritesModel>();

            ActivityLog log = new ActivityLog(username, Constants.UserActivity_Values.Favorited);

            foreach (ActivityItem ai in log.Activities)
            {
                Sitecore.Data.Items.Item item = Sitecore.Context.Database.GetItem(ai.ContentId);
                if (item != null)
                {
                    ContentPageItem contentPage = item;
                    favoritesList.Add(new FavoritesModel
                    {
                        Title = contentPage.PageTitle,
                        Url = item.GetUrl(),
                        ContentId = ai.ContentId,
                        ReplyCount = GetTotalComments(item).ToString(),
                        RecentCommentDate = GetRecentCommentDate(item),
                        Type = GetContentType(item),
                        Date = ai.DateModified
                    });
                }
            }

            return favoritesList;
        }