Exemple #1
0
        private void CreateDefaultUser()
        {
            var email = _configuration["DefaultUserEmail"];

            using (var transaction = _dbContext.Database.BeginTransaction()) {
                try {
                    if (_accountManager.CreateUser(email) &&
                        _accountManager.CreateDefaultRoles() &&
                        _accountManager.SetUserRole(
                            email,
                            new SingleAccountEdit()
                    {
                        Permission = YearApPermissionLevels.Admin,
                        VersionStamp = _accountManager.GetAccountInfoByEmail(email).LastUpdate
                    }))
                    {
                        transaction.Commit();
                        _emailService.SendMessage(email,
                                                  _configuration["WelcomeEmail:Subject"],
                                                  _configuration["WelcomeEmail:Text"]);
                    }
                    else
                    {
                        transaction.Rollback();
                    }
                }catch (Exception e) {
                    Console.WriteLine(e.Message);
                    transaction.Rollback();
                }
            }
        }