Ejemplo n.º 1
0
        private void CreateEditions()
        {
            var defaultEdition = _context.Editions.IgnoreQueryFilters().FirstOrDefault(e => e.Name == EditionManager.DefaultEditionName);

            if (defaultEdition == null)
            {
                defaultEdition = new Edition {
                    Name = EditionManager.DefaultEditionName, DisplayName = EditionManager.DefaultEditionName
                };
                _context.Editions.Add(defaultEdition);
                _context.SaveChanges();

                /* Add desired features to the standard edition, if wanted... */
            }
        }
        public void Create()
        {
            new DefaultEditionCreator(_context).Create();
            new DefaultLanguagesCreator(_context).Create();
            new HostRoleAndUserCreator(_context).Create();
            new DefaultSettingsCreator(_context).Create();

            _context.SaveChanges();
        }
Ejemplo n.º 3
0
        private void AddSettingIfNotExists(string name, string value, int?tenantId = null)
        {
            if (_context.Settings.IgnoreQueryFilters().Any(s => s.Name == name && s.TenantId == tenantId && s.UserId == null))
            {
                return;
            }

            _context.Settings.Add(new Setting(tenantId, null, name, value));
            _context.SaveChanges();
        }
Ejemplo n.º 4
0
        private void AddLanguageIfNotExists(ApplicationLanguage language)
        {
            if (_context.Languages.IgnoreQueryFilters().Any(l => l.TenantId == language.TenantId && l.Name == language.Name))
            {
                return;
            }

            _context.Languages.Add(language);
            _context.SaveChanges();
        }
Ejemplo n.º 5
0
 public void SetBookmarkState(int jobPostId, bool isBookmarked)
 {
     using (var dbContext = new JobPortalDbContext())
     {
         var jobPost = new JobPost
         {
             Id           = jobPostId,
             IsBookmarked = isBookmarked
         };
         dbContext.JobPosts.Attach(jobPost);
         dbContext.Entry <JobPost>(jobPost).Property(jp => jp.IsBookmarked).IsModified = true;
         dbContext.SaveChanges();
     }
 }
Ejemplo n.º 6
0
        private void CreateDefaultTenant()
        {
            // Default tenant

            var defaultTenant = _context.Tenants.IgnoreQueryFilters().FirstOrDefault(t => t.TenancyName == AbpTenantBase.DefaultTenantName);

            if (defaultTenant == null)
            {
                defaultTenant = new Tenant(AbpTenantBase.DefaultTenantName, AbpTenantBase.DefaultTenantName);

                var defaultEdition = _context.Editions.IgnoreQueryFilters().FirstOrDefault(e => e.Name == EditionManager.DefaultEditionName);
                if (defaultEdition != null)
                {
                    defaultTenant.EditionId = defaultEdition.Id;
                }

                _context.Tenants.Add(defaultTenant);
                _context.SaveChanges();
            }
        }
