예제 #1
0
        public static async void Run(IServiceProvider serviceProvider)
        {
            var context     = serviceProvider.GetService(typeof(CoinSaverContext)) as CoinSaverContext;
            var userManager = serviceProvider.GetService(typeof(UserManager <CSUser>)) as UserManager <CSUser>;

            CSRole[] roles = new CSRole[] {
                new CSRole {
                    Name = "User", Description = "Обычный пользователь", NormalizedName = "USER"
                },
                new CSRole {
                    Name = "Administrator", Description = "Администратор", NormalizedName = "ADMINISTRATOR"
                }
            };

            foreach (var role in roles)
            {
                var roleStore = new RoleStore <CSRole>(context);

                if (!context.Roles.Any(r => r.NormalizedName == role.NormalizedName))
                {
                    await roleStore.CreateAsync(role);
                }
            }
            foreach (var user in userManager.Users)
            {
                if (!userManager.IsInRoleAsync(user, roles[0].Name).Result)
                {
                    await userManager.AddToRoleAsync(user, roles[0].Name);
                }
            }
        }
예제 #2
0
        private void Role_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            if (null != Role.SelectedValue && !string.IsNullOrEmpty(Role.SelectedValue.ToString()))
            {
                CSRole role = (CSRole)Enum.Parse(typeof(CSRole), this.Role.SelectedValue.ToString(), true);
                switch (role)
                {
                case CSRole.CS:
                    textBlock3.Visibility = System.Windows.Visibility.Collapsed;
                    textBlock4.Visibility = System.Windows.Visibility.Collapsed;
                    cmbManager.Visibility = System.Windows.Visibility.Collapsed;
                    textBlock5.Visibility = System.Windows.Visibility.Visible;
                    cmbLeader.Visibility  = System.Windows.Visibility.Visible;
                    Underlings.Visibility = System.Windows.Visibility.Collapsed;
                    break;

                case CSRole.Leader:
                    textBlock3.Visibility = System.Windows.Visibility.Visible;
                    textBlock4.Visibility = System.Windows.Visibility.Visible;
                    cmbManager.Visibility = System.Windows.Visibility.Visible;
                    textBlock5.Visibility = System.Windows.Visibility.Collapsed;
                    cmbLeader.Visibility  = System.Windows.Visibility.Collapsed;
                    Underlings.Visibility = System.Windows.Visibility.Visible;
                    SetUnderlings();
                    break;

                case CSRole.Manager:
                    textBlock3.Visibility = System.Windows.Visibility.Collapsed;
                    textBlock4.Visibility = System.Windows.Visibility.Collapsed;
                    cmbManager.Visibility = System.Windows.Visibility.Collapsed;
                    textBlock5.Visibility = System.Windows.Visibility.Collapsed;
                    cmbLeader.Visibility  = System.Windows.Visibility.Collapsed;
                    Underlings.Visibility = System.Windows.Visibility.Collapsed;
                    break;
                }
            }
        }