Beispiel #1
0
        /// <summary>
        /// 删除垃圾数据
        /// </summary>
        /// <param name="serviceKey">服务标识</param>
        public void DeleteTrashDatas()
        {
            IEnumerable <TenantType> tenantTypes = new TenantTypeService().Gets(MultiTenantServiceKeys.Instance().Tag());
            List <Sql> sqls = new List <Sql>();

            foreach (var tenantType in tenantTypes)
            {
                Type type = Type.GetType(tenantType.ClassType);
                if (type == null)
                {
                    continue;
                }

                var pd = PetaPoco.Database.PocoData.ForType(type);

                if (tenantType.TenantTypeId == TenantTypeIds.Instance().User() || tenantType.TenantTypeId == TenantTypeIds.Instance().Group())
                {
                    sqls.Add(Sql.Builder.Append("delete from tn_TagsInOwners")
                             .Where("not exists (select 1 from " + pd.TableInfo.TableName + " where OwnerId = " + pd.TableInfo.PrimaryKey + ") and TenantTypeId = @0"
                                    , tenantType.TenantTypeId));
                }
                else
                {
                    sqls.Add(Sql.Builder.Append("delete from tn_ItemsInTags")
                             .Where("not exists (select 1 from " + pd.TableInfo.TableName + " where ItemId = " + pd.TableInfo.PrimaryKey + ") and TenantTypeId = @0"
                                    , tenantType.TenantTypeId));
                }
            }

            CreateDAO().Execute(sqls);
        }
Beispiel #2
0
        /// <summary>
        /// 是否具有编辑附件的权限
        /// </summary>
        /// <returns></returns>
        public bool Attachment_Edit(Attachment attachment)
        {
            IUser currentUser = UserContext.CurrentUser;

            if (currentUser == null)
            {
                return(false);
            }
            TenantTypeService tenantTypeService = new TenantTypeService();
            TenantType        tenantType        = tenantTypeService.Get(attachment.TenantTypeId);

            if (tenantType == null)
            {
                return(false);
            }
            if (IsAdministrator(tenantType.ApplicationId))
            {
                return(true);
            }
            if (AuthorizationService.IsOwner(currentUser, attachment.UserId))
            {
                return(true);
            }
            if (AuthorizationService.IsTenantManager(currentUser, attachment.TenantTypeId, attachment.OwnerId))
            {
                return(true);
            }
            return(false);
        }
        /// <summary>
        /// 重建缩略图
        /// </summary>
        /// <returns></returns>
        public ActionResult RebuildingThumbnails()
        {
            IEnumerable <TenantAttachmentSettings> tenantAttachmentSettings = TenantAttachmentSettings.GetAll();

            ViewData["TenantAttachmentSettings"] = tenantAttachmentSettings;
            ViewData["TenantLogoSettings"]       = TenantLogoSettings.GetAll();

            IStoreProvider storeProvider = DIContainer.Resolve <IStoreProvider>();
            string         rootPath      = WebUtility.GetPhysicalFilePath("~");
            string         uploadsPath   = storeProvider.StoreRootPath;

            if (storeProvider.StoreRootPath.StartsWith(rootPath))
            {
                uploadsPath = uploadsPath.Replace(rootPath, "");
            }
            ViewData["uploadsPath"] = uploadsPath;
            Dictionary <string, string> ApplicationName = new Dictionary <string, string>();

            TenantTypeService        tenantTypeService = new TenantTypeService();
            IEnumerable <TenantType> tenantTypes       = tenantTypeService.Gets(null, null);

            foreach (var item in tenantTypes)
            {
                TenantType type = tenantTypeService.Get(item.TenantTypeId);
                ApplicationName[item.TenantTypeId] = type != null ? type.Name : item.Name;
            }

            ViewData["ApplicationName"] = ApplicationName;

            return(View());
        }
Beispiel #4
0
        /// <summary>
        /// 是否具有管理推荐内容的权限
        /// </summary>
        /// <returns></returns>
        public bool RecommendItem_Manage(string tenantTypeId)
        {
            IUser currentUser = UserContext.CurrentUser;

            if (currentUser == null)
            {
                return(false);
            }

            TenantTypeService tenantTypeService = new TenantTypeService();
            TenantType        tenantType        = tenantTypeService.Get(tenantTypeId);

            if (tenantType == null)
            {
                return(false);
            }

            if (IsAdministrator(tenantType.ApplicationId))
            {
                return(true);
            }

            if (currentUser.IsInRoles("ContentAdministrator"))
            {
                return(true);
            }

            return(false);
        }
