Example #1
0
        public async Task <DataHolder <string> > GetUserId(string identityName)
        {
            if (identityName == null)
            {
                throw new ArgumentNullException(nameof(identityName));
            }

            var userId = await _userManager
                         .Users
                         .Where(user => user.UserName == identityName || user.Email == identityName)
                         .Select(user => user.Id)
                         .FirstOrDefaultAsync();

            if (userId == Guid.Empty)
            {
                return(DataHolder <string> .CreateUnauthorized());
            }

            return(DataHolder <string> .CreateSuccess(userId.ToString()));
        }
Example #2
0
        public async Task <DataHolder <User> > GetFromIdentityAsync(string identityName)
        {
            if (identityName == null)
            {
                throw new ArgumentNullException(nameof(identityName));
            }

            var userData = await _userManager
                           .Users
                           .FirstOrDefaultAsync(user => user.UserName == identityName ||
                                                user.Email == identityName ||
                                                user.PhoneNumber == identityName);

            if (userData == null)
            {
                return(DataHolder <User> .CreateUnauthorized());
            }

            return(DataHolder <User> .CreateSuccess(userData));
        }