Ejemplo n.º 1
0
        private CommentViewModel GenerateComment(ForumMessages message)
        {
            if (includedMessages.Contains(message.Id))
            {
                return(null);
            }
            includedMessages.Add(message.Id);
            var comment = new CommentViewModel
            {
                User              = message.User,
                Id                = message.Id,
                Message           = message.Message,
                PublishedDateTime = message.PublishedDateTime,
                UserId            = message.User.Id,
                UserName          = message.User.UserName
            };

            comment.User.Comments = null;
            comment.User          = null;
            var answers = new List <CommentViewModel>();

            foreach (var ans in message.Answers)
            {
                if (includedMessages.Contains(ans.Id))
                {
                    continue;
                }
                answers.Add(GenerateComment(ans));
            }

            comment.Answers = answers;

            return(comment);
        }
        // ****************************************************************
        // InitializeControlTemplate
        //
        /// <summary>
        /// This control uses a user control for a template. This function
        /// initializes the control and attempts to call FindControl on the
        /// controls that it needs access to in order to render properly
        /// </summary>
        // ****************************************************************
        private void InitializeControlTemplate()
        {
            Button button;

            // Find and populate the drop down list with the available templates
            messageTemplates = (DropDownList)controlTemplate.FindControl("messageTemplateList");
            messageTemplates.DataTextField  = "Title";
            messageTemplates.DataValueField = "MessageID";
            messageTemplates.DataSource     = ForumMessages.GetMessageTemplateList();
            messageTemplates.DataBind();
            messageTemplates.AutoPostBack          = true;
            messageTemplates.SelectedIndexChanged += new System.EventHandler(MessageTemplate_Changed);

            // Set up the button used to update the email template
            button        = (Button)controlTemplate.FindControl("UpdateTemplate");
            button.Text   = " Update Template ";
            button.Click += new System.EventHandler(UpdateTemplate_Click);

            // Set up the preview option
            preview = (HyperLink)controlTemplate.FindControl("PreviewMessage");

            // Find the status control
            status         = (Label)controlTemplate.FindControl("Status");
            status.Visible = false;

            // Find the subject text box and the body textbox
            title = (TextBox)controlTemplate.FindControl("Title");
            body  = (TextBox)controlTemplate.FindControl("Body");

            DisplayEditMode();
        }
        // ****************************************************************
        // DisplayEditMode
        //
        /// <summary>
        /// Retrieves the values for the title and body from the database
        /// and dispalys them in textboxs for the user to edit
        /// </summary>
        // ****************************************************************
        private void DisplayEditMode()
        {
            // Set the preview to the correct message
            preview.NavigateUrl = Globals.UrlMessage + messageTemplates.SelectedItem.Value;

            // Now populate the subject/body with the appropriate values
            // read in the email template's subject/body
            ForumMessage message = ForumMessages.GetMessage(Convert.ToInt32(messageTemplates.SelectedItem.Value));

            // Set the values for subject/body
            title.Text = message.Title;
            body.Text  = message.Body;
        }
        // ****************************************************************
        // UpdateTemplate_Click
        //
        /// <summary>
        /// Logic to handle updating the message in the database when
        /// the user has made changes.
        /// </summary>
        // ****************************************************************
        private void UpdateTemplate_Click(Object sender, EventArgs e)
        {
            ForumMessage message = new ForumMessage();

            message.MessageID = Convert.ToInt32(messageTemplates.SelectedItem.Value);
            message.Title     = title.Text;
            message.Body      = body.Text;

            // update the email template
            ForumMessages.UpdateMessageTemplate(message);

            // Display that we've updated
            status.Visible = true;
            status.Text    = "Message template updated...";
        }
Ejemplo n.º 5
0
        public int AddComment(int productId, string userId, DateTime dateTime, string message, int?parentComment = null)
        {
            var msg = new ForumMessages
            {
                Message           = message,
                UserId            = userId,
                ProductId         = productId,
                PublishedDateTime = dateTime,
                ReplyToId         = parentComment
            };

            _forumMessage.Add(msg);
            _forumMessage.Commit();

            return(msg.Id);
        }
Ejemplo n.º 6
0
        // *********************************************************************
        //  Message
        //
        /// <summary>
        /// Constructor
        /// </summary>
        //
        // ********************************************************************/
        public Message() : base()
        {
            // Assign a default template name
            if (SkinFilename == null)
            {
                SkinFilename = skinFilename;
            }

            // Get the error message id
            if (null != Context)
            {
                // Get the message id
                if (null != Context.Request.QueryString["MessageId"])
                {
                    MessageID = Convert.ToInt32(Context.Request.QueryString["MessageId"]);
                }
                else if (null != Context.Request.Form["MessageId"])
                {
                    MessageID = Convert.ToInt32(Context.Request.Form["MessageId"]);
                }
            }

            message = ForumMessages.GetMessage(MessageID);
        }