Beispiel #5
0
        /// <summary>
        /// 是否具有删除分类的权限
        /// </summary>
        /// <returns></returns>
        public bool Category_Delete(Category category)
        {
            IUser currentUser = UserContext.CurrentUser;

            if (currentUser == null)
            {
                return(false);
            }
            TenantTypeService tenantTypeService = new TenantTypeService();
            TenantType        tenantType        = tenantTypeService.Get(category.TenantTypeId);

            if (tenantType == null)
            {
                return(false);
            }
            if (IsAdministrator(tenantType.ApplicationId))
            {
                return(true);
            }
            if (AuthorizationService.IsTenantManager(currentUser, category.TenantTypeId, category.OwnerId))
            {
                return(true);
            }
            return(false);
        }
Beispiel #6
0
        /// <summary>
        /// 是否具有编辑标签的权限
        /// </summary>
        /// <returns></returns>
        public bool Tag_Edit(Tag tag)
        {
            IUser currentUser = UserContext.CurrentUser;

            if (currentUser == null)
            {
                return(false);
            }
            TenantTypeService tenantTypeService = new TenantTypeService();
            TenantType        tenantType        = tenantTypeService.Get(tag.TenantTypeId);

            if (tenantType == null)
            {
                return(false);
            }
            if (IsAdministrator(tenantType.ApplicationId))
            {
                return(true);
            }
            if (AuthorizationService.IsTenantManager(currentUser, tag.TenantTypeId, tag.OwnerId))
            {
                return(true);
            }
            return(false);
        }
Beispiel #7
0
        /// <summary>
        /// 推荐积分处理
        /// </summary>
        /// <param name="sender">推荐实体</param>
        /// <param name="eventArgs">事件参数</param>
        void RecommendPointModule_After(RecommendItem sender, CommonEventArgs eventArgs)
        {
            if (eventArgs.EventOperationType != EventOperationType.Instance().Create())
            {
                return;
            }
            string            pointItemKey      = string.Empty;
            PointService      pointService      = new PointService();
            string            description       = string.Empty;
            TenantTypeService tenantTypeService = new TenantTypeService();

            var urlGetter = RecommendUrlGetterFactory.Get(sender.TenantTypeId);

            NoticeService noticeService = new NoticeService();
            Notice        notice        = Notice.New();

            notice.TypeId = NoticeTypeIds.Instance().Hint();

            //notice.TemplateName = "FollowUser";
            notice.UserId             = sender.UserId;
            notice.LeadingActorUserId = sender.ReferrerId;
            notice.LeadingActor       = sender.ReferrerName;
            notice.LeadingActorUrl    = SiteUrls.FullUrl(SiteUrls.Instance().SpaceHome(sender.ReferrerId));
            notice.RelativeObjectId   = sender.UserId;
            notice.RelativeObjectName = sender.ItemName;
            notice.RelativeObjectUrl  = sender.DetailUrl;

            if (sender.TenantTypeId == TenantTypeIds.Instance().User())
            {
                pointItemKey        = PointItemKeys.Instance().RecommendUser();
                description         = string.Format(ResourceAccessor.GetString("PointRecord_Pattern_RecommendUser"));
                notice.TemplateName = NoticeTemplateNames.Instance().ManagerRecommendedUser();
            }
            else
            {
                pointItemKey = PointItemKeys.Instance().RecommendContent();
                TenantType tenantType = tenantTypeService.Get(sender.TenantTypeId);
                if (tenantType == null)
                {
                    return;
                }
                description         = string.Format(ResourceAccessor.GetString("PointRecord_Pattern_RecommendContent"), tenantType.Name, sender.ItemName);
                notice.TemplateName = NoticeTemplateNames.Instance().ManagerRecommended();
            }

            noticeService.Create(notice);
            pointService.GenerateByRole(sender.UserId, pointItemKey, description);
        }
        public ActionResult ManageThreads(string spaceKey, ManageThreadEditModel model, int pageIndex = 1)
        {
            long       groupId = GroupIdToGroupKeyDictionary.GetGroupId(spaceKey);
            BarSection section = barSectionService.Get(groupId);

            if (!new Authorizer().BarSection_Manage(section))
            {
                return(Redirect(SiteUrls.Instance().SystemMessage(TempData, new SystemMessageViewModel
                {
                    Body = string.Format("您没有权限管理 {0} !", section == null ? "" : section.Name),
                    Title = "没有权限",
                    StatusMessageType = StatusMessageType.Error
                })));
            }
            var group = groupService.Get(spaceKey);

            pageResourceManager.InsertTitlePart(group.GroupName);

            pageResourceManager.InsertTitlePart("帖吧管理");

            List <SelectListItem> SelectListItem_TrueAndFlase = new List <SelectListItem> {
                new SelectListItem {
                    Text = "是", Value = true.ToString()
                }, new SelectListItem {
                    Text = "否", Value = false.ToString()
                }
            };

            ViewData["IsEssential"] = new SelectList(SelectListItem_TrueAndFlase, "Value", "Text", model.IsEssential);
            ViewData["IsSticky"]    = new SelectList(SelectListItem_TrueAndFlase, "Value", "Text", model.IsSticky);

            IEnumerable <Category> categories = categoryService.GetOwnerCategories(section.SectionId, TenantTypeIds.Instance().BarThread());

            ViewData["CategoryId"] = new SelectList(categories.Select(n => new { text = StringUtility.Trim(n.CategoryName, 20), value = n.CategoryId }), "value", "text", model.CategoryId);

            BarThreadQuery query = model.GetBarThreadQuery();

            query.SectionId        = section.SectionId;
            ViewData["BarThreads"] = barThreadService.Gets(TenantTypeIds.Instance().Group(), query, model.PageSize ?? 20, pageIndex);

            model.SectionId = section.SectionId;

            ViewData["TenantType"] = new TenantTypeService().Get(TenantTypeIds.Instance().Group());

            return(View(model));
        }
