/// <summary> /// 添加功能信息信息 /// </summary> /// <param name="dtos">要添加的功能信息DTO信息</param> /// <returns>业务操作结果</returns> public OperationResult AddFunctions(params FunctionDto[] dtos) { dtos.CheckNotNull("dtos"); OperationResult result = FunctionRepository.Insert(dtos, dto => { if (dto.Url.IsNullOrWhiteSpace()) { throw new Exception("自定义功能的URL不能为空"); } if (FunctionRepository.CheckExists(m => m.Name == dto.Name)) { throw new Exception("名称为“{0}”的功能信息已存在".FormatWith(dto.Name)); } if (dto.Url == null && FunctionRepository.CheckExists(m => m.Area == dto.Area && m.Controller == dto.Controller && m.Action == dto.Action)) { throw new Exception("区域“{0}”控制器“{1}”方法“{2}”的功能信息已存在".FormatWith(dto.Area, dto.Controller, dto.Action)); } }, (dto, entity) => { entity.IsCustom = true; if (entity.Url.IsNullOrEmpty()) { entity.Url = null; } return(entity); }); if (result.ResultType == OperationResultType.Success) { OSharpContext.Current.FunctionHandler.RefreshCache(); } return(result); }
/// <summary> /// 添加功能信息信息 /// </summary> /// <param name="dto">要添加的功能信息DTO信息</param> /// <returns>业务操作结果</returns> public virtual async Task <OperationResult> CreateFunction(TFunctionInputDto dto) { if (dto.Url.IsMissing()) { return(new OperationResult(OperationResultType.Error, "自定义功能的URL不能为空")); } if (await FunctionRepository.CheckExistsAsync(m => m.Name == dto.Name)) { return(new OperationResult(OperationResultType.Error, "名称为“{0}”的功能信息已存在".FormatWith(dto.Name))); } if (dto.Url == null && FunctionRepository.CheckExists(m => m.Area == dto.Area && m.Controller == dto.Controller && m.Action == dto.Action)) { return(new OperationResult(OperationResultType.Error, "区域“{0}”控制器“{1}”方法“{2}”的功能信息已存在".FormatWith(dto.Area, dto.Controller, dto.Action))); } TFunction entity = dto.MapTo <TFunction>(); entity.IsCustom = true; if (entity.Url.IsMissing()) { entity.Url = null; } await FunctionRepository.InsertAsync(entity); return(OperationResult.Success); }
/// <summary> /// 更新功能信息信息 /// </summary> /// <param name="dtos">包含更新信息的功能信息DTO信息</param> /// <returns>业务操作结果</returns> public async Task <OperationResult> EditFunctions(params FunctionDto[] dtos) { dtos.CheckNotNull("dtos"); List <string> names = new List <string>(); FunctionRepository.UnitOfWork.TransactionEnabled = true; foreach (FunctionDto dto in dtos) { if (FunctionRepository.CheckExists(m => m.Name == dto.Name, dto.Id)) { return(new OperationResult(OperationResultType.Error, "名称为“{0}”的功能信息已存在".FormatWith(dto.Name))); } Function entity = FunctionRepository.GetByKey(dto.Id); if (entity == null) { return(new OperationResult(OperationResultType.QueryNull)); } FunctionType oldType = entity.FunctionType; bool oldIsMenu = entity.IsMenu; int oldOrderNo = entity.OrderNo; if (dto.DataLogEnabled && !dto.OperateLogEnabled && !entity.OperateLogEnabled && !entity.DataLogEnabled) { dto.OperateLogEnabled = true; } else if (!dto.OperateLogEnabled && dto.DataLogEnabled && entity.OperateLogEnabled && entity.DataLogEnabled) { dto.DataLogEnabled = false; } entity = dto.MapTo(entity); if (entity.Url.IsNullOrEmpty()) { entity.Url = null; } if (oldType != entity.FunctionType || oldIsMenu != entity.IsMenu || oldOrderNo != entity.OrderNo) { entity.IsTypeChanged = true; } FunctionRepository.Update(entity); names.Add(entity.Name); } int count = await FunctionRepository.UnitOfWork.SaveChangesAsync(); OperationResult result = count > 0 ? new OperationResult(OperationResultType.Success, "功能“{0}”更新成功".FormatWith(names.ExpandAndToString())) : new OperationResult(OperationResultType.NoChanged); if (result.ResultType == OperationResultType.Success) { IFunctionHandler handler = ServiceProvider.GetService <IFunctionHandler>(); handler.RefreshCache(); } return(result); }
/// <summary> /// 更新功能信息信息 /// </summary> /// <param name="dtos">包含更新信息的功能信息DTO信息</param> /// <returns>业务操作结果</returns> public OperationResult EditFunctions(params FunctionDto[] dtos) { dtos.CheckNotNull("dtos"); List <string> names = new List <string>(); FunctionRepository.UnitOfWork.TransactionEnabled = true; foreach (FunctionDto dto in dtos) { if (FunctionRepository.CheckExists(m => m.Name == dto.Name, dto.Id)) { return(new OperationResult(OperationResultType.Error, "名称为“{0}”的功能信息已存在".FormatWith(dto.Name))); } Function entity = FunctionRepository.GetByKey(dto.Id); if (entity == null) { return(new OperationResult(OperationResultType.QueryNull)); } FunctionType oldType = entity.FunctionType; if (dto.DataLogEnabled && !dto.OperateLogEnabled && !entity.OperateLogEnabled && !entity.DataLogEnabled) { dto.OperateLogEnabled = true; } else if (!dto.OperateLogEnabled && dto.DataLogEnabled && entity.OperateLogEnabled && entity.DataLogEnabled) { dto.DataLogEnabled = false; } entity = dto.MapTo(entity); if (entity.Url.IsNullOrEmpty()) { entity.Url = null; } if (oldType != entity.FunctionType) { entity.IsTypeChanged = true; } FunctionRepository.Update(entity); names.Add(entity.Name); } int count = FunctionRepository.UnitOfWork.SaveChanges(); OperationResult result = count > 0 ? new OperationResult(OperationResultType.Success, "功能“{0}”更新成功".FormatWith(names.ExpandAndToString())) : new OperationResult(OperationResultType.NoChanged); if (result.ResultType == OperationResultType.Success) { OSharpContext.Current.FunctionHandler.RefreshCache(); } return(result); }
/// <summary> /// 检查功能信息信息是否存在 /// </summary> /// <param name="predicate">检查谓语表达式</param> /// <param name="id">更新的功能信息编号</param> /// <returns>功能信息是否存在</returns> public bool CheckFunctionExists(Expression <Func <Function, bool> > predicate, Guid id = new Guid()) { return(FunctionRepository.CheckExists(predicate, id)); }