示例#1
0
        public async Task <List <UserRole> > GetUserRoles(int userId, bool isAdmin)
        {
            var userRoleCache = new UserRoleCache(Cache);

            List <UserRole> cacheResult = await userRoleCache.GetUserRolesFromCache(userId, isAdmin);

            if (cacheResult != null)
            {
                return(cacheResult);
            }

            List <UserRole> roles;

            using (var uow = new UnitOfWork(Context))
            {
                var repo = new UserRoleRepository(uow);

                roles = await repo.GetAllWithRelated(isAdmin).Where(c => c.UserId == userId).ToListAsync();
            }

            if (roles != null)
            {
                await userRoleCache.AddUserRolesToCache(userId, roles, isAdmin);
            }

            return(roles);
        }
示例#2
0
        public async Task <UserRole> GetUserRole(int userRoleId, bool isAdmin)
        {
            UserRole userRole;

            using (var uow = new UnitOfWork(Context))
            {
                var repo = new UserRoleRepository(uow);

                userRole = await repo.GetAllWithRelated(isAdmin).Where(ur => ur.UserRoleId == userRoleId).FirstOrDefaultAsync();
            }

            return(userRole);
        }