Ejemplo n.º 1
0
        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 _EditIdentificationType(IdentificationTypeEditModel editModel)
        {
            string fileName = string.Empty;
            Stream stream = null;

            //获取上传图片
            HttpPostedFileBase logo = Request.Files["IdentificationTypeLogo"];

            //如果上传图片不为空则校验其扩展名和大小
            if (logo != null && logo.ContentLength > 0)
            {
                fileName = logo.FileName;

                //校验附件的扩展名
                ISettingsManager<LogoSettings> logoSettingsManager = DIContainer.Resolve<ISettingsManager<LogoSettings>>();
                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, "操作成功!")));
        }