Esempio n. 1
0
        public async Task <PagedQuery <UserDTO> > SearchUser(SearchDTO search)
        {
            var query = from obj in Users
                        .Include(o => o.UserRoles)
                        .ThenInclude(o => o.Role)
                        .Include(o => o.Claims)
                        select obj;

            if (!string.IsNullOrWhiteSpace(search.Search))
            {
                var _s = search.Search;
                query = from obj in query
                        where obj.Email.Contains(_s) || obj.Claims.Any(claim => claim.ClaimValue.Contains(_s)) || obj.UserRoles.Any(s => s.Role.Name.Contains(_s))
                        select obj;
            }

            int total = query.Count();
            var users = await query.Skip(search.Start).Take(search.Count).ToArrayAsync();

            var result = new PagedQuery <UserDTO>
            {
                Start  = search.Start,
                Count  = search.Count,
                Total  = total,
                Items  = users.Select(i => i.ToDTO()),
                Search = search.Search
            };

            return(result);
        }
Esempio n. 2
0
        public async Task <UserDTO> FindUserByEmail(string email)
        {
            var query = from obj in Users
                        .Include(o => o.UserRoles)
                        .ThenInclude(o => o.Role)
                        .Include(o => o.Claims)
                        where obj.Email == email
                        select obj;

            var user = await query.FirstOrDefaultAsync();

            return(user.ToDTO());
        }
Esempio n. 3
0
        public async Task <UserDTO> FindUserBySubjectId(string subjectId)
        {
            var query = from obj in Users
                        .Include(o => o.UserRoles)
                        .ThenInclude(o => o.Role)
                        .Include(o => o.Claims)
                        where obj.Id.ToString() == subjectId
                        select obj;

            var user = await query.FirstOrDefaultAsync();

            return(user.ToDTO());
        }