Example #1
0
        public async Task <bool> CheckCode(string Name, long Id)
        {
            int i = 0;

            //添加
            if (Id == 0)
            {
                i = await RoleRep.GetCountAsync(o => o.Name == Name);

                if (i > 0)
                {
                    return(true);
                }
                else
                {
                    return(false);
                }
            }
            //编辑
            i = await RoleRep.GetCountAsync(o => o.Name == Name && o.Id != Id);

            if (i > 0)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
Example #2
0
 public RoleMenuApp(IDbContext dbContext, IOperateLogApp operateLogApp) : base(dbContext)
 {
     context        = dbContext;
     _RoleMenuRep   = new RoleMenuRep(dbContext);
     _RoleRep       = new RoleRep(dbContext);
     _operateLogApp = operateLogApp;
     _cache         = CacheFactory.Cache();
 }
Example #3
0
 public async Task <IEnumerable <Role> > GetListAsync(RoleOption option)
 {
     if (!string.IsNullOrWhiteSpace(option.Name))
     {
         return(await RoleRep.Find(o => o.Name.Contains(option.Name)).ToListAsync());
     }
     else
     {
         return(await RoleRep.Find(null).ToListAsync());
     }
 }
Example #4
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="pageNumber"></param>
        /// <param name="rowsPrePage"></param>
        /// <param name="filter"></param>
        /// <returns></returns>
        public async Task <PageResult <UserSunpleDto> > GetPageAsync(int pageNumber, int rowsPrePage, UserOption filter)
        {
            List <UserSunpleDto>       data = new List <UserSunpleDto>();
            PageResult <UserSunpleDto> list = new PageResult <UserSunpleDto>();
            string orderby   = " id desc";
            var    predicate = PredicateBuilder.True <User>();

            predicate = predicate.And(o => o.DeleteMark == null);
            if (!string.IsNullOrWhiteSpace(filter.Account))
            {
                predicate = predicate.And(o => o.Account == filter.Account);
            }
            if (!string.IsNullOrWhiteSpace(filter.RealName))
            {
                predicate = predicate.And(o => o.RealName == filter.RealName);
            }
            var tlist = await UserRep.Find(pageNumber, rowsPrePage, orderby, predicate).ToListAsync() ?? new List <User>();

            data = MapperHelper.MapList <User, UserSunpleDto>(tlist);
            List <long> roleIds = tlist.Select(o => o.RoleId).Distinct().ToList();

            if (roleIds.Count() > 0)
            {
                var roles = await RoleRep.Find(o => roleIds.Contains(o.Id)).ToListAsync();

                foreach (var d in data)
                {
                    var r = roles.FirstOrDefault(o => o.Id == d.RoleId);
                    d.RoleName = r?.Name;
                }
            }
            List <long?> DepartmentIds = tlist.Select(o => o.DepartmentId).Distinct().ToList();

            DepartmentIds.Remove(null);
            if (DepartmentIds.Count() > 0)
            {
                var Departments = await DepartmentRep.Find(o => DepartmentIds.Contains(o.Id)).ToListAsync();

                foreach (var d in data)
                {
                    var r = Departments.FirstOrDefault(o => o.Id == d.DepartmentId);
                    d.deptname = r?.Name;
                }
            }
            list.Data = data.ToList();
            int total = await UserRep.GetCountAsync(predicate);

            list.ItemCount = total;
            return(list);
        }
Example #5
0
        /// <summary>
        /// 删除
        /// </summary>
        /// <param name="Id"></param>
        /// <returns></returns>
        public async Task <(bool s, string msg)> DeleteAsync(long Id, CurrentUser currentUser)
        {
            var entity = await RoleRep.FindSingleAsync(o => o.Id == Id);

            if (entity == null)
            {
                return(false, "数据不存在");
            }
            await RoleRep.DeleteAsync(o => o.Id == Id);

            if (currentUser != null)
            {
                await OperateLogApp.RemoveLogAsync <Role>(currentUser, "删除角色", entity);
            }
            await RemoveCacheAsync(Id);

            return(true, "操作成功");
        }
Example #6
0
        public async Task <PageResult <Role> > GetPageAsync(int pageNumber, int rowsPrePage, RoleOption filter)
        {
            List <Role>       data    = new List <Role>();
            PageResult <Role> list    = new PageResult <Role>();
            string            orderby = " id desc";
            var predicate             = PredicateBuilder.True <Role>();

            if (!string.IsNullOrWhiteSpace(filter.Name))
            {
                predicate = predicate.And(o => o.Name.Contains(filter.Name));
            }
            var tlist = await RoleRep.Find(pageNumber, rowsPrePage, orderby, predicate).ToListAsync();

            list.Data = tlist.ToList();
            int total = await RoleRep.GetCountAsync(predicate);

            list.ItemCount = total;
            return(list);
        }
Example #7
0
        public async Task <Role> GetAsync(long Id)
        {
            var r = await RoleRep.FindSingleAsync(o => o.Id == Id);

            return(r);
        }