Example #1
0
        /// <summary>
        /// 编辑功能用户映射信息
        /// </summary>
        /// <param name="dto">功能用户映射信息DTO</param>
        /// <returns>业务操作结果</returns>
        public virtual async Task <OperationResult> EditFunctionUserMapAsync(TFunctionUserMapDto dto)
        {
            dto.CheckNotNull("dto");
            TFunctionUserMap map = await FunctionUserMapRepository.GetByKeyAsync(dto.Id);

            if (map == null)
            {
                return(new OperationResult(OperationResultType.QueryNull, "指定编号的功能用户映射信息不存在"));
            }
            map = dto.MapTo(map);
            if (!map.Function.Id.Equals(dto.FunctionId))
            {
                TFunction function = await FunctionRepository.GetByKeyAsync(dto.FunctionId);

                if (function == null)
                {
                    return(new OperationResult(OperationResultType.QueryNull, "指定编号的功能信息不存在"));
                }
                map.Function = function;
            }
            if (!map.User.Id.Equals(dto.UserId))
            {
                TUser user = await UserRepository.GetByKeyAsync(dto.UserId);

                if (user == null)
                {
                    return(new OperationResult(OperationResultType.QueryNull, "指定编号的用户信息不存在"));
                }
                map.User = user;
            }
            return(await FunctionUserMapRepository.UpdateAsync(map) > 0
                ? new OperationResult(OperationResultType.Success, "功能用户映射信息编辑成功")
                : OperationResult.NoChanged);
        }
Example #2
0
        /// <summary>
        /// 增加功能角色映射信息
        /// </summary>
        /// <param name="dto">功能角色映射信息DTO</param>
        /// <returns>业务操作结果</returns>
        public virtual async Task <OperationResult> AddFunctionRoleMapAsync(TFunctionRoleMapDto dto)
        {
            dto.CheckNotNull("dto");
            if (await FunctionRoleMapRepository.CheckExistsAsync(m => m.Function.Id.Equals(dto.FunctionId) && m.Role.Id.Equals(dto.RoleId)))
            {
                return(new OperationResult(OperationResultType.Error, "指定功能与角色的功能角色映射信息已存在"));
            }
            TFunction function = await FunctionRepository.GetByKeyAsync(dto.FunctionId);

            if (function == null)
            {
                return(new OperationResult(OperationResultType.QueryNull, "指定编号的功能信息不存在"));
            }
            TRole role = await RoleRepository.GetByKeyAsync(dto.RoleId);

            if (role == null)
            {
                return(new OperationResult(OperationResultType.QueryNull, "指定编号的角色信息不存在"));
            }
            TFunctionRoleMap map = dto.MapTo <TFunctionRoleMap>();

            map.Function = function;
            map.Role     = role;
            return(await FunctionRoleMapRepository.InsertAsync(map) > 0
                ? new OperationResult(OperationResultType.Success, "功能角色映射信息添加成功")
                : OperationResult.NoChanged);
        }
Example #3
0
        /// <summary>
        /// 编辑功能角色映射信息
        /// </summary>
        /// <param name="dto">功能角色映射信息DTO</param>
        /// <returns>业务操作结果</returns>
        public virtual async Task <OperationResult> EditFunctionRoleMapAsync(TFunctionRoleMapDto dto)
        {
            dto.CheckNotNull("dto");
            TFunctionRoleMap map = await FunctionRoleMapRepository.GetByKeyAsync(dto.Id);

            if (map == null)
            {
                return(new OperationResult(OperationResultType.QueryNull, "指定编号的功能角色映射信息不存在"));
            }
            map = dto.MapTo(map);
            if (!map.Function.Id.Equals(dto.FunctionId))
            {
                TFunction function = await FunctionRepository.GetByKeyAsync(dto.FunctionId);

                if (function == null)
                {
                    return(new OperationResult(OperationResultType.QueryNull, "指定编号的功能信息不存在"));
                }
                map.Function = function;
            }
            if (!map.Role.Id.Equals(dto.RoleId))
            {
                TRole role = await RoleRepository.GetByKeyAsync(dto.RoleId);

                if (role == null)
                {
                    return(new OperationResult(OperationResultType.QueryNull, "指定编号的角色信息不存在"));
                }
                map.Role = role;
            }
            return(await FunctionRoleMapRepository.UpdateAsync(map) > 0
                ? new OperationResult(OperationResultType.Success, "功能角色映射信息编辑成功")
                : OperationResult.NoChanged);
        }
