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, "操作成功!")))); }
/// <summary> /// 上传Logo /// </summary> /// <param name="associateId"></param> /// <param name="stream"></param> /// <returns>上传文件的相对路径(包含文件名)</returns> public string UploadLogo(object associateId, Stream stream) { string relativeFileName = string.Empty; if (stream != null) { ILogoSettingsManager logoSettingsManager = DIContainer.Resolve <ILogoSettingsManager>(); LogoSettings logoSettings = logoSettingsManager.Get(); //检查是否需要缩放原图 Image image = Image.FromStream(stream); if (image.Height > this.TenantLogoSettings.MaxHeight || image.Width > this.TenantLogoSettings.MaxWidth) { stream = ImageProcessor.Resize(stream, this.TenantLogoSettings.MaxWidth, this.TenantLogoSettings.MaxHeight, logoSettings.ResizeMethod); } string relativePath = GetLogoRelativePath(associateId); string fileName = GetLogoFileName(associateId); relativeFileName = relativePath + "\\" + fileName; StoreProvider.AddOrUpdateFile(relativePath, fileName, stream); stream.Dispose(); //根据不同租户类型的设置生成不同尺寸的图片,用于图片直连访问 if (this.TenantLogoSettings.ImageSizeTypes != null && this.TenantLogoSettings.ImageSizeTypes.Count > 0) { foreach (var imageSizeType in this.TenantLogoSettings.ImageSizeTypes.Values) { string sizedFileName = StoreProvider.GetSizeImageName(fileName, imageSizeType.Key, imageSizeType.Value); StoreProvider.DeleteFile(relativePath, sizedFileName); IStoreFile file = StoreProvider.GetResizedImage(relativePath, fileName, imageSizeType.Key, imageSizeType.Value); } } } return(relativeFileName); }
public ActionResult EditTag(TagEditModel tagEditModel) { System.IO.Stream stream = null; //是否创建 bool isCreate = tagEditModel.TagId == 0; if (isCreate) { ViewData["editTagTitle"] = "创建标签"; } else { ViewData["editTagTitle"] = "编辑标签"; } TagService tagService = new TagService(tagEditModel.TenantTypeId); //是特色标签 if (tagEditModel.IsFeatured) { HttpPostedFileBase tagLogo = Request.Files["tagLogo"]; string fileName = tagLogo == null ? "" : tagLogo.FileName; if (string.IsNullOrEmpty(fileName) && string.IsNullOrEmpty(tagEditModel.FeaturedImage)) { //所属租户类型下拉框 SelectList tenants = GetTenantSelectList(MultiTenantServiceKeys.Instance().Tag(), tagEditModel.TenantTypeId); ViewData["tenants"] = tenants; //标签分组下拉框 SelectList tagGroups = GetTagGroupSelectList(tagEditModel.GroupId, tagEditModel.TenantTypeId); ViewData["tagGroups"] = tagGroups; //取到用户设置的相关标签 ViewData["seletedTagNames"] = tagEditModel.RelatedTags[1].Split(',').ToList <string>(); ViewData["StatusMessageData"] = new StatusMessageData(StatusMessageType.Error, "图片不能为空"); return(View(tagEditModel)); } else if (!string.IsNullOrEmpty(fileName)) { //校验附件的扩展名 ILogoSettingsManager logoSettingsManager = DIContainer.Resolve <ILogoSettingsManager>(); if (!logoSettingsManager.Get().ValidateFileExtensions(fileName)) { //所属租户类型下拉框 SelectList tenants = GetTenantSelectList(MultiTenantServiceKeys.Instance().Tag(), tagEditModel.TenantTypeId); ViewData["tenants"] = tenants; //标签分组下拉框 SelectList tagGroups = GetTagGroupSelectList(tagEditModel.GroupId, tagEditModel.TenantTypeId); ViewData["tagGroups"] = tagGroups; //取到用户设置的相关标签 ViewData["seletedTagNames"] = tagEditModel.RelatedTags[1].Split(',').ToList <string>(); 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 tenants = GetTenantSelectList(MultiTenantServiceKeys.Instance().Tag(), tagEditModel.TenantTypeId); ViewData["tenants"] = tenants; //标签分组下拉框 SelectList tagGroups = GetTagGroupSelectList(tagEditModel.GroupId, tagEditModel.TenantTypeId); ViewData["tagGroups"] = tagGroups; //取到用户设置的相关标签 ViewData["seletedTagNames"] = tagEditModel.RelatedTags[1].Split(',').ToList <string>(); ViewData["StatusMessageData"] = new StatusMessageData(StatusMessageType.Error, string.Format("文件大小不允许超过{0}KB", tenantLogoSettings.MaxLogoLength)); return(View(tagEditModel)); } stream = tagLogo.InputStream; tagEditModel.FeaturedImage = fileName; } } //获取相关标签 string relatedTags = tagEditModel.RelatedTags[1]; //创建 if (isCreate) { Tag tag = tagEditModel.AsTag(); tagService.Create(tag, stream); //添加到分组 if (tagEditModel.GroupId > 0) { tagService.BatchAddGroupsToTag(new List <long>() { tagEditModel.GroupId }, tagEditModel.TagName); } //创建相关标签 if (!string.IsNullOrEmpty(relatedTags)) { tagService.AddRelatedTagsToTag(relatedTags, 0, tag.TagId); } }//更新 else { Tag tag = tagEditModel.AsTag(); tagService.Update(tag, stream); //添加到分组 if (tagEditModel.GroupId > 0) { tagService.BatchAddGroupsToTag(new List <long>() { tagEditModel.GroupId }, tagEditModel.TagName); } //创建相关标签 if (!string.IsNullOrEmpty(relatedTags)) { tagService.ClearRelatedTagsFromTag(tagEditModel.TagId); tagService.AddRelatedTagsToTag(relatedTags, 0, tagEditModel.TagId); } } return(RedirectToAction("ManageTags")); }
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)) { //校验附件的扩展名 ILogoSettingsManager logoSettingsManager = DIContainer.Resolve <ILogoSettingsManager>(); if (!logoSettingsManager.Get().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")); }