Ejemplo n.º 7
0
        private void CreateRolesAndUsers()
        {
            // Admin role

            var adminRole = _context.Roles.IgnoreQueryFilters().FirstOrDefault(r => r.TenantId == _tenantId && r.Name == StaticRoleNames.Tenants.Admin);

            if (adminRole == null)
            {
                adminRole = _context.Roles.Add(new Role(_tenantId, StaticRoleNames.Tenants.Admin, StaticRoleNames.Tenants.Admin)
                {
                    IsStatic = true
                }).Entity;
                _context.SaveChanges();
            }

            // Grant all permissions to admin role

            var grantedPermissions = _context.Permissions.IgnoreQueryFilters()
                                     .OfType <RolePermissionSetting>()
                                     .Where(p => p.TenantId == _tenantId && p.RoleId == adminRole.Id)
                                     .Select(p => p.Name)
                                     .ToList();

            var permissions = PermissionFinder
                              .GetAllPermissions(new JobPortalAuthorizationProvider())
                              .Where(p => p.MultiTenancySides.HasFlag(MultiTenancySides.Tenant) &&
                                     !grantedPermissions.Contains(p.Name))
                              .ToList();

            if (permissions.Any())
            {
                _context.Permissions.AddRange(
                    permissions.Select(permission => new RolePermissionSetting
                {
                    TenantId  = _tenantId,
                    Name      = permission.Name,
                    IsGranted = true,
                    RoleId    = adminRole.Id
                })
                    );
                _context.SaveChanges();
            }

            // Admin user

            var adminUser = _context.Users.IgnoreQueryFilters().FirstOrDefault(u => u.TenantId == _tenantId && u.UserName == AbpUserBase.AdminUserName);

            if (adminUser == null)
            {
                adminUser                  = User.CreateTenantAdminUser(_tenantId, "*****@*****.**");
                adminUser.Password         = new PasswordHasher <User>(new OptionsWrapper <PasswordHasherOptions>(new PasswordHasherOptions())).HashPassword(adminUser, "123qwe");
                adminUser.IsEmailConfirmed = true;
                adminUser.IsActive         = true;

                _context.Users.Add(adminUser);
                _context.SaveChanges();

                // Assign Admin role to admin user
                _context.UserRoles.Add(new UserRole(_tenantId, adminUser.Id, adminRole.Id));
                _context.SaveChanges();
            }
        }
