public void Insert(int ModuleId, bool IsPostDateVisible, int ItemsPerPage, bool RequireAuthentication, bool AllowComments, bool ShowTagFilter, bool ShowImageIfBlank, string Template, bool PageVisibleInNavigation)
        {
            MasterDetailSetting item = new MasterDetailSetting();

            item.ModuleId = ModuleId;

            item.IsPostDateVisible = IsPostDateVisible;

            item.ItemsPerPage = ItemsPerPage;

            item.RequireAuthentication = RequireAuthentication;

            item.AllowComments = AllowComments;

            item.ShowTagFilter = ShowTagFilter;

            item.ShowImageIfBlank = ShowImageIfBlank;

            item.Template = Template;

            item.PageVisibleInNavigation = PageVisibleInNavigation;


            item.Save(UserName);
        }
        private void LoadSettings()
        {
            MasterDetailSetting settings = MasterDetailSetting.FetchByID(this.ModuleId);

            IsPostDateVisible.Checked       = settings.IsPostDateVisible;
            txtItemsPerPage.Text            = settings.ItemsPerPage.ToString();
            cbRequireAuthentication.Checked = settings.RequireAuthentication;
            cbAllowComments.Checked         = settings.AllowComments;
            cbTagFilter.Checked             = settings.ShowTagFilter;
            cbShowImageIfBlank.Checked      = settings.ShowImageIfBlank;

            // Load list of templates
            dlTemplateList.DataSource = BayshoreSolutions.WebModules.WebDirectories.GetTemplates();
            dlTemplateList.DataBind();
            if (string.IsNullOrEmpty(settings.Template))
            {
                var _instanceId = int.Parse(Request.QueryString["InstanceId"]);
                var _page       = Webpage.GetWebpage(_instanceId);

                dlTemplateList.SelectedValue = _page.TemplateGroup + " - " + _page.Template;
            }
            else
            {
                dlTemplateList.SelectedValue = settings.Template;
            }

            ModuleTemplate = dlTemplateList.SelectedValue;
        }
        override protected void EnsureModule()
        {
            MasterDetailSetting module = MasterDetailSetting.FetchByID(this.ModuleId);

            if (null == module)
            {
                module          = new MasterDetailSetting();
                module.ModuleId = this.ModuleId;
                module.Save();
            }
        }
        private void LoadData()
        {
            _itemList = MasterDetailSetting.FetchByID(this.ModuleId);

            string tagFilter = ddlFilter.SelectedValue;

            if (!string.IsNullOrEmpty(tagFilter) && tagFilter == "All")
            {
                tagFilter = null;
            }
            PagedDataSource pgitems = new PagedDataSource();

            pgitems.AllowPaging = true;
            pgitems.DataSource  = MasterDetailList.GetMasterDetailChildrenFiltered(this.ModuleId, true, true, tagFilter, true);
            //			pgitems.DataSource = SPs.MasterDetailGetRecentItems(this.Page.ID.ToString(), 10).GetDataSet();
            pgitems.PageSize         = _itemList.ItemsPerPage;
            pgitems.CurrentPageIndex = PageNumber;

            if (pgitems.PageCount > 1)
            {
                PagerRepeater.Visible = true;
                ArrayList pages = new ArrayList();
                for (int i = 0; i < pgitems.PageCount; i++)
                {
                    pages.Add((i + 1).ToString());
                }
                PagerRepeater.DataSource = pages;
                PagerRepeater.DataBind();
            }
            else
            {
                PagerRepeater.Visible = false;
            }

            // Clear taglist
            TagList = new ArrayList();

            SummaryListRepeater.DataSource = pgitems;
            SummaryListRepeater.DataBind();

            if (_itemList.ShowTagFilter && (ddlFilter.Items.Count == 0))
            {
                lblFilter.Visible = true;
                ddlFilter.Visible = true;

                TagList.Sort();
                TagList.Insert(0, "All");
                ddlFilter.DataSource = TagList;
                ddlFilter.DataBind();
            }
        }
        protected void MasterDetail_List_SaveButton_Click(object sender, EventArgs e)
        {
            MasterDetailSetting settings = MasterDetailSetting.FetchByID(this.ModuleId);

            settings.IsPostDateVisible     = IsPostDateVisible.Checked;
            settings.ItemsPerPage          = int.Parse(txtItemsPerPage.Text);
            settings.RequireAuthentication = cbRequireAuthentication.Checked;
            settings.AllowComments         = cbAllowComments.Checked;
            settings.ShowTagFilter         = cbTagFilter.Checked;
            settings.ShowImageIfBlank      = cbShowImageIfBlank.Checked;
            settings.Template = ModuleTemplate = dlTemplateList.SelectedValue;
            settings.Save();
            Msg.ShowSuccess("Saved settings.");
        }
        //finds the first content list that "contains" this item, if any.
        public MasterDetailSetting GetContentList()
        {
            WebModuleInfo       module     = WebModule.GetModule(this.ModuleId);
            WebpageInfo         parentPage = module.Webpage.Parent;
            MasterDetailSetting itemList   = null;

            foreach (WebModuleInfo m in parentPage.Modules)
            {
                if (m.WebModuleType == MasterDetailList.ModuleType)
                {
                    itemList = MasterDetailSetting.FetchByID(m.Id);
                    break;
                }
            }

            return(itemList);
        }
        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 + ":&nbsp;&nbsp;";
                    }

                    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("\"", "&quot;") + "\", '"
                                           + 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 ModuleId)
 {
     return(MasterDetailSetting.Delete(ModuleId) == 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();
            }
        }