/// <summary> /// 删除代码模块信息信息 /// </summary> /// <param name="ids">要删除的代码模块信息编号</param> /// <returns>业务操作结果</returns> public async Task <OperationResult> DeleteCodeModules(params Guid[] ids) { List <string> names = new List <string>(); UnitOfWork.EnableTransaction(); foreach (var id in ids) { var module = ModuleRepository.Query(m => m.Id == id).Select(m => new { D = m, EntityCount = m.Entities.Count() }) .FirstOrDefault(); if (module == null) { return(null); } if (module.EntityCount > 0) { return(new OperationResult(OperationResultType.Error, $"模块“{module.D.Name}”包含着 {module.EntityCount} 个实体,请先删除下属实体信息")); } int count = await ModuleRepository.DeleteAsync(module.D); if (count > 0) { names.Add(module.D.Name); } } await UnitOfWork.CommitAsync(); return(names.Count > 0 ? new OperationResult(OperationResultType.Success, $"模块“{names.ExpandAndToString()}”删除成功") : OperationResult.NoChanged); }
/// <summary> /// 删除模块信息信息 /// </summary> /// <param name="id">要删除的模块信息编号</param> /// <returns>业务操作结果</returns> public virtual async Task <OperationResult> DeleteModule(TModuleKey id) { TModule module = await ModuleRepository.GetByKeyAsync(id); if (module == null) { return(OperationResult.Success); } if (module.SubModules.Count > 0) { return(new OperationResult(OperationResultType.Error, "模块“{0}”的子模块不为空,不能删除".FormatWith(module.Name))); } module.Functions.Clear(); await ModuleRepository.DeleteAsync(module); return(OperationResult.Success); }
/// <summary> /// 删除模块信息信息 /// </summary> /// <param name="id">要删除的模块信息编号</param> /// <returns>业务操作结果</returns> public virtual async Task <OperationResult> DeleteModule(TModuleKey id) { TModule entity = await ModuleRepository.GetByKeyAsync(id); if (entity == null) { return(OperationResult.Success); } if (entity.SubModules.Count > 0) { return(new OperationResult(OperationResultType.Error, "模块“{0}”的子模块不为空,不能删除".FormatWith(entity.Name))); } entity.Functions.Clear(); return(await ModuleRepository.DeleteAsync(entity) > 0 ? new OperationResult(OperationResultType.Success, "模块“{0}”删除成功".FormatWith(entity.Name)) : OperationResult.NoChanged); }