Beispiel #9
0
        /// <summary>
        /// 是否具有管理BarSection的权限
        /// </summary>
        /// <param name="barSection"></param>
        /// <returns></returns>
        public static bool BarSection_Manage(this Authorizer authorizer, BarSection barSection)
        {
            IUser currentUser = UserContext.CurrentUser;

            if (currentUser == null)
            {
                return(false);
            }

            if (barSection == null)
            {
                return(false);
            }

            if (barSection.AuditStatus == AuditStatus.Success)
            {
                //吧主
                if (barSection.UserId == currentUser.UserId)
                {
                    return(true);
                }

                //吧管理员
                if (authorizer.AuthorizationService.IsTenantManager(currentUser, barSection.TenantTypeId, barSection.SectionId))
                {
                    return(true);
                }
            }

            TenantType tenantType    = new TenantTypeService().Get(barSection.TenantTypeId);
            int        applicationId = BarConfig.Instance().ApplicationId;

            if (tenantType != null)
            {
                applicationId = tenantType.ApplicationId;
            }
            if (authorizer.IsAdministrator(applicationId))
            {
                return(true);
            }

            return(false);
        }
Beispiel #10
0
        /// <summary>
        /// 是否有权限查看评论
        /// </summary>
        /// <param name="comment"></param>
        /// <returns></returns>
        public bool Comment_Show(Comment comment)
        {
            if (!comment.IsPrivate)
            {
                return(true);
            }
            IUser currentUser = UserContext.CurrentUser;

            if (currentUser == null)
            {
                return(false);
            }

            if (comment.OwnerId == currentUser.UserId && comment.ParentId == 0)
            {
                return(true);
            }

            if (comment.ToUserId != 0 && comment.ToUserId == currentUser.UserId)
            {
                return(true);
            }
            if (comment.UserId == currentUser.UserId)
            {
                return(true);
            }
            TenantTypeService tenantTypeService = new TenantTypeService();
            TenantType        tenantType        = tenantTypeService.Get(comment.TenantTypeId);

            if (tenantType == null)
            {
                return(false);
            }
            if (IsAdministrator(tenantType.ApplicationId))
            {
                return(true);
            }
            if (AuthorizationService.IsTenantManager(currentUser, comment.TenantTypeId, comment.OwnerId))
            {
                return(true);
            }
            return(false);
        }
        public ActionResult _CreateBarThread(long ActivityId)
        {
            Activity activity = activityService.Get(ActivityId);

            if (activity == null)
            {
                return(Content(string.Empty));
            }
            BarThread thread = barThreadService.Get(activity.SourceId);

            if (thread == null)
            {
                return(Content(string.Empty));
            }
            PagingDataSet <BarPost> barPosts = barPostService.Gets(thread.ThreadId, false, SortBy_BarPost.DateCreated_Desc);


            ViewData["BarPosts"] = barPosts.Take(3);
            IEnumerable <Attachment> attachments = attachementService.GetsByAssociateId(thread.ThreadId);

            if (attachments != null && attachments.Count() > 0)
            {
                IEnumerable <Attachment> attachmentImages = attachments.Where(n => n.MediaType == MediaType.Image);
                if (attachmentImages != null && attachmentImages.Count() > 0)
                {
                    ViewData["Attachments"] = attachmentImages;
                }
            }
            ViewData["ActivityId"] = ActivityId;
            if (thread.BarSection.TenantTypeId != TenantTypeIds.Instance().Bar())
            {
                var    tenantType     = new TenantTypeService().Get(thread.BarSection.TenantTypeId);
                string tenantTypeName = string.Empty;
                if (tenantType != null)
                {
                    tenantTypeName = tenantType.Name;
                }
                ViewData["tenantTypeName"] = tenantTypeName;
            }
            return(View(thread));
        }
