/// <summary>
 /// 将数据库实体转换为EditModel
 /// </summary>
 /// <param name="accountType"></param>
 /// <returns></returns>
 public static IdentificationTypeEditModel AsEditModel(this IdentificationType identificationType)
 {
     return(new IdentificationTypeEditModel
     {
         Name = identificationType.Name,
         Description = identificationType.Description,
         Enabled = identificationType.Enabled,
         IdentificationTypeId = identificationType.IdentificationTypeId,
         IdentificationTypeLogo = identificationType.IdentificationTypeLogo
     });
 }
        /// <summary>
        /// 新建实体时使用
        /// </summary>
        public static IdentificationType New()
        {
            IdentificationType identificationType = new IdentificationType()
            {
                Name        = string.Empty,
                Description = string.Empty,
                CreaterId   = 0,
                DateCreated = DateTime.UtcNow
            };

            return(identificationType);
        }
Exemple #3
0
        public ActionResult _EditIdentificationType(long identificationTypeId = 0)
        {
            //如果Id为0则为添加标识
            if (identificationTypeId == 0)
            {
                return(View());
            }

            //获得所有标识
            IdentificationType identificationType = identificationService.GetIdentificationTypes(null).SingleOrDefault(n => n.IdentificationTypeId == identificationTypeId);

            return(View(identificationType.AsEditModel()));
        }
Exemple #4
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, "操作成功!"))));
        }
        /// <summary>
        /// 更新认证标识
        /// </summary>
        /// <param name="identificationType">认证标识实体</param>
        /// <returns></returns>
        public bool UpdateIdentificationType(IdentificationType identificationType, Stream logoStream)
        {
            EventBus <IdentificationType> .Instance().OnBefore(identificationType, new CommonEventArgs(EventOperationType.Instance().Update()));

            if (logoStream != null)
            {
                LogoService logoService = new LogoService(TenantTypeIds.Instance().IdentificationType());
                identificationType.IdentificationTypeLogo = logoService.UploadLogo(identificationType.IdentificationTypeId, logoStream);
            }
            identificationTypeRepository.Update(identificationType);

            EventBus <IdentificationType> .Instance().OnAfter(identificationType, new CommonEventArgs(EventOperationType.Instance().Update()));

            return(true);
        }
        /// <summary>
        /// 将EditModel转为数据库实体
        /// </summary>
        /// <returns></returns>
        public IdentificationType AsIdentificationType()
        {
            IdentificationType identificationtype = null;

            if (IdentificationTypeId == 0)
            {
                identificationtype = IdentificationType.New();
            }
            else
            {
                identificationtype = new IdentificationTypeRepository().Get(this.IdentificationTypeId);
            }
            identificationtype.CreaterId   = UserContext.CurrentUser.UserId;
            identificationtype.DateCreated = DateTime.Now;
            identificationtype.Description = this.Description;
            identificationtype.Enabled     = this.Enabled;
            identificationtype.Name        = this.Name;

            return(identificationtype);
        }
        /// <summary>
        /// 删除认证标识
        /// </summary>
        /// <param name="identificationTypeId">认证标识ID</param>
        /// <returns></returns>
        public bool DeleteIdentificationType(long identificationTypeId)
        {
            IdentificationType identificationType = identificationTypeRepository.Get(identificationTypeId);

            if (identificationType != null)
            {
                EventBus <IdentificationType> .Instance().OnBefore(identificationType, new CommonEventArgs(EventOperationType.Instance().Delete()));

                //删除认证标识和该认证标识下的所有申请
                IdentificationTypeRepository typeRepository = new IdentificationTypeRepository();
                typeRepository.DeleteIdentificationTypes(identificationTypeId);

                //删除认证标识图
                LogoService logoService = new LogoService(TenantTypeIds.Instance().IdentificationType());
                logoService.DeleteLogo(identificationTypeId);

                EventBus <IdentificationType> .Instance().OnAfter(identificationType, new CommonEventArgs(EventOperationType.Instance().Delete()));

                return(true);
            }
            return(false);
        }