示例#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... */
            }
        }
示例#2
0
        private void CreateRules()
        {
            _context.Rules.AddRange(
                new Rule {
                Name = "Fishing Equipment", URL = "https://www.qld.gov.au/recreation/activities/boating-fishing/rec-fishing/rules/equipment", Description = "Fishing Equipment", TimeStamp = DateTime.Now
            },
                new Rule {
                Name = "Catch Limits & Closures", URL = "https://www.qld.gov.au/recreation/activities/boating-fishing/rec-fishing/rules/closures", Description = "Catch Limits & Closures", TimeStamp = DateTime.Now
            },
                new Rule
            {
                Name        = "Size & Possession Limits(Tidal Waters)",
                URL         = "https://www.qld.gov.au/recreation/activities/boating-fishing/rec-fishing/rules/limits-tidal",
                Description = "Size & Possession Limits(Tidal Waters)",
                TimeStamp   = DateTime.Now
            },

                new Rule
            {
                Name        = "Size & Possession Limits (Fresh Waters)",
                URL         = "https://www.daf.qld.gov.au/business-priorities/fisheries/species-identification/freshwater-fish/bloomfield-river-cod",
                Description = "Size & Possession Limits (Fresh Waters)",
                TimeStamp   = DateTime.Now
            }
                );
            _context.SaveChanges();
        }
示例#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();
        }
        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();
        }
示例#5
0
        public void Create()
        {
            new DefaultEditionCreator(_context).Create();
            new DefaultLanguagesCreator(_context).Create();
            new HostRoleAndUserCreator(_context).Create();
            new DefaultSettingsCreator(_context).Create();
            new DefaultSpicesCreator(_context).Create();
            new DefaultRulesCreator(_context).Create();

            _context.SaveChanges();
        }
示例#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();
            }
        }
示例#7
0
 private void CreateSpecies()
 {
     _context.Species.AddRange(
         new Species {
         Name = "Australian bass", URL = "https://www.daf.qld.gov.au/business-priorities/fisheries/species-identification/inshore-estuarine-species/australian-bass", Description = "Australian bass", TimeStamp = DateTime.Now
     },
         new Species {
         Name = "Barcoo grunter", URL = "https://www.daf.qld.gov.au/business-priorities/fisheries/species-identification/freshwater-fish/barcoo-grunter", Description = "Barcoo grunter", TimeStamp = DateTime.Now
     },
         new Species {
         Name = "Barramundi", URL = "https://www.daf.qld.gov.au/business-priorities/fisheries/species-identification/inshore-estuarine-species/barramundi", Description = "Barramundi", TimeStamp = DateTime.Now
     },
         new Species {
         Name = "Bloomfield river cod", URL = "https://www.daf.qld.gov.au/business-priorities/fisheries/species-identification/freshwater-fish/bloomfield-river-cod", Description = "Bloomfield river cod", TimeStamp = DateTime.Now
     },
         new Species
     {
         Name        = "Freshwater catfish(eel tailed catfish)",
         URL         = "https://www.daf.qld.gov.au/business-priorities/fisheries/species-identification/freshwater-fish/freshwater-catfish-eel-tailed-catfish",
         Description = "Freshwater catfish(eel tailed catfish)",
         TimeStamp   = DateTime.Now
     },
         new Species {
         Name = "Freshwater sawfish", URL = "https://www.daf.qld.gov.au/business-priorities/fisheries/species-identification/shark-identification-guide/photo-guide-to-sharks/sharks,-part-3/freshwater-sawfish", Description = "Freshwater sawfish", TimeStamp = DateTime.Now
     },
         new Species {
         Name = "Golden perch(yellowbelly)", URL = "https://www.daf.qld.gov.au/business-priorities/fisheries/species-identification/freshwater-fish/golden-perch-yellowbelly", Description = "Golden perch(yellowbelly)", TimeStamp = DateTime.Now
     },
         new Species {
         Name = "Jungle perch", URL = "https://www.daf.qld.gov.au/business-priorities/fisheries/species-identification/freshwater-fish/jungle-perch", Description = "Jungle perch", TimeStamp = DateTime.Now
     },
         new Species {
         Name = "Khaki grunter", URL = "https://www.daf.qld.gov.au/business-priorities/fisheries/species-identification/freshwater-fish/khaki-grunter", Description = "Khaki grunter", TimeStamp = DateTime.Now
     },
         new Species {
         Name = "Longfin eel", URL = "https://www.daf.qld.gov.au/business-priorities/fisheries/species-identification/freshwater-fish/longfin-eel", Description = "Longfin eel", TimeStamp = DateTime.Now
     }
         );
     _context.SaveChanges();
 }
示例#8
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 DLQAuthorizationProvider())
                              .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();
            }
        }
        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 DLQAuthorizationProvider())
                              .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();
            }
        }