Beispiel #12
0
        /// <summary>
        /// 删除垃圾数据
        /// </summary>
        public void DeleteTrashDatas()
        {
            IEnumerable <TenantType> tenantTypes = new TenantTypeService().Gets(MultiTenantServiceKeys.Instance().Recommend());

            List <Sql> sqls = new List <Sql>();

            foreach (var tenantType in tenantTypes)
            {
                Type type = Type.GetType(tenantType.ClassType);
                if (type == null)
                {
                    continue;
                }
                var pd = TableInfo.FromPoco(type);
                sqls.Add(Sql.Builder.Append("delete from tn_RecommendItems")
                         .Where("not exists (select 1 from " + pd.TableName + " where ItemId = " + pd.PrimaryKey + ") and TenantTypeId = @0"
                                , tenantType.TenantTypeId));
            }

            CreateDAO().Execute(sqls);
        }
        public ActionResult _CreateBarPost(long ActivityId)
        {
            Activity activity = activityService.Get(ActivityId);

            if (activity == null)
            {
                return(Content(string.Empty));
            }
            BarPost post = barPostService.Get(activity.SourceId);

            if (post == null)
            {
                return(Content(string.Empty));
            }


            BarThread thread = barThreadService.Get(activity.ReferenceId);

            if (thread == null)
            {
                return(Content(string.Empty));
            }
            ViewData["BarThread"] = thread;


            ViewData["Attachments"] = thread.Attachments.Where(n => n.MediaType == MediaType.Image).FirstOrDefault();
            ViewData["ActivityId"]  = ActivityId;
            if (thread.BarSection.TenantTypeId != TenantTypeIds.Instance().Bar())
            {
                var    tenantType     = new TenantTypeService().Get(thread.BarSection.TenantTypeId);
                string tenantTypeName = string.Empty;
                if (tenantType != null)
                {
                    tenantTypeName = tenantType.Name;
                }
                ViewData["tenantTypeName"] = tenantTypeName;
            }
            return(View(post));
        }
Beispiel #14
0
        /// <summary>
        /// 删除垃圾数据
        /// </summary>
        public void DeleteTrashDatas()
        {
            IEnumerable <TenantType> tenantTypes = new TenantTypeService().Gets(MultiTenantServiceKeys.Instance().Comment());

            List <Sql> sqls = new List <Sql>();

            sqls.Add(Sql.Builder.Append("delete from tn_Comments where not exists (select 1 from tn_Users where UserId = tn_Comments.UserId)"));

            foreach (var tenantType in tenantTypes)
            {
                Type type = Type.GetType(tenantType.ClassType);
                if (type == null)
                {
                    continue;
                }
                var pd = PetaPoco.Database.PocoData.ForType(type);
                sqls.Add(Sql.Builder.Append("delete from tn_Comments")
                         .Where("not exists (select 1 from " + pd.TableInfo.TableName + " where CommentedObjectId = " + pd.TableInfo.PrimaryKey + ") and TenantTypeId = @0"
                                , tenantType.TenantTypeId));
            }

            CreateDAO().Execute(sqls);
        }
