public IActionResult Create(CreateAccountViewModel viewModel)
        {
            // If basic syntax check returns false return to view with proper messages
            // defined in view model annotations.
            if (!ModelState.IsValid)
            {
                return(View());
            }

            Profile addedProfile = UserAccountServiceLogic.CreateProfile(viewModel);
            User    addedUser    = addedUser = UserAccountServiceLogic.CreateUser(viewModel, addedProfile);

            addedProfile.User = addedUser;

            if (UserAccountServiceLogic.AddUserAndDependenciesToDB(addedUser, userManager, viewModel, context).Result)
            {
                ViewBag.Message = localizer["CreateSuccess"];
                return(RedirectToAction("Login"));
            }
            else
            {
                ViewBag.Message = localizer["CreateFail"];
                return(View());
            }
        }
Exemple #2
0
        /// <summary>
        /// Populates database with test users and their profiles.
        /// </summary>
        /// <param name="userManager"></param>
        /// <param name="context"></param>
        public static void CreateTestUsers(UserManager <User> userManager, AppDbContext context)
        {
            List <CreateAccountViewModel> usersData = new List <CreateAccountViewModel>
            {
                new CreateAccountViewModel
                {
                    BirthDate    = new DateTime(1990, 1, 1),
                    EmailAddress = "*****@*****.**",
                    FirstName    = "Jan",
                    LastName     = "Kowalski",
                    Password     = "******"
                },
                new CreateAccountViewModel
                {
                    BirthDate    = new DateTime(1980, 5, 5),
                    EmailAddress = "*****@*****.**",
                    FirstName    = "Preston",
                    LastName     = "Davis",
                    Password     = "******"
                },
                new CreateAccountViewModel
                {
                    BirthDate    = new DateTime(1970, 8, 15),
                    EmailAddress = "*****@*****.**",
                    FirstName    = "Andrew",
                    LastName     = "Walles",
                    Password     = "******"
                },
                new CreateAccountViewModel
                {
                    BirthDate    = new DateTime(1992, 12, 1),
                    EmailAddress = "*****@*****.**",
                    FirstName    = "Brian",
                    LastName     = "May",
                    Password     = "******"
                },
                new CreateAccountViewModel
                {
                    BirthDate    = new DateTime(1982, 4, 30),
                    EmailAddress = "*****@*****.**",
                    FirstName    = "Jack",
                    LastName     = "Tasack",
                    Password     = "******"
                },
                new CreateAccountViewModel
                {
                    BirthDate    = new DateTime(1962, 3, 18),
                    EmailAddress = "*****@*****.**",
                    FirstName    = "James",
                    LastName     = "May",
                    Password     = "******"
                },
                new CreateAccountViewModel
                {
                    BirthDate    = new DateTime(1978, 6, 5),
                    EmailAddress = "*****@*****.**",
                    FirstName    = "Jim",
                    LastName     = "Raynor",
                    Password     = "******"
                },
                new CreateAccountViewModel
                {
                    BirthDate    = new DateTime(1984, 8, 12),
                    EmailAddress = "*****@*****.**",
                    FirstName    = "Sarah",
                    LastName     = "Kerrigan",
                    Password     = "******"
                },
                new CreateAccountViewModel
                {
                    BirthDate    = new DateTime(1976, 12, 1),
                    EmailAddress = "*****@*****.**",
                    FirstName    = "Varian",
                    LastName     = "Vrynn",
                    Password     = "******"
                },
                new CreateAccountViewModel
                {
                    BirthDate    = new DateTime(1984, 11, 5),
                    EmailAddress = "*****@*****.**",
                    FirstName    = "Jaina",
                    LastName     = "Proudmore",
                    Password     = "******"
                },
                new CreateAccountViewModel
                {
                    BirthDate    = new DateTime(1966, 8, 30),
                    EmailAddress = "*****@*****.**",
                    FirstName    = "Arthas",
                    LastName     = "Menethil",
                    Password     = "******"
                },
                new CreateAccountViewModel
                {
                    BirthDate    = new DateTime(1901, 2, 22),
                    EmailAddress = "*****@*****.**",
                    FirstName    = "Machete",
                    LastName     = "Cortez",
                    Password     = "******"
                },
                new CreateAccountViewModel
                {
                    BirthDate    = new DateTime(1960, 5, 23),
                    EmailAddress = "*****@*****.**",
                    FirstName    = "Peter",
                    LastName     = "Griffin",
                    Password     = "******"
                },
                new CreateAccountViewModel
                {
                    BirthDate    = new DateTime(1967, 8, 13),
                    EmailAddress = "*****@*****.**",
                    FirstName    = "Derwan",
                    LastName     = "Gościwuj",
                    Password     = "******"
                },
            };

            List <Profile> profiles = new List <Profile>();

            foreach (CreateAccountViewModel user in usersData)
            {
                profiles.Add(UserAccountServiceLogic.CreateProfile(user));
            }

            List <User> users = new List <User>();
            int         i     = 0;

            foreach (CreateAccountViewModel userData in usersData)
            {
                users.Add(UserAccountServiceLogic.CreateUser(userData, profiles[i]));
                i++;
            }
            i = 0;

            foreach (User user in users)
            {
                UserAccountServiceLogic.AddUserAndDependenciesToDB(user, userManager, usersData[i], context).Wait();
                i++;
            }
        }