protected void btnCommentSubmit_Click(object sender, EventArgs e)
        {
            if (!Page.IsValid)
            {
                return;
            }

            // Check the spam-bot fields for data
            string s1 = Request.Form.Get("url");
            string s2 = Request.Form.Get("email");
            string s3 = Request.Form.Get("comment");
            object o4 = Session["AntiSpamVar"];

            if (!string.IsNullOrEmpty(Request.Form.Get("url")) ||
                !string.IsNullOrEmpty(Request.Form.Get("email")) ||
                !string.IsNullOrEmpty(Request.Form.Get("comment")) ||
                (Session["AntiSpamVar"] == null))
            {
                Response.End();
                return;
            }

            // Save record
            MasterDetailComment rec = new MasterDetailComment();

            rec.ModuleId    = CurrentModuleId;
            rec.Username    = tbCommentName.Text.Trim();
            rec.Email       = tbCommentEmail.Text.Trim();
            rec.IPAddress   = Request.ServerVariables["REMOTE_ADDR"];
            rec.CommentText = tbCommentText.Text.Trim();
            rec.CreatedBy   = Page.User.Identity.IsAuthenticated ? Page.User.Identity.Name : "Anonymous";
            rec.Save();

            Response.Redirect(this.Request.Url.ToString());
        }
 protected void btnDeleteAll_Click(object sender, EventArgs e)
 {
     foreach (RepeaterItem item in CommentsListRepeater.Items)
     {
         HiddenField hidCommentRecId = item.FindControl("hidCommentRecId") as HiddenField;
         if (hidCommentRecId != null)
         {
             MasterDetailComment.Delete(Convert.ToInt64(hidCommentRecId.Value));
         }
         BindData();
     }
 }
        public void Insert(int ModuleId, string Username, string Email, string IPAddress, string CommentText)
        {
            MasterDetailComment item = new MasterDetailComment();

            item.ModuleId = ModuleId;

            item.Username = Username;

            item.Email = Email;

            item.IPAddress = IPAddress;

            item.CommentText = CommentText;

            item.CreatedOn = DateTime.Now;

            item.CreatedBy = UserName;


            item.Save(UserName);
        }
        public void Update(long Id, int ModuleId, string Username, string Email, string IPAddress, string CommentText)
        {
            MasterDetailComment item = new MasterDetailComment();

            item.MarkOld();
            item.IsLoaded = true;

            item.Id = Id;

            item.ModuleId = ModuleId;

            item.Username = Username;

            item.Email = Email;

            item.IPAddress = IPAddress;

            item.CommentText = CommentText;

            item.Save(UserName);
        }
        protected void CommentsListRepeater_ItemCommand(object source, RepeaterCommandEventArgs e)
        {
            switch (e.CommandName)
            {
            case "Delete":
                int recId = Convert.ToInt32(e.CommandArgument);
                // Delete the comment record.  Cascase delete will remove flag records as well.
                MasterDetailComment.Delete(recId);
                BindData();
                break;

            case "Accept":
                int recId2 = Convert.ToInt32(e.CommandArgument);
                // Accept the comment, and clear all flag records.
                MasterDetailFlagComment.Delete(MasterDetailFlagComment.Columns.CommentId, recId2);
                BindData();
                break;

            default:
                break;
            }
        }
        public void InsertAndReturnIdentity(int ModuleId, string Username, string Email, string IPAddress, string CommentText, out object newId)
        {
            MasterDetailComment item = new MasterDetailComment();

            item.ModuleId = ModuleId;

            item.Username = Username;

            item.Email = Email;

            item.IPAddress = IPAddress;

            item.CommentText = CommentText;

            item.CreatedOn = DateTime.Now;

            item.CreatedBy = UserName;


            item.Save(UserName);

            newId = item.Id;
        }
        protected void MiniSummaryRepeater_ItemDataBound(object sender, RepeaterItemEventArgs e)
        {
            if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
            {
                Label lblCategory = e.Item.FindControl("lblCategory") as Label;
                if (lblCategory != null)
                {
                    int         pageId         = Convert.ToInt32(DataBinder.Eval(e.Item.DataItem, "PageId"));
                    WebpageInfo parentPageInfo = Webpage.GetWebpageByPageId(pageId);
                    if (parentPageInfo != null)
                    {
                        lblCategory.Text = parentPageInfo.Parent.Text + ":  ";
                    }

                    HyperLink hypTitle = e.Item.FindControl("hypTitle") as HyperLink;
                    if (hypTitle != null)
                    {
                        hypTitle.NavigateUrl = DataBinder.Eval(e.Item.DataItem, "Path").ToString();

                        string scriptStr = "autoEllipseText('" + hypTitle.ClientID + "', \""
                                           + (DataBinder.Eval(e.Item.DataItem, "NavigationText")).ToString().Replace("\"", """) + "\", '"
                                           + lblCategory.ClientID + "');";
                        Page.ClientScript.RegisterStartupScript(GetType(), "truncate" + e.Item.ItemIndex, scriptStr, true);
                    }
                }

                // TODO: Cache this info
                int moduleId = Convert.ToInt32(DataBinder.Eval(e.Item.DataItem, "ModuleId"));
                MasterDetailItem               item               = MasterDetailItem.GetSafeResource(moduleId);
                MasterDetailSetting            setting            = item.GetContentList();
                MasterDetailMiniSummarySetting miniSummarySetting = MasterDetailMiniSummarySetting.FetchByID(this.ModuleId);

                Label lblCommentCount = e.Item.FindControl("lblCommentCount") as Label;
                if (lblCommentCount != null)
                {
                    if ((setting != null) && (setting.AllowComments))
                    {
                        int numComments =
                            MasterDetailComment.Query().WHERE(MasterDetailComment.Columns.ModuleId, moduleId).GetCount(
                                MasterDetailComment.Columns.ModuleId);
                        if (numComments > 999)
                        {
                            numComments = 999;                    // max display size is 3 digits.
                        }
                        lblCommentCount.Text    = numComments.ToString();
                        lblCommentCount.ToolTip = numComments + " Reader Comments";
                    }
                    else
                    {
                        lblCommentCount.Visible = false;
                    }
                }

                Label lblTimestamp = e.Item.FindControl("lblTimestamp") as Label;
                if (lblTimestamp != null)
                {
                    if ((miniSummarySetting != null) && ((bool)miniSummarySetting.ShowElapsedTime))
                    {
                        DateTime postDate = Convert.ToDateTime(DataBinder.Eval(e.Item.DataItem, "PostDate"));
                        TimeSpan ts       = DateTime.Now.Subtract(postDate);
                        if (ts.Days > 0)
                        {
                            lblTimestamp.Text = ts.Days + "d ago";
                        }
                        else if (ts.Hours > 0)
                        {
                            lblTimestamp.Text = ts.Hours + "h ago";
                        }
                        else if (ts.Minutes > 0)
                        {
                            lblTimestamp.Text = ts.Minutes + "m ago";
                        }
                        else
                        {
                            lblTimestamp.Text = "< 1m ago";
                        }
                    }
                    else
                    {
                        lblTimestamp.Visible = false;
                    }
                }
            }
        }
 public bool Delete(object Id)
 {
     return(MasterDetailComment.Delete(Id) == 1);
 }
 public bool Destroy(object Id)
 {
     return(MasterDetailComment.Destroy(Id) == 1);
 }
        protected void Page_Load(object sender, EventArgs e)
        {
            HtmlLink cssLink = new HtmlLink();

            cssLink.Href = "~/WebModules/MasterDetail/public/css/MasterDetail.css";
            cssLink.Attributes["rel"]  = "stylesheet";
            cssLink.Attributes["type"] = "text/css";
            this.Page.Header.Controls.AddAt(1, cssLink);

            // AntiSpam session var
            Session.Add("AntiSpamVar", "0");

            if (!IsPostBack)
            {
                WebpageInfo         page     = this.WebModuleInfo.Webpage;
                MasterDetailItem    item     = MasterDetailItem.GetSafeResource(this.ModuleId);
                MasterDetailSetting itemList = item.GetContentList();

                CurrentModuleId = item.ModuleId;

                if (itemList != null)
                {
                    lblPostDate.Visible   = itemList.IsPostDateVisible;
                    CommentsPanel.Visible = itemList.AllowComments;

                    if (itemList.AllowComments)
                    {
                        Query q = MasterDetailComment.Query().WHERE(MasterDetailComment.Columns.ModuleId, CurrentModuleId);
                        litCommentsLink.Text = "&nbsp;&nbsp;|&nbsp;&nbsp;<a href='#Comments'>" + q.GetCount(MasterDetailComment.Columns.Id) + " Comment(s)</a>";
                    }
                    if (Page.User.Identity.IsAuthenticated || !itemList.RequireAuthentication)
                    {
                        submitCommentsDiv.Visible = true;
                        lblLoginMsg.Visible       = false;
                    }
                    else
                    {
                        submitCommentsDiv.Visible = false;
                        lblLoginMsg.Visible       = true;
                    }
                }

                if (lblPostDate.Visible)
                {
                    if (page.PostDate.HasValue)
                    {
                        lblPostDate.Text = page.PostDate.Value.ToLongDateString();
                    }
                }

                if (string.IsNullOrEmpty(item.ImagePath))
                {
                    img.Visible = false;
                }
                else
                {
                    img.ImageUrl = ResolveUrl(item.ImagePath);
                }

                litTitle.Text       = page.Text;
                litBody.Text        = item.LongDescription;
                hypBack.NavigateUrl = this.WebModuleInfo.Webpage.Parent.Path;

                CommentsListRepeater.DataSource = new MasterDetailCommentCollection()
                                                  .Where(MasterDetailComment.Columns.ModuleId, CurrentModuleId)
                                                  .OrderByDesc(MasterDetailComment.Columns.CreatedOn)
                                                  .Load();
                CommentsListRepeater.DataBind();
            }
        }