Beispiel #15
0
        //[DonutOutputCache(CacheProfile = "Frequently")]
        public ActionResult _CreateBarRating(long ActivityId)
        {
            Activity activity = activityService.Get(ActivityId);

            if (activity == null)
            {
                return(HttpNotFound());
            }
            BarRating rating = barRatingService.Get(activity.SourceId);

            if (rating == null)
            {
                return(HttpNotFound());
            }
            ViewData["BarRating"] = rating;
            BarThread thread = barThreadService.Get(activity.ReferenceId);

            if (thread == null)
            {
                return(HttpNotFound());
            }
            ViewData["ActivityId"] = ActivityId;
            //todo:bianchx,by zhengw:相同问题,做个记号

            ViewData["Attachments"] = thread.Attachments.Where(n => n.MediaType == MediaType.Image).FirstOrDefault();
            if (thread.BarSection.TenantTypeId != TenantTypeIds.Instance().Bar())
            {
                var    tenantType     = new TenantTypeService().Get(thread.BarSection.TenantTypeId);
                string tenantTypeName = string.Empty;
                if (tenantType != null)
                {
                    tenantTypeName = tenantType.Name;
                }
                ViewData["tenantTypeName"] = tenantTypeName;
            }
            return(View(thread));
        }
Beispiel #16
0
        /// <summary>
        /// 删除垃圾数据
        /// </summary>
        /// <param name="serviceKey">服务标识</param>
        public void DeleteTrashDatas(string serviceKey)
        {
            IEnumerable <TenantType> tenantTypes = new TenantTypeService().Gets(serviceKey);

            List <Sql> sqls = new List <Sql>();

            sqls.Add(Sql.Builder.Append("delete from tn_Favorites where not exists (select 1 from tn_Users where UserId = tn_Favorites.UserId)"));

            foreach (var tenantType in tenantTypes)
            {
                Type type = Type.GetType(tenantType.ClassType);
                if (type == null)
                {
                    continue;
                }

                var pd = TableInfo.FromPoco(type);
                sqls.Add(Sql.Builder.Append("delete from tn_Favorites")
                         .Where("not exists (select 1 from " + pd.TableName + " where ObjectId = " + pd.PrimaryKey + ") and TenantTypeId = @0"
                                , tenantType.TenantTypeId));
            }

            CreateDAO().Execute(sqls);
        }
Beispiel #17
0
        /// <summary>
        /// 资讯操作日志事件处理
        /// </summary>
        private void RecommendOperationLogEventModule_After(RecommendItem sender, CommonEventArgs eventArgs)
        {
            if (eventArgs.EventOperationType == EventOperationType.Instance().Create() ||
                eventArgs.EventOperationType == EventOperationType.Instance().Delete())
            {
                TenantTypeService tenantTypeService = new TenantTypeService();
                TenantType        tenantType        = tenantTypeService.Get(sender.TenantTypeId);
                if (tenantType == null)
                {
                    return;
                }

                OperationLogEntry entry = new OperationLogEntry(eventArgs.OperatorInfo);
                entry.ApplicationId       = tenantType.ApplicationId;
                entry.Source              = tenantType.Name;
                entry.OperationType       = eventArgs.EventOperationType;
                entry.OperationObjectName = sender.ItemName;
                entry.OperationObjectId   = sender.ItemId;
                entry.Description         = string.Format(ResourceAccessor.GetString("OperationLog_Pattern_" + eventArgs.EventOperationType), tenantType.Name + "推荐", entry.OperationObjectName);

                OperationLogService logService = Tunynet.DIContainer.Resolve <OperationLogService>();
                logService.Create(entry);
            }
        }
