Esempio n. 1
0
        /// <summary>
        /// 删除功能信息信息
        /// </summary>
        /// <param name="ids">要删除的功能信息编号</param>
        /// <returns>业务操作结果</returns>
        public async Task <OperationResult> DeleteFunctions(params Guid[] ids)
        {
            ids.CheckNotNull(nameof(ids));
            List <string> names = new List <string>();

            FunctionRepository.UnitOfWork.TransactionEnabled = true;
            foreach (Guid id in ids)
            {
                Function entity = await FunctionRepository.GetByKeyAsync(id);

                if (entity == null)
                {
                    return(new OperationResult(OperationResultType.QueryNull));
                }
                await FunctionRepository.DeleteAsync(entity);

                names.Add(entity.Name);
            }
            int count = await FunctionRepository.UnitOfWork.SaveChangesAsync();

            OperationResult result = count > 0
                ? new OperationResult(OperationResultType.Success, $"功能“{names.ExpandAndToString()}”删除成功")
                : new OperationResult(OperationResultType.NoChanged);

            if (result.ResultType == OperationResultType.Success)
            {
                IFunctionHandler handler = ServiceProvider.GetService <IFunctionHandler>();
                handler.RefreshCache();
            }
            return(result);
        }
Esempio n. 2
0
        /// <summary>
        /// 删除功能信息信息
        /// </summary>
        /// <param name="id">要删除的功能信息编号</param>
        /// <returns>业务操作结果</returns>
        public virtual async Task <OperationResult> DeleteFunction(TFunctionKey id)
        {
            TFunction entity = await FunctionRepository.GetByKeyAsync(id);

            if (entity == null)
            {
                return(new OperationResult(OperationResultType.QueryNull, "编号为“{0}”的功能信息不存在".FormatWith(id)));
            }
            if (!entity.IsCustom && !entity.IsDeleted)
            {
                return(new OperationResult(OperationResultType.Error, "功能“{0}”不是自定义功能,并且未被回收,不能删除".FormatWith(entity.Name)));
            }
            await FunctionRepository.DeleteAsync(entity);

            return(OperationResult.Success);
        }