コード例 #1
0
        public async Task <IActionResult> SyncUsers()
        {
            var errorList = new List <string>();

            try
            {
                if (_db.Connection.State == System.Data.ConnectionState.Closed)
                {
                    await _db.Connection.OpenAsync();
                }

                var query = new UserQueries(_db);
                var users = await query.GetAllUsers();

                foreach (var user in users)
                {
                    var givenName = string.IsNullOrWhiteSpace(user.first_name + " " + user.last_name) ? user.user_login : user.first_name + " " + user.last_name;
                    if (await _userManager.FindByEmailAsync(user.user_email) == null)
                    {
                        var u = new ApplicationUser
                        {
                            UserName       = user.user_login,
                            Email          = user.user_email,
                            EmailConfirmed = true,
                            GivenName      = givenName
                        };

                        await _userManager.CreateAsync(u, "P2ssw0rd!");
                    }
                }
                _db.Connection.Close();
            }
            catch (Exception ex)
            {
                errorList.Add("order taxes:" + ex.ToString());
            }

            return(Ok(errorList));
        }