Beispiel #18
0
        /// <summary>
        /// 是否具有创建BarThread的权限
        /// </summary>
        /// <param name="authorizer"></param>
        /// <param name="sectionId">所属帖吧Id</param>
        /// <param name="errorMessage">无权信息提示</param>
        /// <returns></returns>
        public static bool BarThread_Create(this Authorizer authorizer, long sectionId, out string errorMessage)
        {
            errorMessage = string.Empty;
            IUser currentUser = UserContext.CurrentUser;

            if (currentUser == null)
            {
                errorMessage = "您需要先登录,才能发帖";
                return(false);
            }
            BarSectionService barSectionService = new BarSectionService();
            var barSection = barSectionService.Get(sectionId);

            if (barSection == null)
            {
                errorMessage = "贴吧不存在";
                return(false);
            }

            if (authorizer.BarSection_Manage(barSection))
            {
                return(true);
            }

            if (!authorizer.AuthorizationService.Check(currentUser, PermissionItemKeys.Instance().Bar_CreateThread()))
            {
                if (currentUser.IsModerated)
                {
                    errorMessage = Resources.Resource.Description_ModeratedUser_CreateBarThreadDenied;
                }
                return(false);
            }
            if (barSection.TenantTypeId == TenantTypeIds.Instance().Bar())
            {
                IBarSettingsManager barSettingsManager = DIContainer.Resolve <IBarSettingsManager>();
                BarSettings         barSetting         = barSettingsManager.Get();
                if (barSetting.OnlyFollowerCreateThread)
                {
                    SubscribeService subscribeService = new SubscribeService(TenantTypeIds.Instance().BarSection());
                    if (subscribeService.IsSubscribed(sectionId, currentUser.UserId))
                    {
                        return(true);
                    }
                    else
                    {
                        errorMessage = "您需要先关注此帖吧,才能发帖";
                        return(false);
                    }
                }
                else
                {
                    return(true);
                }
            }
            else
            {
                if (authorizer.AuthorizationService.IsTenantMember(currentUser, barSection.TenantTypeId, barSection.SectionId))
                {
                    return(true);
                }
                else
                {
                    TenantType tenantType = new TenantTypeService().Get(barSection.TenantTypeId);
                    errorMessage = string.Format("只有加入{0}才能发帖", tenantType.Name);
                    return(false);
                }
            }
        }
Beispiel #19
0
        // This method must be thread-safe since it is called by the thread-safe OnCacheAuthorization() method.
        protected virtual bool AuthorizeCore(AuthorizationContext filterContext)
        {
            if (CheckCookie)
            {
                HttpCookie adminCookie = filterContext.HttpContext.Request.Cookies["SpacebuilderAdminCookie"];
                if (adminCookie != null)
                {
                    bool isLoginMarked = false;
                    try
                    {
                        bool.TryParse(Utility.DecryptTokenForAdminCookie(adminCookie.Value), out isLoginMarked);
                    }
                    catch { }

                    if (!isLoginMarked)
                    {
                        return(false);
                    }
                }
                else
                {
                    return(false);
                }
            }
            IUser currentUser = UserContext.CurrentUser;

            if (currentUser == null)
            {
                return(false);
            }

            RoleService roleService = new RoleService();

            if (RequireSystemAdministrator)
            {
                if (roleService.IsUserInRoles(currentUser.UserId, RoleNames.Instance().SuperAdministrator()))
                {
                    return(true);
                }
                else
                {
                    return(false);
                }
            }
            else
            {
                if (roleService.IsUserInRoles(currentUser.UserId, RoleNames.Instance().SuperAdministrator(), RoleNames.Instance().ContentAdministrator()))
                {
                    return(true);
                }
            }

            if (checkApplication)
            {
                //是否为管理员
                ApplicationService applicationService = new ApplicationService();
                string             applicationKey     = GetAreaName(filterContext.RouteData);
                var application = applicationService.Get(applicationKey);
                var authorizer  = new Authorizer();
                if (application != null && authorizer.IsAdministrator(application.ApplicationId))
                {
                    return(true);
                }
                string tenantTypeId = filterContext.RequestContext.GetParameterFromRouteDataOrQueryString("tenantTypeId");
                if (!string.IsNullOrEmpty(tenantTypeId))
                {
                    TenantType tenantType = new TenantTypeService().Get(tenantTypeId);
                    if (tenantType != null)
                    {
                        if (authorizer.IsAdministrator(tenantType.ApplicationId))
                        {
                            return(true);
                        }
                    }
                }
            }
            else
            {
                return(currentUser.IsAllowEntryControlPannel());
            }
            return(false);
        }
