Ejemplo n.º 1
0
        public ActionResult Edit(string spaceKey, long?threadId, long?ownerId)
        {
            BlogThreadEditModel model      = null;
            BlogThread          blogThread = null;

            //日志用户分类下拉列表
            IEnumerable <Category> ownerCategories = null;

            //写日志
            if (!threadId.HasValue)
            {
                string errorMessage = string.Empty;
                if (!authorizer.BlogThread_Create(spaceKey, out errorMessage))
                {
                    return(Redirect(SiteUrls.Instance().SystemMessage(TempData, new SystemMessageViewModel
                    {
                        Title = "没有权限",
                        Body = errorMessage,
                        StatusMessageType = StatusMessageType.Error
                    })));
                }

                model = new BlogThreadEditModel()
                {
                    PrivacyStatus = PrivacyStatus.Public
                };
                if (ownerId.HasValue)
                {
                    model.OwnerId = ownerId;
                }

                //获取所有者分类
                if (ownerId.HasValue)
                {
                    ownerCategories = categoryService.GetOwnerCategories(ownerId.Value, TenantTypeIds.Instance().BlogThread());
                }
                else
                {
                    ownerCategories = categoryService.GetOwnerCategories(UserContext.CurrentUser.UserId, TenantTypeIds.Instance().BlogThread());
                }

                pageResourceManager.InsertTitlePart("写日志");
            }

            //编辑日志
            else
            {
                blogThread = blogService.Get(threadId.Value);
                if (blogThread == null)
                {
                    return(HttpNotFound());
                }

                if (!authorizer.BlogThread_Edit(blogThread))
                {
                    return(Redirect(SiteUrls.Instance().SystemMessage(TempData, new SystemMessageViewModel
                    {
                        Title = "没有权限",
                        Body = "没有权限编辑" + blogThread.Subject + "!",
                        StatusMessageType = StatusMessageType.Error
                    })));
                }

                Dictionary <int, IEnumerable <ContentPrivacySpecifyObject> > privacySpecifyObjects = contentPrivacyService.GetPrivacySpecifyObjects(TenantTypeIds.Instance().BlogThread(), blogThread.ThreadId);
                if (privacySpecifyObjects.ContainsKey(SpecifyObjectTypeIds.Instance().User()))
                {
                    IEnumerable <ContentPrivacySpecifyObject> userPrivacySpecifyObjects = privacySpecifyObjects[SpecifyObjectTypeIds.Instance().User()];
                    ViewData["userPrivacySpecifyObjects"] = string.Join(",", userPrivacySpecifyObjects.Select(n => n.SpecifyObjectId));
                }
                if (privacySpecifyObjects.ContainsKey(SpecifyObjectTypeIds.Instance().UserGroup()))
                {
                    IEnumerable <ContentPrivacySpecifyObject> userGroupPrivacySpecifyObjects = privacySpecifyObjects[SpecifyObjectTypeIds.Instance().UserGroup()];
                    ViewData["userGroupPrivacySpecifyObjects"] = string.Join(",", userGroupPrivacySpecifyObjects.Select(n => n.SpecifyObjectId));
                }

                model = blogThread.AsEditModel();

                //获取所有者分类
                ownerCategories = categoryService.GetOwnerCategories(blogThread.OwnerId, TenantTypeIds.Instance().BlogThread());

                IEnumerable <Category>      selectedOwnerCategories = blogThread.OwnerCategories;
                Dictionary <long, Category> ownerCategoryDic        = new Dictionary <long, Category>();
                if (selectedOwnerCategories != null && selectedOwnerCategories.Count() > 0)
                {
                    ownerCategoryDic = selectedOwnerCategories.ToDictionary(n => n.CategoryId, n => n);
                }
                ViewData["ownerCategoryDic"] = ownerCategoryDic;

                pageResourceManager.InsertTitlePart("编辑日志");
            }

            ViewData["ownerCategories"] = ownerCategories;

            //日志站点分类下拉列表(投稿到)
            if (blogSettings.AllowSetSiteCategory)
            {
                IEnumerable <Category> siteCategories = categoryService.GetOwnerCategories(0, TenantTypeIds.Instance().BlogThread());
                ViewData["siteCategories"] = new SelectList(siteCategories, "CategoryId", "CategoryName", blogThread == null ? null : blogThread.SiteCategoryId);
            }

            return(View(model));
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 撰写日志/转载日志
        /// 空间主人撰写空间用户的日志
        /// </summary>
        public static bool BlogThread_Create(this Authorizer authorizer, string spaceKey)
        {
            string errorMessage = string.Empty;

            return(authorizer.BlogThread_Create(spaceKey, out errorMessage));
        }