Example #4
0
        /// <summary>
        /// 增加功能用户映射信息
        /// </summary>
        /// <param name="dto">功能用户映射信息DTO</param>
        /// <returns>业务操作结果</returns>
        public virtual async Task <OperationResult> AddFunctionUserMapAsync(TFunctionUserMapDto dto)
        {
            dto.CheckNotNull("dto");
            if (await FunctionUserMapRepository.CheckExistsAsync(m => m.Function.Id.Equals(dto.FunctionId) && m.User.Id.Equals(dto.UserId)))
            {
                return(new OperationResult(OperationResultType.Error, "指定功能与用户的功能用户映射信息已存在"));
            }
            TFunction function = await FunctionRepository.GetByKeyAsync(dto.FunctionId);

            if (function == null)
            {
                return(new OperationResult(OperationResultType.QueryNull, "指定编号的功能信息不存在"));
            }
            TUser user = await UserRepository.GetByKeyAsync(dto.UserId);

            if (user == null)
            {
                return(new OperationResult(OperationResultType.QueryNull, "指定编号的用户信息不存在"));
            }
            TFunctionUserMap map = dto.MapTo <TFunctionUserMap>();

            map.Function = function;
            map.User     = user;
            return(await FunctionUserMapRepository.InsertAsync(map) > 0
                ? new OperationResult(OperationResultType.Success, "功能用户映射信息添加成功")
                : OperationResult.NoChanged);
        }
Example #5
0
        /// <summary>
        /// 编辑功能用户映射信息
        /// </summary>
        /// <param name="dto">功能用户映射信息DTO</param>
        /// <returns>业务操作结果</returns>
        public virtual async Task <OperationResult> UpdateFunctionUserMapAsync(TFunctionUserMapInputDto dto)
        {
            dto.CheckNotNull("dto");
            TFunctionUserMap map = await FunctionUserMapRepository.GetByKeyAsync(dto.Id);

            if (map == null)
            {
                return(new OperationResult(OperationResultType.QueryNull, "编号为“{0}”的功能用户映射信息不存在".FormatWith(dto.Id)));
            }
            map = dto.MapTo(map);
            if (!map.Function.Id.Equals(dto.FunctionId))
            {
                TFunction function = await FunctionRepository.GetByKeyAsync(dto.FunctionId);

                if (function == null)
                {
                    return(new OperationResult(OperationResultType.QueryNull, "编号为“{0}”指定编号的功能信息不存在".FormatWith(dto.FunctionId)));
                }
                map.Function = function;
            }
            if (!map.User.Id.Equals(dto.UserId))
            {
                TUser user = await UserRepository.GetByKeyAsync(dto.UserId);

                if (user == null)
                {
                    return(new OperationResult(OperationResultType.QueryNull, "编号为“{0}”指定编号的用户信息不存在".FormatWith(dto.UserId)));
                }
                map.User = user;
            }
            await FunctionUserMapRepository.UpdateAsync(map);

            return(new OperationResult(OperationResultType.Success, "功能用户映射信息编辑成功"));
        }