Beispiel #20
0
        public ActionResult _RecommendItem(string tenantTypeId, long itemId = 0, string itemName = null, string recommendItemTypeId = null, bool showLink = false, long recommendId = 0, bool showInList = true, long userId = 0)
        {
            RecommendItem recommendItem = null;

            if (recommendId > 0)
            {
                recommendItem = recommendService.Get(recommendId);
                if (recommendItem == null)
                {
                    return(HttpNotFound());
                }
                tenantTypeId                  = recommendItem.TenantTypeId;
                itemId                        = recommendItem.ItemId;
                recommendItemTypeId           = recommendItem.TypeId;
                ViewData["RecommendTypeName"] = recommendItem.RecommendItemType.Name;
                ViewData["RecommendTypeId"]   = recommendItem.TypeId;
            }
            if (!authorizer.RecommendItem_Manage(tenantTypeId))
            {
                return(Redirect(SiteUrls.Instance().SystemMessage(TempData, new SystemMessageViewModel
                {
                    Body = "没有管理推荐内容的权限",
                    Title = "没有权限",
                    StatusMessageType = StatusMessageType.Hint
                })));
            }
            IEnumerable <RecommendItemType> itemTypes      = recommendService.GetRecommendTypes(tenantTypeId);
            IEnumerable <RecommendItem>     recommendItems = recommendService.Gets(itemId, tenantTypeId);

            //已修改
            RecommendItemEditModel itemEditModel = new RecommendItemEditModel();

            ViewData["recommendItems"] = recommendItems;

            //已修改
            ViewData["TypeId"] = new SelectList(itemTypes, "TypeId", "Name", recommendItemTypeId);
            if (recommendId != 0)
            {
                itemEditModel = recommendItem.AsEditModel();
                ViewData["HasFeaturedImage"] = recommendItem.RecommendItemType.HasFeaturedImage;
            }
            else
            {
                if (itemTypes != null && itemTypes.Count() > 0 && string.IsNullOrEmpty(recommendItemTypeId))
                {
                    //已修改
                    recommendItemTypeId = itemTypes.First().TypeId;
                }
                if (!string.IsNullOrEmpty(recommendItemTypeId))
                {
                    recommendItem = recommendService.Get(itemId, recommendItemTypeId);
                    RecommendItemType recommendType = recommendService.GetRecommendType(recommendItemTypeId);
                    ViewData["HasFeaturedImage"]  = recommendType.HasFeaturedImage;
                    ViewData["RecommendTypeName"] = recommendType.Name;
                    ViewData["RecommendTypeId"]   = recommendType.TypeId;
                    if (recommendItem != null && !recommendItem.IsLink)
                    {
                        ViewData["ExpiredDate"] = recommendItem.ExpiredDate;
                        itemEditModel           = recommendItem.AsEditModel();
                    }
                    else
                    {
                        RecommendItem newItem = RecommendItem.New();
                        newItem.ItemName     = itemName;
                        newItem.ItemId       = itemId;
                        newItem.TenantTypeId = tenantTypeId;
                        newItem.ExpiredDate  = DateTime.UtcNow.AddMonths(1);
                        newItem.UserId       = userId;
                        itemEditModel        = newItem.AsEditModel();
                    }
                }

                else
                {
                    StatusMessageData message           = null;
                    TenantTypeService tenantTypeService = new TenantTypeService();
                    TenantType        tenantType        = tenantTypeService.Get(tenantTypeId);

                    if (tenantType == null)
                    {
                        message = new StatusMessageData(StatusMessageType.Hint, "没有推荐类别");
                    }
                    else
                    {
                        message = new StatusMessageData(StatusMessageType.Hint, tenantType.Name + "下没有推荐类别");
                    }
                    ViewData["statusMessageData"] = message;
                }
            }
            ViewData["showLink"]   = showLink || itemEditModel.IsLink;
            ViewData["showInList"] = showInList;
            return(View(itemEditModel));
        }