Пример #1
0
        public static User ToUser(this dto.ApplicationUserExtended userDto)
        {
            var result = new User()
            {
                Email                = userDto.Email,
                Id                   = userDto.Id,
                ContactId            = userDto.MemberId,
                PhoneNumber          = userDto.PhoneNumber,
                UserName             = userDto.UserName,
                StoreId              = userDto.StoreId,
                IsRegisteredUser     = true,
                IsAdministrator      = userDto.IsAdministrator ?? false,
                Permissions          = userDto.Permissions,
                AccessFailedCount    = userDto.AccessFailedCount ?? 0,
                LockoutEnabled       = userDto.LockoutEnabled ?? false,
                EmailConfirmed       = userDto.EmailConfirmed ?? false,
                LockoutEndDateUtc    = userDto.LockoutEndDateUtc,
                PasswordHash         = userDto.PasswordHash,
                SecurityStamp        = userDto.SecurityStamp,
                UserState            = EnumUtility.SafeParse(userDto.UserState, AccountState.Approved),
                UserType             = userDto.UserType,
                TwoFactorEnabled     = userDto.TwoFactorEnabled ?? false,
                PhoneNumberConfirmed = userDto.PhoneNumberConfirmed ?? false,
            };

            if (!userDto.Roles.IsNullOrEmpty())
            {
                result.Roles = userDto.Roles.Select(x => new Role
                {
                    Id   = x.Id,
                    Name = x.Name
                });
            }

            if (!userDto.Logins.IsNullOrEmpty())
            {
                result.ExternalLogins = userDto.Logins.Select(x => new ExternalUserLoginInfo
                {
                    LoginProvider = x.LoginProvider,
                    ProviderKey   = x.ProviderKey
                }).ToList();
            }

            return(result);
        }
Пример #2
0
        public static dto.ApplicationUserExtended ToUserDto(this User user)
        {
            var result = new dto.ApplicationUserExtended
            {
                Id                   = user.Id,
                Email                = user.Email,
                Password             = user.Password,
                UserName             = user.UserName,
                StoreId              = user.StoreId,
                MemberId             = user.Contact?.Id ?? user.ContactId,
                AccessFailedCount    = user.AccessFailedCount,
                EmailConfirmed       = user.EmailConfirmed,
                LockoutEnabled       = user.LockoutEnabled,
                LockoutEndDateUtc    = user.LockoutEndDateUtc,
                TwoFactorEnabled     = user.TwoFactorEnabled,
                SecurityStamp        = user.SecurityStamp,
                PasswordHash         = user.PasswordHash,
                UserState            = user.UserState.ToString(),
                UserType             = user.UserType,
                IsAdministrator      = user.IsAdministrator,
                PhoneNumber          = user.PhoneNumber,
                PhoneNumberConfirmed = user.PhoneNumberConfirmed,
            };

            if (!user.Roles.IsNullOrEmpty())
            {
                //Need to convert role names to the registered in the platform roles entities
                result.Roles = user.Roles.Select(ToRoleDto).ToList();
            }
            if (!user.ExternalLogins.IsNullOrEmpty())
            {
                result.Logins = user.ExternalLogins.Select(x => new dto.ApplicationUserLogin
                {
                    LoginProvider = x.LoginProvider,
                    ProviderKey   = x.ProviderKey
                }).ToList();
            }
            return(result);
        }