Example #6
0
        /// <summary>
        /// 设置角色功能
        /// </summary>
        /// <param name="roleId">角色Id</param>
        /// <param name="functionIds">功能Id集合</param>
        /// <returns>业务操作结果</returns>
        public async Task <OperationResult> SetRoleFunctions(int roleId, Guid[] functionIds)
        {
            SysRole role = await RoleRepository.GetByKeyAsync(roleId);

            if (role == null)
            {
                return(new OperationResult(OperationResultType.QueryNull, "指定编号的角色信息不存在"));
            }
            Guid[] existIds  = FunctionRoleMapRepository.Entities.Where(m => m.Role.Id == roleId).Select(m => m.Function.Id).ToArray();
            Guid[] addIds    = functionIds.Except(existIds).ToArray();
            Guid[] removeIds = existIds.Except(functionIds).ToArray();
            FunctionRoleMapRepository.UnitOfWork.TransactionEnabled = true;
            foreach (Guid addId in addIds)
            {
                Function function = await FunctionRepository.GetByKeyAsync(addId);

                if (function == null)
                {
                    return(new OperationResult(OperationResultType.QueryNull, "指定编号的功能信息不存在"));
                }
                FunctionRoleMap map = new FunctionRoleMap()
                {
                    Function = function, Role = role, BeginTime = DateTime.Now
                };
                await FunctionRoleMapRepository.InsertAsync(map);
            }
            await FunctionRoleMapRepository.DeleteAsync(m => m.Role.Id == roleId && removeIds.Contains(m.Function.Id));

            return(await FunctionRoleMapRepository.UnitOfWork.SaveChangesAsync() > 0
                ? new OperationResult(OperationResultType.Success, "角色“{0}”指派功能操作成功".FormatWith(role.Name))
                : OperationResult.NoChanged);
        }
Example #7
0
        /// <summary>
        /// 增加功能用户映射信息
        /// </summary>
        /// <param name="dto">功能用户映射信息DTO</param>
        /// <returns>业务操作结果</returns>
        public virtual async Task <OperationResult> CreateFunctionUserMapAsync(TFunctionUserMapInputDto dto)
        {
            dto.CheckNotNull("dto");
            if (await FunctionUserMapRepository.CheckExistsAsync(m => m.Function.Id.Equals(dto.FunctionId) && m.User.Id.Equals(dto.UserId)))
            {
                return(OperationResult.Success);
            }
            TFunction function = await FunctionRepository.GetByKeyAsync(dto.FunctionId);

            if (function == null)
            {
                return(new OperationResult(OperationResultType.QueryNull, "编号为“{0}”的功能信息不存在".FormatWith(dto.FunctionId)));
            }
            TUser user = await UserRepository.GetByKeyAsync(dto.UserId);

            if (user == null)
            {
                return(new OperationResult(OperationResultType.QueryNull, "编号为“{0}”的用户信息不存在".FormatWith(dto.UserId)));
            }
            TFunctionUserMap map = dto.MapTo <TFunctionUserMap>();

            map.Function = function;
            map.User     = user;
            await FunctionUserMapRepository.InsertAsync(map);

            return(new OperationResult(OperationResultType.Success, "功能用户映射信息添加成功"));
        }
Example #8
0
        /// <summary>
        /// 更新功能信息信息
        /// </summary>
        /// <param name="dto">包含更新信息的功能信息DTO信息</param>
        /// <returns>业务操作结果</returns>
        public virtual async Task <OperationResult> UpdateFunction(TFunctionInputDto dto)
        {
            if (await FunctionRepository.CheckExistsAsync(m => m.Name == dto.Name, dto.Id))
            {
                return(new OperationResult(OperationResultType.Error, "名称为“{0}”的功能信息已存在".FormatWith(dto.Name)));
            }
            TFunction entity = await FunctionRepository.GetByKeyAsync(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;
            }
            await FunctionRepository.UpdateAsync(entity);

            return(OperationResult.Success);
        }
        /// <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);
        }
        /// <summary>
        /// 更新功能信息信息
        /// </summary>
        /// <param name="dtos">包含更新信息的功能信息DTO信息</param>
        /// <returns>业务操作结果</returns>
        public async Task <OperationResult> UpdateFunctions(params FunctionInputDto[] dtos)
        {
            dtos.CheckNotNull(nameof(dtos));
            List <string> names = new List <string>();

            FunctionRepository.UnitOfWork.TransactionEnabled = true;
            foreach (FunctionInputDto dto in dtos)
            {
                if (await FunctionRepository.CheckExistsAsync(m => m.Name == dto.Name, dto.Id))
                {
                    return(new OperationResult(OperationResultType.Error, $"名称为“{dto.Name}”的功能信息已存在"));
                }
                Function entity = await FunctionRepository.GetByKeyAsync(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;
                }
                await FunctionRepository.UpdateAsync(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);
        }
Example #11
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);
        }