Beispiel #1
0
        /// <summary>
        /// 贴吧所在呈现区域拥有者自动创建贴吧事件
        /// </summary>
        /// <param name="sender">群组实体</param>
        /// <param name="eventArgs">事件参数</param>
        void AutoMaintainBarSectionModule_After(GroupEntity sender, CommonEventArgs eventArgs)
        {
            BarSectionService barSectionService = new BarSectionService();

            if (eventArgs.EventOperationType == EventOperationType.Instance().Create())
            {
                BarSection barSection = BarSection.New();

                barSection.TenantTypeId         = TenantTypeIds.Instance().Group();
                barSection.SectionId            = sender.GroupId;
                barSection.OwnerId              = sender.GroupId;
                barSection.UserId               = sender.UserId;
                barSection.Name                 = sender.GroupName;
                barSection.IsEnabled            = true;
                barSection.LogoImage            = sender.Logo;
                barSection.ThreadCategoryStatus = ThreadCategoryStatus.NotForceEnabled;
                barSectionService.Create(barSection, sender.UserId, null, null);
            }
            else if (eventArgs.EventOperationType == EventOperationType.Instance().Update())
            {
                BarSection barSection = barSectionService.Get(sender.GroupId);
                barSection.UserId    = sender.UserId;
                barSection.Name      = sender.GroupName;
                barSection.LogoImage = sender.Logo;

                IList <long> managerIds = null;
                if (barSection.SectionManagers != null)
                {
                    managerIds = barSection.SectionManagers.Select(n => n.UserId).ToList();
                }
                barSectionService.Update(barSection, sender.UserId, managerIds, null);
            }
            else if (eventArgs.EventOperationType == EventOperationType.Instance().Approved() || eventArgs.EventOperationType == EventOperationType.Instance().Disapproved())
            {
                BarSection barSection = barSectionService.Get(sender.GroupId);
                barSection.AuditStatus = sender.AuditStatus;
                IList <long> managerIds = null;
                if (barSection.SectionManagers != null)
                {
                    managerIds = barSection.SectionManagers.Select(n => n.UserId).ToList();
                }
                barSectionService.Update(barSection, sender.UserId, managerIds, null);
            }
            else
            {
                barSectionService.Delete(sender.GroupId);
            }
        }
        public ActionResult EditSection(BarSectionEditModel model)
        {
            HttpPostedFileBase logoImage         = Request.Files["LogoImage"];
            string             logoImageFileName = string.Empty;
            Stream             stream            = null;

            if (logoImage != null && !string.IsNullOrEmpty(logoImage.FileName))
            {
                TenantLogoSettings tenantLogoSettings = TenantLogoSettings.GetRegisteredSettings(TenantTypeIds.Instance().BarSection());
                if (!tenantLogoSettings.ValidateFileLength(logoImage.ContentLength))
                {
                    ViewData["StatusMessageData"] = new StatusMessageData(StatusMessageType.Error, string.Format("Logo文件大小不允许超过{0}", Formatter.FormatFriendlyFileSize(tenantLogoSettings.MaxLogoLength * 1024)));
                    return(View(model));
                }

                LogoSettings logoSettings = DIContainer.Resolve <ILogoSettingsManager>().Get();
                if (!logoSettings.ValidateFileExtensions(logoImage.FileName))
                {
                    ViewData["StatusMessageData"] = new StatusMessageData(StatusMessageType.Error, "Logo文件是不支持的文件类型,仅支持" + logoSettings.AllowedFileExtensions);
                    return(View(model));
                }
                stream            = logoImage.InputStream;
                logoImageFileName = logoImage.FileName;
            }


            IEnumerable <long> managerUserIds = Request.Form.Gets <long>("ManagerUserIds");

            if (model.SectionId == 0)
            {
                BarSection section = model.AsBarSection();

                //long userId = Request.QueryString.Gets<long>(model.UserId, new List<long>()).FirstOrDefault();


                section.UserId = Request.Form.Gets <long>("UserId", new List <long>()).FirstOrDefault();
                if (section.UserId == 0)
                {
                    ViewData["StatusMessageData"] = new StatusMessageData(StatusMessageType.Error, "请输入吧主信息");
                    return(View(model));
                }
                section.LogoImage    = logoImageFileName;
                section.DisplayOrder = model.DisplayOrder ?? 100;
                if (managerUserIds != null && managerUserIds.Count() > 0)
                {
                    managerUserIds = managerUserIds.Where(n => n != section.UserId);
                }

                bool isCreated = barSectionService.Create(section, UserContext.CurrentUser.UserId, managerUserIds, stream);

                categoryService.AddItemsToCategory(new List <long> {
                    section.SectionId
                }, model.CategoryId, 0);

                if (isCreated)
                {
                    TempData["StatusMessageData"] = new StatusMessageData(StatusMessageType.Success, "创建成功");
                    return(Redirect(SiteUrls.Instance().EditSection(section.SectionId)));
                }
                ViewData["StatusMessageData"] = new StatusMessageData(StatusMessageType.Error, "创建失败");
                return(View(model));
            }
            else
            {
                BarSection section = model.AsBarSection();



                long userId = Request.Form.Gets <long>("UserId", new List <long>()).FirstOrDefault();
                if (userId == 0)
                {
                    ViewData["StatusMessageData"] = new StatusMessageData(StatusMessageType.Error, "必须输入吧主信息");
                    ViewData["ManagerUserIds"]    = barSectionService.GetSectionManagers(section.SectionId).Select(n => n.UserId);
                    IBarSettingsManager manager  = DIContainer.Resolve <IBarSettingsManager>();
                    BarSettings         settings = manager.Get();
                    ViewData["SectionManagerMaxCount"] = settings.SectionManagerMaxCount;
                    return(View(model));
                }
                section.UserId = userId;
                if (!string.IsNullOrEmpty(logoImageFileName))
                {
                    section.LogoImage = logoImageFileName;
                }
                section.DisplayOrder = model.DisplayOrder ?? 100;
                barSectionService.Update(section, UserContext.CurrentUser.UserId, managerUserIds, stream);
                categoryService.ClearCategoriesFromItem(section.SectionId, 0, TenantTypeIds.Instance().BarSection());
                categoryService.AddItemsToCategory(new List <long> {
                    section.SectionId
                }, model.CategoryId, 0);

                TempData["StatusMessageData"] = new StatusMessageData(StatusMessageType.Success, "更新成功");
                return(Redirect(SiteUrls.Instance().EditSection(model.SectionId)));
            }
        }