Ejemplo n.º 8
0
        private static DbContext InitializeDatabase()
        {
            var context = new JobPortalDbContext(Effort.DbConnectionFactory.CreatePersistent(TestDbConnectionString));

            context.Employers.RemoveRange(context.Employers);
            context.Users.RemoveRange(context.Users);
            context.Applicants.RemoveRange(context.Applicants);
            context.JobOffers.RemoveRange(context.JobOffers);
            context.JobApplications.RemoveRange(context.JobApplications);
            context.Questions.RemoveRange(context.Questions);
            context.QuestionAnswers.RemoveRange(context.QuestionAnswers);
            context.SkillTags.RemoveRange(context.SkillTags);

            context.SaveChanges();

            #region employers

            RedHatEmployer = new Employer
            {
                Name         = "RedHat",
                Address      = "Brno, CzechRepublic",
                Email        = "*****@*****.**",
                PhoneNumber  = "+420 123 456 789",
                PasswordHash = "password",
                PasswordSalt = "password"
            };
            GoogleEmployer = new Employer
            {
                Name         = "Google",
                Address      = "MountainView, CA",
                Email        = "*****@*****.**",
                PhoneNumber  = "+421 123 456 789",
                PasswordHash = "password",
                PasswordSalt = "password"
            };

            MicrosoftEmployer = new Employer
            {
                Name         = "Microsoft",
                Address      = "Praha, CZ",
                Email        = "*****@*****.**",
                PhoneNumber  = "(425) 882-8080",
                PasswordHash = "password",
                PasswordSalt = "password"
            };

            context.Employers.Add(RedHatEmployer);
            context.Employers.Add(GoogleEmployer);
            context.Employers.Add(MicrosoftEmployer);

            #endregion

            #region skills

            CSharpSkill = new SkillTag {
                Name = "C#"
            };
            JavaSkill = new SkillTag {
                Name = "Java"
            };
            PhpSkill = new SkillTag {
                Name = "Php"
            };
            AngularSkill = new SkillTag {
                Name = "Angular"
            };
            AndroidSkill = new SkillTag {
                Name = "Android"
            };

            context.SkillTags.Add(CSharpSkill);
            context.SkillTags.Add(JavaSkill);
            context.SkillTags.Add(PhpSkill);
            context.SkillTags.Add(AngularSkill);
            context.SkillTags.Add(AndroidSkill);

            #endregion

            #region users

            PiskulaUser = new User
            {
                FirstName   = "Piskula",
                LastName    = "Zeleny",
                Email       = "*****@*****.**",
                PhoneNumber = "+420 123 456 789",
                Education   = "High School of Live",
                Skills      = new List <SkillTag>
                {
                    JavaSkill,
                    PhpSkill,
                    AngularSkill
                },
                PasswordHash = "password",
                PasswordSalt = "password"
            };

            MadkiUser = new User
            {
                FirstName   = "Madki",
                LastName    = "Programmer",
                Email       = "*****@*****.**",
                PhoneNumber = "+421 999 666 789",
                Education   = "Programming High",
                Skills      = new List <SkillTag>
                {
                    JavaSkill,
                    CSharpSkill,
                    AndroidSkill
                },
                PasswordHash = "password",
                PasswordSalt = "password"
            };

            AnonymousUser = new Applicant()
            {
                FirstName   = "Anonymous",
                LastName    = "Inkognito",
                Email       = "*****@*****.**",
                PhoneNumber = "+420 5565893",
                Education   = "Secret"
            };

            context.Applicants.Add(PiskulaUser);
            context.Applicants.Add(MadkiUser);
            context.Applicants.Add(AnonymousUser);

            #endregion

            #region questions

            JavaExperienceQuestion = new Question {
                Text = "What is your exeperience with Java programming?"
            };
            JavaEeExperienceQuestion = new Question {
                Text = "What is your exeperience with Java EE programming?"
            };
            CSharpExperienceQuestion = new Question {
                Text = "What is your exeperience with .Net programming?"
            };
            WebEprienceQuestion = new Question {
                Text = "What is your exeperience with web application programming?"
            };
            AndroidExperienceQuestion = new Question {
                Text = "What is your exeperience with Android programming?"
            };
            SoftSkillQuestion = new Question {
                Text = "Tell us about your soft skills"
            };
            HobbyQuesiton = new Question {
                Text = "What is your hobby?"
            };

            context.Questions.Add(JavaExperienceQuestion);
            context.Questions.Add(JavaEeExperienceQuestion);
            context.Questions.Add(CSharpExperienceQuestion);
            context.Questions.Add(WebEprienceQuestion);
            context.Questions.Add(AndroidExperienceQuestion);
            context.Questions.Add(SoftSkillQuestion);
            context.Questions.Add(HobbyQuesiton);

            #endregion

            #region job offers

            GoogleAndroidOffer = new JobOffer
            {
                Name        = "Associate Android Developer",
                Employer    = GoogleEmployer,
                Location    = "Paris, FR",
                Description = "Develop apps for Android - it will be fun!",
                Skills      = new List <SkillTag>
                {
                    JavaSkill,
                    AndroidSkill
                },
                Questions = new List <Question>
                {
                    SoftSkillQuestion,
                    JavaExperienceQuestion,
                    AndroidExperienceQuestion
                }
            };


            MicrosoftCSharpOffer = new JobOffer
            {
                Name        = "C# dev",
                Employer    = MicrosoftEmployer,
                Location    = "Seattle, WS",
                Description = "Lets see sharp!",
                Skills      = new List <SkillTag>
                {
                    CSharpSkill
                },
                Questions = new List <Question>
                {
                    CSharpExperienceQuestion
                }
            };

            MicrosoftManagerOffer = new JobOffer
            {
                Name        = "Project manager junior",
                Employer    = MicrosoftEmployer,
                Location    = "Seattle 2, WS",
                Description = "Manage amazing projects",
                Skills      = new List <SkillTag>
                {
                    CSharpSkill
                },
                Questions = new List <Question>
                {
                    SoftSkillQuestion,
                    HobbyQuesiton
                }
            };

            RedHatQualityOffer = new JobOffer
            {
                Name        = "Quality engineer",
                Employer    = RedHatEmployer,
                Location    = "Brno, CZ",
                Description = "Quality matters",
                Skills      = new List <SkillTag>
                {
                    JavaSkill
                },
                Questions = new List <Question>
                {
                    SoftSkillQuestion,
                    JavaExperienceQuestion,
                    JavaEeExperienceQuestion
                }
            };

            context.JobOffers.Add(GoogleAndroidOffer);
            context.JobOffers.Add(MicrosoftCSharpOffer);
            context.JobOffers.Add(MicrosoftManagerOffer);
            context.JobOffers.Add(RedHatQualityOffer);

            #endregion

            #region applications

            ApplicationRedHatQuality = new JobApplication
            {
                Applicant            = MadkiUser,
                JobOffer             = RedHatQualityOffer,
                JobApplicationStatus = JobApplicationStatus.Open
            };

            AnswersoftSkillsRedHat = new QuestionAnswer
            {
                Text        = "Great",
                Application = ApplicationRedHatQuality,
                Question    = SoftSkillQuestion
            };

            ÀnswersJavaRedHat = new QuestionAnswer
            {
                Text        = "Very Good",
                Application = ApplicationRedHatQuality,
                Question    = JavaExperienceQuestion
            };

            AnswerJavaEeRedHat = new QuestionAnswer
            {
                Text        = "Basic",
                Application = ApplicationRedHatQuality,
                Question    = JavaEeExperienceQuestion
            };

            ApplicationRedHatQuality.QuestionAnswers = new List <QuestionAnswer>
            {
                AnswersoftSkillsRedHat,
                ÀnswersJavaRedHat,
                AnswerJavaEeRedHat
            };


            context.QuestionAnswers.Add(AnswersoftSkillsRedHat);
            context.QuestionAnswers.Add(AnswerJavaEeRedHat);
            context.QuestionAnswers.Add(ÀnswersJavaRedHat);
            context.JobApplications.Add(ApplicationRedHatQuality);

            #endregion

            context.SaveChanges();

            return(context);
        }
