示例#1
0
        public AjaxResponse SaveThread(int id, int categoryID, string name, string description)
        {
            AjaxResponse resp = new AjaxResponse();

            resp.rs2 = categoryID.ToString();

            if (String.IsNullOrEmpty(name) || String.IsNullOrEmpty(name.Trim()))
            {
                resp.rs1 = "0";
                resp.rs3 = "<div>" + Resources.ForumResource.ErrorEmptyName + "</div>";
                return(resp);
            }

            try
            {
                var thread = ForumDataProvider.GetThreadByID(TenantProvider.CurrentTenantID, id);

                if (thread == null || !ForumManager.Instance.ValidateAccessSecurityAction(ForumAction.GetAccessForumEditor, null))
                {
                    resp.rs1 = "0";
                    resp.rs3 = "<div>" + Resources.ForumResource.ErrorAccessDenied + "</div>";
                    return(resp);
                }

                thread.Title       = name.Trim();
                thread.Description = description ?? "";
                thread.CategoryID  = categoryID;

                ForumDataProvider.UpdateThread(TenantProvider.CurrentTenantID, thread.ID, thread.CategoryID,
                                               thread.Title, thread.Description, thread.SortOrder);

                var threads  = new List <Thread>();
                var category = ForumDataProvider.GetCategoryByID(TenantProvider.CurrentTenantID, thread.CategoryID, out threads);

                resp.rs1 = "1";
                resp.rs3 = ForumEditor.RenderForumCategory(category, threads);


                ForumActivityPublisher.EditThread(thread);
            }
            catch
            {
                resp.rs1 = "0";
                resp.rs3 = "<div>" + Resources.ForumResource.ErrorAccessDenied + "</div>";
            }
            return(resp);
        }
        public string UpdateThreadSortOrder(string sortOrders)
        {
            try
            {
                if (!ForumManager.Instance.ValidateAccessSecurityAction(ASC.Forum.ForumAction.GetAccessForumEditor, null))
                {
                    throw new Exception(Resources.ForumResource.ErrorAccessDenied);
                }

                List <ThreadCategory> categories;
                List <Thread>         threads;
                ForumDataProvider.GetThreadCategories(TenantProvider.CurrentTenantID, out categories, out threads);

                foreach (var categoryItem in sortOrders.Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries))
                {
                    var cid       = Convert.ToInt32(categoryItem.Split('@')[0]);
                    var threadStr = categoryItem.Split('@')[1];

                    var category = categories.Find(c => c.ID == cid);
                    if (category != null)
                    {
                        foreach (var thrItem in threadStr.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries))
                        {
                            int tid    = Convert.ToInt32(thrItem.Split(':')[0]);
                            int order  = Convert.ToInt32(thrItem.Split(':')[1]);
                            var thread = threads.Find(t => t.ID == tid);
                            if (thread != null)
                            {
                                thread.CategoryID = category.ID;
                                thread.SortOrder  = order;
                                ForumDataProvider.UpdateThread(TenantProvider.CurrentTenantID, thread.ID,
                                                               thread.CategoryID, thread.Title, thread.Description, thread.SortOrder);
                            }
                        }
                    }
                }

                return("ok");
            }
            catch (Exception e)
            {
                return(e.Message);
            }
        }