Пример #1
0
        public void Create()
        {
            var douglas = _context.People.FirstOrDefault(p => p.Name == "Douglas");

            if (douglas == null)
            {
                _context.People.Add(
                    new Person
                {
                    Name             = "Douglas",
                    Gender           = Gender.F,
                    NationalIDNumber = "330724",
                    PhoneList        = new List <PersonPhone>
                    {
                        new PersonPhone {
                            PhoneNumberType = PhoneNumberType.手机, PhoneNumber = "138***"
                        },
                        new PersonPhone {
                            PhoneNumberType = PhoneNumberType.公司, PhoneNumber = "2223342"
                        }
                    }
                });
                _context.SaveChanges();
            }

            var asimov = _context.People.FirstOrDefault(p => p.Name == "Isaac");

            if (asimov == null)
            {
                _context.People.Add(
                    new Person
                {
                    Name             = "Isaac",
                    Gender           = Gender.M,
                    NationalIDNumber = "330724",
                    PhoneList        = new List <PersonPhone>
                    {
                        new PersonPhone {
                            PhoneNumberType = PhoneNumberType.手机, PhoneNumber = "137***"
                        },
                        new PersonPhone {
                            PhoneNumberType = PhoneNumberType.公司, PhoneNumber = "1123345"
                        }
                    }
                });
                _context.SaveChanges();
            }
        }
        public void Create()
        {
            var ou1 = _context.OrganizationUnits.FirstOrDefault(ou => ou.Id == 1);

            if (ou1 == null)
            {
                _context.OrganizationUnits.Add(
                    new OrganizationUnit
                {
                    ParentId    = null,
                    DisplayName = "物料类型",
                    Code        = "00001",
                    IsDeleted   = false
                });
                _context.SaveChanges();
            }

            var ou2 = _context.OrganizationUnits.FirstOrDefault(ou => ou.Id == 2);

            if (ou2 == null)
            {
                _context.OrganizationUnits.Add(
                    new OrganizationUnit
                {
                    ParentId    = null,
                    DisplayName = "组织机构",
                    Code        = "00002",
                    IsDeleted   = false
                });
                _context.SaveChanges();
            }

            var ou3 = _context.OrganizationUnits.FirstOrDefault(ou => ou.Id == 3);

            if (ou3 == null)
            {
                _context.OrganizationUnits.Add(
                    new OrganizationUnit
                {
                    ParentId    = null,
                    DisplayName = "仓库地址",
                    Code        = "00003",
                    IsDeleted   = false
                });
                _context.SaveChanges();
            }
        }
Пример #3
0
        public void Create()
        {
            _context.DisableAllFilters();

            new TestOrganizationUnitsBuilder(_context).Create();

            _context.SaveChanges();
        }
        private OrganizationUnit CreateOU(string displayName, string code, long?parentId = null)
        {
            var ou = _context.OrganizationUnits.Add(new OrganizationUnit(_defaultTenant.Id, displayName, parentId)
            {
                Code = code
            });

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

            _context.Settings.Add(new Setting(tenantId, null, name, value));
            _context.SaveChanges();
        }
Пример #6
0
        private void AddLanguageIfNotExists(ApplicationLanguage language)
        {
            if (_context.Languages.Any(l => l.TenantId == language.TenantId && l.Name == language.Name))
            {
                return;
            }

            _context.Languages.Add(language);

            _context.SaveChanges();
        }
Пример #7
0
        public void Create()
        {
            _context.DisableAllFilters();

            new DefaultEditionCreator(_context).Create();
            new DefaultLanguagesCreator(_context).Create();
            new DefaultTenantRoleAndUserCreator(_context).Create();
            new DefaultSettingsCreator(_context).Create();
            new DefaultPersonAndPhoneCreator(_context).Create();
            _context.SaveChanges();
        }
        private void CreateEditions()
        {
            var defaultEdition = _context.Editions.FirstOrDefault(e => e.Name == EditionManager.DefaultEditionName);

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

                //TODO: Add desired features to the standard edition, if wanted!
            }
        }
        private void CreateHostAndUsers()
        {
            //Admin role for host

            var adminRoleForHost = _context.Roles.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
                });
                _context.SaveChanges();
            }

            //admin user for host

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

            if (adminUserForHost == null)
            {
                adminUserForHost = _context.Users.Add(
                    new User
                {
                    TenantId         = null,
                    UserName         = User.AdminUserName,
                    Name             = "admin",
                    Surname          = "admin",
                    EmailAddress     = "*****@*****.**",
                    IsEmailConfirmed = true,
                    ShouldChangePasswordOnNextLogin = true,
                    IsActive = true,
                    Password = "******"     //123qwe
                });
                _context.SaveChanges();

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

                //Grant all permissions
                var permissions = PermissionFinder
                                  .GetAllPermissions(new AppAuthorizationProvider())
                                  .Where(p => p.MultiTenancySides.HasFlag(MultiTenancySides.Host))
                                  .ToList();

                foreach (var permission in permissions)
                {
                    if (!permission.IsGrantedByDefault)
                    {
                        _context.Permissions.Add(
                            new RolePermissionSetting
                        {
                            Name      = permission.Name,
                            IsGranted = true,
                            RoleId    = adminRoleForHost.Id
                        });
                    }
                }

                _context.SaveChanges();
            }
        }