Ejemplo n.º 9
0
        private void CreateHostRoleAndUsers()
        {
            // Admin role for host

            var adminRoleForHost = _context.Roles.IgnoreQueryFilters().FirstOrDefault(r => r.TenantId == null && r.Name == StaticRoleNames.Host.Admin);

            if (adminRoleForHost == null)
            {
                adminRoleForHost = _context.Roles.Add(new Role(null, StaticRoleNames.Host.Admin, StaticRoleNames.Host.Admin)
                {
                    IsStatic = true, IsDefault = true
                }).Entity;
                _context.SaveChanges();
            }

            // Grant all permissions to admin role for host

            var grantedPermissions = _context.Permissions.IgnoreQueryFilters()
                                     .OfType <RolePermissionSetting>()
                                     .Where(p => p.TenantId == null && p.RoleId == adminRoleForHost.Id)
                                     .Select(p => p.Name)
                                     .ToList();

            var permissions = PermissionFinder
                              .GetAllPermissions(new JobPortalAuthorizationProvider())
                              .Where(p => p.MultiTenancySides.HasFlag(MultiTenancySides.Host) &&
                                     !grantedPermissions.Contains(p.Name))
                              .ToList();

            if (permissions.Any())
            {
                _context.Permissions.AddRange(
                    permissions.Select(permission => new RolePermissionSetting
                {
                    TenantId  = null,
                    Name      = permission.Name,
                    IsGranted = true,
                    RoleId    = adminRoleForHost.Id
                })
                    );
                _context.SaveChanges();
            }

            // Admin user for host

            var adminUserForHost = _context.Users.IgnoreQueryFilters().FirstOrDefault(u => u.TenantId == null && u.UserName == AbpUserBase.AdminUserName);

            if (adminUserForHost == null)
            {
                var user = new User
                {
                    TenantId         = null,
                    UserName         = AbpUserBase.AdminUserName,
                    Name             = "admin",
                    Surname          = "admin",
                    EmailAddress     = "*****@*****.**",
                    IsEmailConfirmed = true,
                    IsActive         = true
                };

                user.Password = new PasswordHasher <User>(new OptionsWrapper <PasswordHasherOptions>(new PasswordHasherOptions())).HashPassword(user, "123qwe");
                user.SetNormalizedNames();

                adminUserForHost = _context.Users.Add(user).Entity;
                _context.SaveChanges();

                // Assign Admin role to admin user
                _context.UserRoles.Add(new UserRole(null, adminUserForHost.Id, adminRoleForHost.Id));
                _context.SaveChanges();

                _context.SaveChanges();
            }
        }