public ActionResult CreateRole(RoleEditModel model) { Stream stream = null; HttpPostedFileBase roleImage = Request.Files["RoleImage"]; Role role = roleService.Get(model.RoleName); if (roleImage != null && !string.IsNullOrEmpty(roleImage.FileName)) { TenantLogoSettings tenantLogoSettings = TenantLogoSettings.GetRegisteredSettings(TenantTypeIds.Instance().Role()); if (!tenantLogoSettings.ValidateFileLength(roleImage.ContentLength)) { ViewData["StatusMessageData"] = new StatusMessageData(StatusMessageType.Error, string.Format("文件大小不允许超过{0}", Formatter.FormatFriendlyFileSize(tenantLogoSettings.MaxLogoLength * 1024))); return(View(model)); } LogoSettings logoSettings = DIContainer.Resolve <ILogoSettingsManager>().Get(); if (!logoSettings.ValidateFileExtensions(roleImage.FileName)) { ViewData["StatusMessageData"] = new StatusMessageData(StatusMessageType.Error, "不支持的文件类型,仅支持" + logoSettings.AllowedFileExtensions); return(View(model)); } stream = roleImage.InputStream; model.RoleImage = roleImage.FileName; } else //当取不到上传的图片文件名时RoleImage值保持不变 { model.RoleImage = role != null ? role.RoleImage : string.Empty; } if (ModelState.IsValid) { if (role != null) { WebUtility.SetStatusCodeForError(Response); EditUserRole_GenerateFormItem(); model.RoleName = string.Empty; ViewData["StatusMessageData"] = new StatusMessageData(StatusMessageType.Error, "角色名已存在!"); return(View("_CreateRole", model)); } role = model.AsRole(); roleService.Create(role, stream); } return(RedirectToAction("ManageUsers")); }
public ActionResult _EditIdentificationType(IdentificationTypeEditModel editModel) { string fileName = string.Empty; Stream stream = null; //获取上传图片 HttpPostedFileBase logo = Request.Files["IdentificationTypeLogo"]; //如果上传图片不为空则校验其扩展名和大小 if (logo != null && logo.ContentLength > 0) { fileName = logo.FileName; //校验附件的扩展名 ILogoSettingsManager logoSettingsManager = DIContainer.Resolve <ILogoSettingsManager>(); LogoSettings logoSettings = logoSettingsManager.Get(); if (!logoSettings.ValidateFileExtensions(fileName)) { return(Content(WarpJsonMessage(new StatusMessageData(StatusMessageType.Error, "只允许上传后缀名为 " + logoSettings.AllowedFileExtensions.TrimEnd(',') + " 的文件")))); } //校验附件的大小 TenantLogoSettings tenantLogoSettings = TenantLogoSettings.GetRegisteredSettings(TenantTypeIds.Instance().Identification()); if (!tenantLogoSettings.ValidateFileLength(logo.ContentLength)) { return(Content(WarpJsonMessage(new StatusMessageData(StatusMessageType.Error, string.Format("文件大小不允许超过{0}KB", tenantLogoSettings.MaxLogoLength))))); } stream = logo.InputStream; } //如果IdentificationTypeId大于0则为编辑标识 if (editModel.IdentificationTypeId > 0) { IdentificationType identificationType = editModel.AsIdentificationType(); identificationService.UpdateIdentificationType(identificationType, stream); } //否则为创建标识 else { if (logo == null || logo.ContentLength == 0) { return(Content(WarpJsonMessage(new StatusMessageData(StatusMessageType.Error, "图片不能为空!")))); } IdentificationType identificationType = editModel.AsIdentificationType(); identificationService.CreateIdentificationType(identificationType, stream); } return(Content(WarpJsonMessage(new StatusMessageData(StatusMessageType.Success, "操作成功!")))); }
public ActionResult Create(GroupEditModel groupEditModel) { string errorMessage = null; if (ModelState.HasBannedWord(out errorMessage)) { return(Redirect(SiteUrls.Instance().SystemMessage(TempData, new SystemMessageViewModel { Body = errorMessage, Title = "创建失败", StatusMessageType = StatusMessageType.Error }))); } System.IO.Stream stream = null; HttpPostedFileBase groupLogo = Request.Files["GroupLogo"]; //已修改 IUser user = UserContext.CurrentUser; if (user == null) { return(Json(new StatusMessageData(StatusMessageType.Error, "您尚未登录!"))); } if (!new Authorizer().Group_Create(out errorMessage)) { return(Redirect(SiteUrls.Instance().SystemMessage(TempData, new SystemMessageViewModel { Body = errorMessage, Title = errorMessage, StatusMessageType = StatusMessageType.Error }))); } if (groupLogo != null && !string.IsNullOrEmpty(groupLogo.FileName)) { TenantLogoSettings tenantLogoSettings = TenantLogoSettings.GetRegisteredSettings(TenantTypeIds.Instance().Group()); if (!tenantLogoSettings.ValidateFileLength(groupLogo.ContentLength)) { ViewData["StatusMessageData"] = new StatusMessageData(StatusMessageType.Error, string.Format("文件大小不允许超过{0}", Formatter.FormatFriendlyFileSize(tenantLogoSettings.MaxLogoLength * 1024))); return(View(groupEditModel)); } LogoSettings logoSettings = DIContainer.Resolve <ILogoSettingsManager>().Get(); if (!logoSettings.ValidateFileExtensions(groupLogo.FileName)) { ViewData["StatusMessageData"] = new StatusMessageData(StatusMessageType.Error, "不支持的文件类型,仅支持" + logoSettings.AllowedFileExtensions); return(View(groupEditModel)); } stream = groupLogo.InputStream; groupEditModel.Logo = groupLogo.FileName; } GroupEntity group = groupEditModel.AsGroupEntity(); bool result = groupService.Create(user.UserId, group); if (stream != null) { groupService.UploadLogo(group.GroupId, stream); } //设置分类 if (groupEditModel.CategoryId > 0) { categoryService.AddItemsToCategory(new List <long>() { group.GroupId }, groupEditModel.CategoryId, 0); } //设置标签 string relatedTags = Request.Form.Get <string>("RelatedTags"); if (!string.IsNullOrEmpty(relatedTags)) { tagService.AddTagsToItem(relatedTags, group.GroupId, group.GroupId); } //发送邀请 if (!string.IsNullOrEmpty(groupEditModel.RelatedUserIds)) { //已修改 IEnumerable <long> userIds = Request.Form.Gets <long>("RelatedUserIds", null); groupService.SendInvitations(group, user, string.Empty, userIds); } return(Redirect(SiteUrls.Instance().GroupHome(group.GroupKey))); }
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 <ISettingsManager <LogoSettings> >().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); 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); ISettingsManager <BarSettings> manager = DIContainer.Resolve <ISettingsManager <BarSettings> >(); 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); TempData["StatusMessageData"] = new StatusMessageData(StatusMessageType.Success, "更新成功"); return(Redirect(SiteUrls.Instance().EditSection(model.SectionId))); } }
public ActionResult EditGroup(string spaceKey, GroupEditModel groupEditModel) { IUser currentUser = UserContext.CurrentUser; if (currentUser == null) { return(Json(new StatusMessageData(StatusMessageType.Error, "您尚未登录!"))); } System.IO.Stream stream = null; HttpPostedFileBase groupLogo = Request.Files["GroupLogo"]; if (groupLogo != null && !string.IsNullOrEmpty(groupLogo.FileName)) { TenantLogoSettings tenantLogoSettings = TenantLogoSettings.GetRegisteredSettings(TenantTypeIds.Instance().Group()); if (!tenantLogoSettings.ValidateFileLength(groupLogo.ContentLength)) { ViewData["StatusMessageData"] = new StatusMessageData(StatusMessageType.Error, string.Format("文件大小不允许超过{0}", Formatter.FormatFriendlyFileSize(tenantLogoSettings.MaxLogoLength * 1024))); return(View(groupEditModel)); } LogoSettings logoSettings = DIContainer.Resolve <ILogoSettingsManager>().Get(); if (!logoSettings.ValidateFileExtensions(groupLogo.FileName)) { ViewData["StatusMessageData"] = new StatusMessageData(StatusMessageType.Error, "不支持的文件类型,仅支持" + logoSettings.AllowedFileExtensions); return(View(groupEditModel)); } stream = groupLogo.InputStream; groupEditModel.Logo = groupLogo.FileName; } GroupEntity group = groupEditModel.AsGroupEntity(); //设置分类 if (groupEditModel.CategoryId > 0) { categoryService.ClearCategoriesFromItem(group.GroupId, 0, TenantTypeIds.Instance().Group()); categoryService.AddItemsToCategory(new List <long>() { group.GroupId }, groupEditModel.CategoryId, 0); } //已修改 //设置标签 string relatedTags = Request.Form.Get <string>("RelatedTags"); if (!string.IsNullOrEmpty(relatedTags)) { tagService.ClearTagsFromItem(group.GroupId, group.GroupId); tagService.AddTagsToItem(relatedTags, group.GroupId, group.GroupId); } if (stream != null) { groupService.UploadLogo(group.GroupId, stream); } groupService.Update(currentUser.UserId, group); TempData["StatusMessageData"] = new StatusMessageData(StatusMessageType.Success, "更新成功!"); return(Redirect(SiteUrls.Instance().EditGroup(group.GroupKey))); }
public ActionResult EditTopic(TagEditModel tagEditModel) { System.IO.Stream stream = null; //是否创建 bool isCreate = tagEditModel.TagId == 0; if (isCreate) { ViewData["editTopicTitle"] = "创建话题"; } else { ViewData["editTopicTitle"] = "编辑话题"; } TagService tagService = new TagService(tagEditModel.TenantTypeId); IEnumerable <long> userIds = Request.Form.Gets <long>("RelatedObjectIds"); //是特色标签 if (tagEditModel.IsFeatured) { HttpPostedFileBase tagLogo = Request.Files["tagLogo"]; string fileName = tagLogo == null ? "" : tagLogo.FileName; if (string.IsNullOrEmpty(fileName) && string.IsNullOrEmpty(tagEditModel.FeaturedImage)) { //标签分组下拉框 SelectList topicGroups = GetTagGroupSelectList(tagEditModel.TopicGroupId, tagEditModel.TenantTypeId); ViewData["topicGroups"] = topicGroups; //取到用户设置的相关标签 ViewData["seletedUserIds"] = userIds; ViewData["StatusMessageData"] = new StatusMessageData(StatusMessageType.Error, "图片不能为空"); return(View(tagEditModel)); } else if (!string.IsNullOrEmpty(fileName)) { //校验附件的扩展名 LogoSettings logoSettings = DIContainer.Resolve <ISettingsManager <LogoSettings> >().Get(); if (!logoSettings.ValidateFileExtensions(fileName)) { //标签分组下拉框 SelectList topicGroups = GetTagGroupSelectList(tagEditModel.TopicGroupId, tagEditModel.TenantTypeId); ViewData["topicGroups"] = topicGroups; //取到用户设置的相关标签 ViewData["seletedUserIds"] = userIds; ViewData["StatusMessageData"] = new StatusMessageData(StatusMessageType.Error, "只允许上传后缀名为 .gif .jpg .jpeg .png 的文件"); return(View(tagEditModel)); } //校验附件的大小 TenantLogoSettings tenantLogoSettings = TenantLogoSettings.GetRegisteredSettings(TenantTypeIds.Instance().Tag()); if (!tenantLogoSettings.ValidateFileLength(tagLogo.ContentLength)) { //标签分组下拉框 SelectList topicGroups = GetTagGroupSelectList(tagEditModel.TopicGroupId, tagEditModel.TenantTypeId); ViewData["topicGroups"] = topicGroups; //取到用户设置的相关标签 ViewData["seletedUserIds"] = userIds; ViewData["StatusMessageData"] = new StatusMessageData(StatusMessageType.Error, string.Format("文件大小不允许超过{0}KB", tenantLogoSettings.MaxLogoLength)); return(View(tagEditModel)); } stream = tagLogo.InputStream; tagEditModel.FeaturedImage = fileName; } } //获取相关微博 IEnumerable <long> seletedUserIds = userIds; //创建 if (isCreate) { Tag tag = tagEditModel.AsTag(); tagService.Create(tag, stream); //添加到分组 if (tagEditModel.TopicGroupId > 0) { tagService.BatchAddGroupsToTag(new List <long>() { tagEditModel.TopicGroupId }, tagEditModel.TagName); } }//更新 else { Tag tag = tagEditModel.AsTag(); tagService.Update(tag, stream); //添加到分组 if (tagEditModel.TopicGroupId > 0) { tagService.BatchAddGroupsToTag(new List <long>() { tagEditModel.TopicGroupId }, tagEditModel.TagName); } } return(RedirectToAction("ManageMicroblogTopics")); }