public ActionResult Create(TopicEditModel topicEditModel) { string errorMessage = null; if (ModelState.HasBannedWord(out errorMessage)) { return Redirect(SiteUrls.Instance().SystemMessage(TempData, new SystemMessageViewModel { Body = errorMessage, Title = "创建失败", StatusMessageType = StatusMessageType.Hint })); } System.IO.Stream stream = null; HttpPostedFileBase topicLogo = Request.Files["TopicLogo"]; //已修改 IUser user = UserContext.CurrentUser; if (user == null) return Json(new StatusMessageData(StatusMessageType.Error, "您尚未登录!")); if (!authorizer.Topic_Create(out errorMessage)) { return Redirect(SiteUrls.Instance().SystemMessage(TempData, new SystemMessageViewModel { Body = errorMessage, Title = errorMessage, StatusMessageType = StatusMessageType.Hint })); } if (topicLogo != null && !string.IsNullOrEmpty(topicLogo.FileName)) { TenantLogoSettings tenantLogoSettings = TenantLogoSettings.GetRegisteredSettings(TenantTypeIds.Instance().Topic()); if (!tenantLogoSettings.ValidateFileLength(topicLogo.ContentLength)) { ViewData["StatusMessageData"] = new StatusMessageData(StatusMessageType.Error, string.Format("文件大小不允许超过{0}", Formatter.FormatFriendlyFileSize(tenantLogoSettings.MaxLogoLength * 1024))); return View(topicEditModel); } LogoSettings logoSettings = DIContainer.Resolve<ISettingsManager<LogoSettings>>().Get(); if (!logoSettings.ValidateFileExtensions(topicLogo.FileName)) { ViewData["StatusMessageData"] = new StatusMessageData(StatusMessageType.Error, "不支持的文件类型,仅支持" + logoSettings.AllowedFileExtensions); return View(topicEditModel); } stream = topicLogo.InputStream; topicEditModel.Logo = topicLogo.FileName; } TopicEntity topic = topicEditModel.AsTopicEntity(); bool result = topicService.Create(user.UserId, topic); if (stream != null) { topicService.UploadLogo(topic.TopicId, stream); } //设置分类 if (topicEditModel.CategoryId > 0) { categoryService.AddItemsToCategory(new List<long>() { topic.TopicId }, topicEditModel.CategoryId); } //设置标签 string relatedTags = Request.Form.Get<string>("RelatedTags"); if (!string.IsNullOrEmpty(relatedTags)) { tagService.AddTagsToItem(relatedTags, topic.TopicId, topic.TopicId); } //发送邀请 if (!string.IsNullOrEmpty(topicEditModel.RelatedUserIds)) { //已修改 IEnumerable<long> userIds = Request.Form.Gets<long>("RelatedUserIds", null); topicService.SendInvitations(topic, user, string.Empty, userIds); } return Redirect(SiteUrls.Instance().TopicHome(topic.TopicKey)); }
public ActionResult Create() { pageResourceManager.InsertTitlePart("创建专题"); string errorMessage = null; if (!authorizer.Topic_Create(out errorMessage)) { return Redirect(SiteUrls.Instance().SystemMessage(TempData, new SystemMessageViewModel { Body = errorMessage, Title = errorMessage, StatusMessageType = StatusMessageType.Hint })); } TopicEditModel topic = new TopicEditModel(); return View(topic); }