/// <summary> /// 删除功能信息信息 /// </summary> /// <param name="ids">要删除的功能信息编号</param> /// <returns>业务操作结果</returns> public OperationResult DeleteFunctions(params Guid[] ids) { ids.CheckNotNull("ids"); List <string> names = new List <string>(); FunctionRepository.UnitOfWork.TransactionEnabled = true; foreach (Guid id in ids) { Function entity = FunctionRepository.GetByKey(id); if (entity == null) { return(new OperationResult(OperationResultType.QueryNull)); } if (!entity.IsCustom) { return(new OperationResult(OperationResultType.Error, "功能“{0}”不是自定义功能,不能删除".FormatWith(entity.Name))); } FunctionRepository.Delete(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) { IFunctionHandler handler = ServiceProvider.GetService <IFunctionHandler>(); handler.RefreshCache(); } return(result); }
/// <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); }