Exemplo n.º 1
0
        private async Task LoadAsync(UpravuvanjeUser user)
        {
            var userName = await _userManager.GetUserNameAsync(user);

            var phoneNumber = await _userManager.GetPhoneNumberAsync(user);

            Username = userName;

            Input = new InputModel
            {
                PhoneNumber = phoneNumber
            };
        }
Exemplo n.º 2
0
        public static async Task CreateUserRoles(IServiceProvider serviceProvider)
        {
            var            RoleManager = serviceProvider.GetRequiredService <RoleManager <IdentityRole> >();
            var            UserManager = serviceProvider.GetRequiredService <UserManager <UpravuvanjeUser> >();
            IdentityResult roleResult;

            //Add Admin Role
            var roleCheck = await RoleManager.RoleExistsAsync("Admin");

            if (!roleCheck)
            {
                roleResult = await RoleManager.CreateAsync(new IdentityRole("Admin"));
            }

            //Add Admin User
            UpravuvanjeUser user = await UserManager.FindByEmailAsync("*****@*****.**");

            if (user == null)
            {
                var User = new UpravuvanjeUser();
                User.Email    = "*****@*****.**";
                User.UserName = "******";
                string         userPWD = "Admin123";
                IdentityResult chkUser = await UserManager.CreateAsync(User, userPWD);

                //Add default User to Role Admin
                if (chkUser.Succeeded)
                {
                    var result1 = await UserManager.AddToRoleAsync(User, "Admin");
                }
            }

            //Add Teacher Role
            roleCheck = await RoleManager.RoleExistsAsync("Teacher");

            if (!roleCheck)
            {
                roleResult = await RoleManager.CreateAsync(new IdentityRole("Teacher"));
            }

            user = await UserManager.FindByEmailAsync("*****@*****.**");

            if (user == null)
            {
                var User = new UpravuvanjeUser();
                User.Email     = "*****@*****.**";
                User.UserName  = "******";
                User.TeacherId = 1;
                string         userPWD = "Profesor123";
                IdentityResult chkUser = await UserManager.CreateAsync(User, userPWD);

                if (chkUser.Succeeded)
                {
                    var result1 = await UserManager.AddToRoleAsync(User, "Teacher");
                }
            }

            //Add Student Role
            roleCheck = await RoleManager.RoleExistsAsync("Student");

            if (!roleCheck)
            {
                roleResult = await RoleManager.CreateAsync(new IdentityRole("Student"));
            }

            user = await UserManager.FindByEmailAsync("*****@*****.**");

            if (user == null)
            {
                var User = new UpravuvanjeUser();
                User.Email     = "*****@*****.**";
                User.UserName  = "******";
                User.StudentId = 2;
                string         userPWD = "Student123";
                IdentityResult chkUser = await UserManager.CreateAsync(User, userPWD);

                if (chkUser.Succeeded)
                {
                    var result1 = await UserManager.AddToRoleAsync(User, "Student");
                }
            }
        }