예제 #1
0
        /// <summary>
        /// Gets the topic elements from the current reader.
        /// </summary>
        /// <param name="reader"></param>
        /// <returns></returns>
        static public TopicElement GetTopicFromReader(IDnaDataReader reader)
        {
            var topicEdit = new TopicElement();
            topicEdit.TopicId = reader.GetInt32NullAsZero("topicid");
            topicEdit.H2G2Id = reader.GetInt32NullAsZero("h2g2ID");
            topicEdit.SiteId = reader.GetInt32NullAsZero("SiteID");
            topicEdit.TopicStatus = (TopicStatus)reader.GetInt32NullAsZero("TopicStatus");
            topicEdit.Title = reader.GetStringNullAsEmpty("TITLE");
            topicEdit.ForumId = reader.GetInt32NullAsZero("ForumID");
            topicEdit.Description = reader.GetStringNullAsEmpty("description");
            topicEdit.Position = reader.GetInt32NullAsZero("position");
            topicEdit.TopicLinkId = reader.GetInt32NullAsZero("topiclinkid");
            topicEdit.Createdby = new TopicCreatedDate
              {
                  CreatedDate = new DateElement(reader.GetDateTime("createddate")),
                  Username = reader.GetStringNullAsEmpty("CreatedByUserName"),
                  Userid = reader.GetInt32NullAsZero("CreatedByUserID")
              };

            topicEdit.Updatedby = new TopicLastUpdated()
            {
                LastUpdated = new DateElement(reader.GetDateTime("LastUpdated")),
                Username = reader.GetStringNullAsEmpty("UpdatedByUserName"),
                Userid = reader.GetInt32NullAsZero("UpdatedByUserID")
            };
            topicEdit.Style = reader.GetInt32NullAsZero("style");
            topicEdit.ForumPostCount = reader.GetInt32NullAsZero("forumpostcount");
            topicEdit.FrontPageElement.Elementid = reader.GetInt32NullAsZero("FP_ElementID");
            topicEdit.FrontPageElement.Position = reader.GetInt32NullAsZero("FP_Position");
            topicEdit.FrontPageElement.Title = reader.GetStringNullAsEmpty("FP_Title");
            topicEdit.FrontPageElement.TemplateElement = reader.GetInt32NullAsZero("FP_Template");
            topicEdit.FrontPageElement.Text = reader.GetStringNullAsEmpty("FP_Text");
            topicEdit.FrontPageElement.ImageName = reader.GetStringNullAsEmpty("FP_ImageName");
            topicEdit.FrontPageElement.ImageAltText = reader.GetStringNullAsEmpty("FP_ImageAltText");
            topicEdit.FrontPageElement.ForumPostCount = reader.GetInt32NullAsZero("forumpostcount");
            topicEdit.FrontPageElement.TopicId = reader.GetInt32NullAsZero("topicid");
            
            topicEdit.Fastmod = reader.GetInt32NullAsZero("fastmod");
            topicEdit.Editkey = reader.GetGuid("editkey");
            topicEdit.FrontPageElement.Editkey = reader.GetGuid("FP_EditKey");

            return topicEdit;
        }
예제 #2
0
        /// <summary>
        /// 
        /// </summary>
        /// <returns></returns>
        private BaseResult UpdateTopic()
        {
            TopicElement element;
            var topicId = InputContext.GetParamIntOrZero("topicid","topicid");
            if (topicId == 0)
            {
                element = new TopicElement{SiteId = InputContext.CurrentSite.SiteID};
            }
            else
            {
                element = _topicPage.TopicElementList.GetTopicElementById(topicId);
                if (element == null)
                {
                    return new Error("InvalidTopicId", "The topic id passed was invalid.");
                }
            }

            if (!String.IsNullOrEmpty(InputContext.GetParamStringOrEmpty("topiceditkey", "topiceditkey")))
            {
                element.Editkey = new Guid(InputContext.GetParamStringOrEmpty("topiceditkey", "topiceditkey"));
            }

            // Check to see if we're creating a new topic element for an existing topic, or have been given bad data
            if (!String.IsNullOrEmpty(InputContext.GetParamStringOrEmpty("fptopiceditkey", "fptopiceditkey")))
            {
                element.FrontPageElement.Editkey = new Guid(InputContext.GetParamStringOrEmpty("fptopiceditkey", "fptopiceditkey"));
            }

            element.FrontPageElement.Title = HtmlUtils.RemoveAllHtmlTags(InputContext.GetParamStringOrEmpty("fp_title", "fp_title"));
            if (element.FrontPageElement.Title.Length == 0)
            {
                return new Error("TopicElementTitleMissing", "No topic element title given.");
            }

            element.FrontPageElement.Text = ExtractHtmlInput("fp_text");

            if (InputContext.GetParamStringOrEmpty("fp_templatetype", "fp_templatetype") == string.Empty)
            {
                element.FrontPageElement.ImageName = InputContext.GetParamStringOrEmpty("fp_imagename", "fp_imagename");
                if (element.FrontPageElement.ImageName.Length == 0)
                {
                    return new Error("ImageNameMissing", "No image name given.");
                }
                element.FrontPageElement.ImageAltText = InputContext.GetParamStringOrEmpty("fp_imagealttext", "fp_imagealttext");
                if (element.FrontPageElement.ImageAltText.Length == 0)
                {
                    return new Error("AltTextMissing", "No alt text given.");
                }
                element.FrontPageElement.Template = FrontPageTemplate.ImageAboveText;
            }
            else
            {
                element.FrontPageElement.ImageName = "";
                element.FrontPageElement.ImageAltText = "";
                element.FrontPageElement.Template = FrontPageTemplate.TextOnly;
            }
            element.Title = HtmlUtils.RemoveAllHtmlTags(InputContext.GetParamStringOrEmpty("topictitle","topictitle"));
            if (element.Title.Length == 0)
            {
                return new Error("TopicTitleMissing", "No topic title given.");
            }
            element.Description = ExtractHtmlInput("topictext");


            if (topicId == 0)
            {
                var result = element.CreateTopic(AppContext.ReaderCreator, InputContext.CurrentSite.SiteID, InputContext.ViewingUser.UserID);
                if (result.IsError())
                {
                    return result;
                }
                _topicPage.TopicElementList.Topics.Add(element);
                return new Result("TopicCreateSuccessful", "New topic created");
            }
            else
            {
                // Check to see if we need to create the element first before updating.
                if (element.FrontPageElement.Elementid == 0)
                {
                    var result = element.FrontPageElement.CreateFrontPageElement(AppContext.ReaderCreator, InputContext.CurrentSite.SiteID, InputContext.ViewingUser.UserID);
                    if (result.IsError())
                    {
                        return result;
                    }
                }

                var result2 = element.UpdateTopic(AppContext.ReaderCreator, InputContext.ViewingUser.UserID);
                if (result2.IsError())
                {
                    return result2;
                }
                return new Result("TopicUpdateSuccessful", "Existing topic editted");
            }
            
        }