示例#1
0
        public ExpandoObject Topic(TopicSaveModel model)
        {
            dynamic o = new ExpandoObject();

            var t = new Topic();

            t.Body              = model.Body;
            t.Title             = model.Title;
            t.MemberId          = Members.GetCurrentMemberId();
            t.Created           = DateTime.Now;
            t.ParentId          = model.Forum;
            t.UrlName           = url.FormatUrl(model.Title);
            t.Updated           = DateTime.Now;
            t.Version           = model.Version;
            t.Locked            = false;
            t.LatestComment     = 0;
            t.LatestReplyAuthor = 0;
            t.Replies           = 0;
            t.Score             = 0;
            t.Answer            = 0;
            t.LatestComment     = 0;
            t.IsSpam            = Members.GetCurrentMember().GetPropertyValue <bool>("blocked") || t.DetectSpam();
            TopicService.Save(t);

            if (t.IsSpam)
            {
                SpamChecker.SendSlackSpamReport(t.Body, t.Id, "topic", t.MemberId);
            }

            o.url = string.Format("{0}/{1}-{2}", library.NiceUrl(t.ParentId), t.Id, t.UrlName);

            return(o);
        }
示例#2
0
        public ExpandoObject Topic(int id, TopicSaveModel model)
        {
            dynamic o = new ExpandoObject();

            var t = TopicService.GetById(id);

            if (t == null)
            {
                throw new Exception("Topic not found");
            }

            if (t.MemberId != Members.GetCurrentMemberId() && Members.IsAdmin() == false)
            {
                throw new Exception("You cannot edit this topic");
            }

            t.Updated  = DateTime.Now;
            t.Body     = model.Body;
            t.Version  = model.Version;
            t.ParentId = model.Forum;
            t.Title    = model.Title;

            // If the chosen version is Umbraco Heartcore, overrule other categories
            if (model.Version == Constants.Forum.HeartcoreVersionNumber)
            {
                var heartCodeForumId = GetHeartCoreForumId();
                t.ParentId = heartCodeForumId;
            }

            TopicService.Save(t);

            o.url = string.Format("{0}/{1}-{2}", library.NiceUrl(t.ParentId), t.Id, t.UrlName);

            return(o);
        }
示例#3
0
        public ExpandoObject Topic(int id, TopicSaveModel model)
        {
            dynamic o = new ExpandoObject();

            var t = TopicService.GetById(id);

            if (t == null)
            {
                throw new Exception("Topic not found");
            }

            if (t.MemberId != Members.GetCurrentMemberId() && Members.IsAdmin() == false)
            {
                throw new Exception("You cannot edit this topic");
            }

            t.Updated  = DateTime.Now;
            t.Body     = model.Body;
            t.Version  = model.Version;
            t.ParentId = model.Forum;
            t.Title    = model.Title;
            TopicService.Save(t);

            o.url = string.Format("{0}/{1}-{2}", library.NiceUrl(t.ParentId), t.Id, t.UrlName);

            return(o);
        }
示例#4
0
        public void Post(TopicSaveModel model)
        {
            var t = new Topic();

            t.Body     = model.Body;
            t.MemberId = Members.GetCurrentMemberId();
            t.Created  = DateTime.Now;
            t.ParentId = model.Forum;
            TopicService.Save(t);
        }
示例#5
0
        public ExpandoObject Topic(TopicSaveModel model)
        {
            dynamic o = new ExpandoObject();

            var t = new Topic();

            t.Body              = model.Body;
            t.Title             = model.Title;
            t.MemberId          = Members.GetCurrentMemberId();
            t.Created           = DateTime.Now;
            t.ParentId          = model.Forum;
            t.UrlName           = url.FormatUrl(model.Title);
            t.Updated           = DateTime.Now;
            t.Version           = model.Version;
            t.Locked            = false;
            t.LatestComment     = 0;
            t.LatestReplyAuthor = 0;
            t.Replies           = 0;
            t.Score             = 0;
            t.Answer            = 0;
            t.LatestComment     = 0;
            t.IsSpam            = Members.GetCurrentMember().GetPropertyValue <bool>("blocked") || t.DetectSpam();

            // If the chosen version is Umbraco Heartcore, overrule other categories
            if (model.Version == Constants.Forum.HeartcoreVersionNumber)
            {
                var heartCodeForumId = GetForumIdFromName(Constants.Forum.UmbracoHeadlessName);
                t.ParentId = heartCodeForumId;
            }

            // If the chosen version is Umbraco Uno, overrule other categories
            if (model.Version == Constants.Forum.UnoVersionNumber)
            {
                var heartCodeForumId = GetForumIdFromName(Constants.Forum.UmbracoUnoName);
                t.ParentId = heartCodeForumId;
            }

            // If the chosen version is Umbraco 9, overrule other categories
            if (model.Version == 9)
            {
                var heartCodeForumId = GetForumIdFromName("Umbraco 9");
                t.ParentId = heartCodeForumId;
            }

            TopicService.Save(t);

            if (t.IsSpam)
            {
                SpamChecker.SendSlackSpamReport(t.Body, t.Id, "topic", t.MemberId);
            }

            o.url = string.Format("{0}/{1}-{2}", library.NiceUrl(t.ParentId), t.Id, t.UrlName);

            return(o);
        }
示例#6
0
        public void Put(int id, TopicSaveModel model)
        {
            var c = TopicService.GetById(id);

            if (c == null)
            {
                throw new Exception("Topic not found");
            }

            if (c.MemberId != Members.GetCurrentMemberId())
            {
                throw new Exception("You cannot edit this topic");
            }

            c.Body = model.Body;
            TopicService.Save(c);
        }