Example #1
0
        private void CreateUnits()
        {
            //Default MeteorType

            var defaultUnit = _context.BD_Units.FirstOrDefault(m => m.UnitName == "ZOGLAB");

            if (defaultUnit == null)
            {
                var seedUnits = new List <BD_Unit>
                {
                    new BD_Unit {
                        UnitName = "ZOGLAB", Address = "杭州西溪", Contact = "Admin", ContactTel = "1990579", Email = "*****@*****.**", FaxNumber = "123456"
                    },
                    new BD_Unit {
                        UnitName = "上海", Address = "商洛区百家园路70号昆仑科技园A座南1-2层", Contact = "陈凌江", ContactTel = "1990579", Email = "*****@*****.**", FaxNumber = "123456"
                    },
                    new BD_Unit {
                        UnitName = "浙江", Address = "杭州", Contact = "张三", ContactTel = "1990579", Email = "*****@*****.**", FaxNumber = "123456"
                    },
                    new BD_Unit {
                        UnitName = "陕西", Address = "西安", Contact = "李四", ContactTel = "1990579", Email = "*****@*****.**", FaxNumber = "123456"
                    }
                };

                foreach (var item in seedUnits)
                {
                    _context.BD_Units.Add(item);
                }
                _context.SaveChanges();     //Step 03
            }
        }
Example #2
0
        public void Create()
        {
            _context.DisableAllFilters();

            new TestOrganizationUnitsBuilder(_context, _tenantId).Create();

            _context.SaveChanges();
        }
Example #3
0
 public void Create()
 {
     new CheckTypeCreator(_context).Create();
     new InstrumentCreator(_context).Create();
     new InstallationAndStandardCreator(_context).Create();
     new UnitsCreator(_context).Create();
     _context.SaveChanges();
 }
Example #4
0
        public void Create()
        {
            new DefaultEditionCreator(_context).Create();
            new DefaultLanguagesCreator(_context).Create();
            new HostRoleAndUserCreator(_context).Create();
            new DefaultSettingsCreator(_context).Create();

            _context.SaveChanges();
        }
Example #5
0
        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();
        }
Example #6
0
        private OrganizationUnit CreateOU(string displayName, string code, long?parentId = null)
        {
            var ou = _context.OrganizationUnits.Add(new OrganizationUnit(_tenantId, displayName, parentId)
            {
                Code = code
            });

            _context.SaveChanges();
            return(ou);
        }
Example #7
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();
        }
Example #8
0
        private void CreateDefaultTenant()
        {
            //Default tenant

            var defaultTenant = _context.Tenants.FirstOrDefault(t => t.TenancyName == MultiTenancy.Tenant.DefaultTenantName);

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

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

                _context.Tenants.Add(defaultTenant);
                _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!
            }

            if (defaultEdition.Id > 0)
            {
                CreateFeatureIfNotExists(defaultEdition.Id, AppFeatures.ChatFeature, true);
                CreateFeatureIfNotExists(defaultEdition.Id, AppFeatures.TenantToTenantChatFeature, true);
                CreateFeatureIfNotExists(defaultEdition.Id, AppFeatures.TenantToHostChatFeature, true);
            }
        }
Example #10
0
        private void CreateCheckType()
        {
            //Default MeteorType

            var defaultMeteorType = _context.BD_MeteorType.FirstOrDefault(m => m.Name == "温度");

            if (defaultMeteorType == null)
            {
                var seedMeteorTypes = new List <BD_MeteorType>
                {
                    new BD_MeteorType {
                        Name = "温度", Mark = "1"
                    },
                    new BD_MeteorType {
                        Name = "湿度", Mark = "2"
                    },
                    new BD_MeteorType {
                        Name = "温湿度", Mark = "3"
                    },
                    new BD_MeteorType {
                        Name = "气压", Mark = "4"
                    },
                    new BD_MeteorType {
                        Name = "风速", Mark = "5"
                    },
                    new BD_MeteorType {
                        Name = "雨量", Mark = "6"
                    },
                    new BD_MeteorType {
                        Name = "其他", Mark = "7"
                    }
                };

                foreach (var item in seedMeteorTypes)
                {
                    _context.BD_MeteorType.Add(item);
                }
                _context.SaveChanges();     //Step 03
            }

            //Default BD_CheckType

            var defaultCheckType = _context.BD_CheckType.FirstOrDefault(s => s.CheckName == "温度检定"); //Step 01

            if (defaultCheckType == null)                                                            //Step 02
            {
                var seedMeteorTypes = _context.BD_MeteorType.ToList();
                var checkTypes      = new List <BD_CheckType>
                {
                    new BD_CheckType {
                        MeteorTypeId    = seedMeteorTypes[0].Id,
                        CalibrationType = Calibration_Type.检定,
                        CheckName       = "温度检定"
                    },
                    new BD_CheckType {
                        MeteorTypeId    = seedMeteorTypes[0].Id,
                        CalibrationType = Calibration_Type.校准,
                        CheckName       = "温度校准"
                    },
                    new BD_CheckType {
                        MeteorType      = seedMeteorTypes[0],
                        CalibrationType = Calibration_Type.核查,
                        CheckName       = "温度核查"
                    },
                    new BD_CheckType {
                        MeteorType      = seedMeteorTypes[1],
                        CalibrationType = Calibration_Type.检定,
                        CheckName       = "湿度检定"
                    },
                    new BD_CheckType {
                        MeteorType      = seedMeteorTypes[1],
                        CalibrationType = Calibration_Type.校准,
                        CheckName       = "湿度校准"
                    },
                    new BD_CheckType {
                        MeteorType      = seedMeteorTypes[1],
                        CalibrationType = Calibration_Type.核查,
                        CheckName       = "湿度核查"
                    },
                    new BD_CheckType {
                        MeteorType      = seedMeteorTypes[2],
                        CalibrationType = Calibration_Type.检定,
                        CheckName       = "温湿度检定"
                    },
                    new BD_CheckType {
                        MeteorType      = seedMeteorTypes[2],
                        CalibrationType = Calibration_Type.校准,
                        CheckName       = "温湿度校准"
                    },
                    new BD_CheckType {
                        MeteorType      = seedMeteorTypes[2],
                        CalibrationType = Calibration_Type.核查,
                        CheckName       = "温湿度核查"
                    },
                    new BD_CheckType {
                        MeteorType      = seedMeteorTypes[3],
                        CalibrationType = Calibration_Type.检定,
                        CheckName       = "气压检定"
                    },
                    new BD_CheckType {
                        MeteorType      = seedMeteorTypes[3],
                        CalibrationType = Calibration_Type.校准,
                        CheckName       = "气压校准"
                    },
                    new BD_CheckType {
                        MeteorType      = seedMeteorTypes[3],
                        CalibrationType = Calibration_Type.核查,
                        CheckName       = "气压核查"
                    },
                    new BD_CheckType {
                        MeteorType      = seedMeteorTypes[4],
                        CalibrationType = Calibration_Type.检定,
                        CheckName       = "风速检定"
                    },
                    new BD_CheckType {
                        MeteorType      = seedMeteorTypes[4],
                        CalibrationType = Calibration_Type.校准,
                        CheckName       = "风速校准"
                    },
                    new BD_CheckType {
                        MeteorType      = seedMeteorTypes[4],
                        CalibrationType = Calibration_Type.核查,
                        CheckName       = "风速核查"
                    },
                    new BD_CheckType {
                        MeteorType      = seedMeteorTypes[5],
                        CalibrationType = Calibration_Type.检定,
                        CheckName       = "雨量检定"
                    },
                    new BD_CheckType {
                        MeteorType      = seedMeteorTypes[5],
                        CalibrationType = Calibration_Type.校准,
                        CheckName       = "雨量校准"
                    },
                    new BD_CheckType {
                        MeteorType      = seedMeteorTypes[5],
                        CalibrationType = Calibration_Type.核查,
                        CheckName       = "雨量核查"
                    }
                };

                foreach (var item in checkTypes)
                {
                    _context.BD_CheckType.Add(item);
                }
                _context.SaveChanges();     //Step 03
            }
        }
        private void CreateRolesAndUsers()
        {
            //Admin role

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

                //Grant all permissions to admin role
                var permissions = PermissionFinder
                                  .GetAllPermissions(new AppAuthorizationProvider(false))
                                  .Where(p => p.MultiTenancySides.HasFlag(MultiTenancySides.Tenant))
                                  .ToList();

                foreach (var permission in permissions)
                {
                    _context.Permissions.Add(
                        new RolePermissionSetting
                    {
                        TenantId  = _tenantId,
                        Name      = permission.Name,
                        IsGranted = true,
                        RoleId    = adminRole.Id
                    });
                }

                _context.SaveChanges();
            }

            //User role

            var userRole = _context.Roles.FirstOrDefault(r => r.TenantId == _tenantId && r.Name == StaticRoleNames.Tenants.User);

            if (userRole == null)
            {
                _context.Roles.Add(new Role(_tenantId, StaticRoleNames.Tenants.User, StaticRoleNames.Tenants.User)
                {
                    IsStatic = true, IsDefault = true
                });
                _context.SaveChanges();
            }

            //admin user

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

            if (adminUser == null)
            {
                adminUser = User.CreateTenantAdminUser(_tenantId, "*****@*****.**", "123qwe");
                adminUser.IsEmailConfirmed = true;
                adminUser.ShouldChangePasswordOnNextLogin = 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();

                //User account of admin user
                if (_tenantId == 1)
                {
                    _context.UserAccounts.Add(new UserAccount
                    {
                        TenantId     = _tenantId,
                        UserId       = adminUser.Id,
                        UserName     = User.AdminUserName,
                        EmailAddress = adminUser.EmailAddress
                    });
                    _context.SaveChanges();
                }
            }
        }
Example #12
0
        private void CreateInstruments()
        {
            //https://stackoverflow.com/questions/14257360/linq-select-objects-in-list-where-exists-in-a-b-c
            //var allowedStatus = new[] { "A", "B", "C" };
            //var filteredOrders = orders.Order.Where(o => allowedStatus.Contains(o.StatusCode));
            //Default MeteorType

            var checkLists = _context.BD_CheckType.ToList();
            //var checkListR = checkLists.Where(c => new long[3] { 1, 2, 3 }.Contains(c.Id)).ToList();
            //var checkListR = new List<BD_CheckType>
            //{
            //    new BD_CheckType{
            //        CalibrationType = Calibration_Type.检定,
            //        CheckName = "温度检定"
            //    },
            //    new BD_CheckType{
            //        CalibrationType = Calibration_Type.检定,
            //        CheckName = "湿度检定"
            //    },
            //     new BD_CheckType{
            //         CalibrationType = Calibration_Type.检定,
            //         CheckName = "气压检定"
            //    }
            //};


            //var checkListB = checkLists.Where(c => new long[3] { 1, 2, 3 }.Contains(c.Id)).ToList();

            var meteorTypes  = _context.BD_MeteorType.ToList();
            var meteorTypesR = meteorTypes.Where(c => new long[3] {
                1, 2, 3
            }.Contains(c.Id)).ToList();
            var meteorTypesW = meteorTypes.Where(c => new long[3] {
                4, 5, 6
            }.Contains(c.Id)).ToList();
            var meteorTypesB = meteorTypes.Where(c => new long[3] {
                5, 6, 7
            }.Contains(c.Id)).ToList();


            var defaultUnit = _context.BD_Instruments.OrderBy(i => i.Name).FirstOrDefault(m => m.Name == "地温传感器");

            if (defaultUnit == null)
            {
                var seedUnits = new List <BD_Instrument>
                {
                    new BD_Instrument
                    {
                        SN           = "TEST013A", Name = "地温传感器", Model = "PT100", Grade = "2", Scope = "(-30~500)℃", Power = "0.1℃",
                        Manufacturer = "杭州仪器厂", Mark = "测试时间:12/24/2018", CheckTypes = checkLists, MeteorTypes = meteorTypesR
                    },
                    new BD_Instrument
                    {
                        SN           = "TEST014B", Name = "地温传感器", Model = "PT200", Grade = "3", Scope = "(-50~600)℃", Power = "0.2℃",
                        Manufacturer = "杭州仪器厂", Mark = "测试时间:12/24/2018", CheckTypes = checkLists, MeteorTypes = meteorTypesW
                    },
                    new BD_Instrument
                    {
                        SN           = "TEST015C", Name = "地温传感器", Model = "PT300", Grade = "4", Scope = "(-30~100)℃", Power = "0.1℃",
                        Manufacturer = "杭州仪器厂", Mark = "测试时间:12/24/2018", CheckTypes = checkLists, MeteorTypes = meteorTypesB
                    },
                    new BD_Instrument
                    {
                        SN           = "TEST016D", Name = "地温传感器", Model = "PT400", Grade = "5", Scope = "(-20~200)℃", Power = "0.3℃",
                        Manufacturer = "杭州仪器厂", Mark = "测试时间:12/24/2018", CheckTypes = checkLists, MeteorTypes = meteorTypesB
                    },
                    new BD_Instrument
                    {
                        SN           = "TEST017E", Name = "地温传感器", Model = "PT500", Grade = "6", Scope = "(-10~300)℃", Power = "0.5℃",
                        Manufacturer = "杭州仪器厂", Mark = "测试时间:12/24/2018", CheckTypes = checkLists, MeteorTypes = meteorTypesR
                    }
                };

                foreach (var item in seedUnits)
                {
                    _context.BD_Instruments.Add(item);
                }
                _context.SaveChanges();     //Step 03
            }
        }
        private void CreateInstallationAndStandard()
        {
            //Default Installationss

            var defaultInstallation = _context.BD_Installations.FirstOrDefault(i => i.Equipment_Name == "湿度检定装置");

            if (defaultInstallation == null)
            {
                var seedInstallations = new List <BD_Installation>
                {
                    new BD_Installation {
                        Standard_SN   = "4113803", Equipment_Name = "二等铂电阻温度计标准装置", Equipment_Model = "3000", TestRange = "(-30~+80)℃", Accurate = "二级",
                        CertificateId = "[2016]桂量标气象证字第006号", ValidateDate = "43840", Organization = "广西壮族自治区质量技术监督局", Mark = "湿度检定装置"
                    },
                    new BD_Installation
                    {
                        Standard_SN   = "12417601", Equipment_Name = " 0.01级数字压力计标准装置", Equipment_Model = "12417601", TestRange = "(500~1100)hPa℃", Accurate = "二级",
                        CertificateId = "[2016]桂量标气象证字第003号", ValidateDate = "43840", Organization = "广西壮族自治区质量技术监督局", Mark = "湿度检定装置"
                    },
                    new BD_Installation
                    {
                        Standard_SN   = "46514500", Equipment_Name = "湿度检定装置", Equipment_Model = "3000", TestRange = "(0-100)%RH", Accurate = "二级",
                        CertificateId = "[86]陕量标气证字第002号", ValidateDate = "43840", Organization = "陕西省质量技术监督局", Mark = "湿度检定装置"
                    },
                    new BD_Installation {
                        Standard_SN   = "46514500", Equipment_Name = "湿度计检定装置", Equipment_Model = "3001", TestRange = "((0~70)℃ (-40~50)℃DP	±0.1℃ ±0.2℃DP", Accurate = "二级",
                        CertificateId = "[2011]冀社量标授证字第104号", ValidateDate = "42363", Organization = "河北省质量技术监督局", Mark = "湿度计检定装置"
                    },
                    new BD_Installation {
                        Standard_SN   = "4114702", Equipment_Name = "水银温度计标准装置", Equipment_Model = "4000", TestRange = "(-30~80)℃	U=0.04 ℃", Accurate = "二级",
                        CertificateId = "[2011]冀量标授证字第105号", ValidateDate = "42363", Organization = "河北省质量技术监督局", Mark = "水银温度计标准装置"
                    }
                };

                foreach (var item in seedInstallations)
                {
                    _context.BD_Installations.Add(item);
                }
                _context.SaveChanges();     //Step 03
            }

            //Default Standards

            var defaultStandard = _context.BD_Standards.FirstOrDefault(s => s.StrName == "精密温湿度测试仪"); //Step 01

            if (defaultStandard == null)                                                              //Step 02
            {
                var installations = _context.BD_Installations.Where(i => i.Id < 4).ToList();
                var seedStandards = new List <BD_Standard>
                {
                    new BD_Standard {
                        StrName      = "气压表(计)检定箱", FactoryNum = "3", StrSpec = "YE-LQ-98-1型", Manufactor = "辽宁气象装备公司", ManufactorTel = "0551-2290348",
                        CaliFactory  = "安徽省气象计量检定站", CaliFactoryMan = "周昌文", CaliFactoryTel = "0551-2290348", Installation = installations[0], ResponsibleMan = "魏根宝",
                        ValidateDate = new DateTime(2012, 4, 24), TestRange = "((500-1100)hPa ", Accurate = "0.14hPa", StrK = "1", CertNum = "",
                        StrType      = true, Mark = "标准器"
                    },
                    new BD_Standard {
                        StrName      = "精密温湿度测试仪", FactoryNum = "3", StrSpec = "DHT-2000", Manufactor = "天津气象仪器厂", ManufactorTel = "010-68407036",
                        CaliFactory  = "国家气象计量检定站", CaliFactoryMan = "赵旭", CaliFactoryTel = "010-68407036", Installation = installations[1], ResponsibleMan = "李建英",
                        ValidateDate = new DateTime(2012, 4, 26), TestRange = "(10-100)%RH", Accurate = "二等", StrK = "1", CertNum = "",
                        StrType      = true, Mark = "标准器"
                    },
                    new BD_Standard {
                        StrName      = "自校式铂电阻数字测温仪", FactoryNum = "4027", StrSpec = "RCY-1A", Manufactor = "河北省高碑店市兴华电子仪器厂", ManufactorTel = "010-68407036",
                        CaliFactory  = "国家气象计量站", CaliFactoryMan = "赵旭", CaliFactoryTel = "010-68407036", Installation = installations[2], ResponsibleMan = "李建英",
                        ValidateDate = new DateTime(2012, 3, 31), TestRange = "(-60~+80)℃", Accurate = "二等", StrK = "1", CertNum = "",
                        StrType      = true, Mark = "标准器"
                    }
                };

                foreach (var item in seedStandards)
                {
                    _context.BD_Standards.Add(item);
                }
                _context.SaveChanges();     //Step 03
            }
        }
Example #14
0
        private void CreateHostRoleAndUsers()
        {
            //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(null, adminUserForHost.Id, adminRoleForHost.Id));
                _context.SaveChanges();

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

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

                _context.SaveChanges();

                //User account of admin user
                _context.UserAccounts.Add(new UserAccount
                {
                    TenantId     = null,
                    UserId       = adminUserForHost.Id,
                    UserName     = User.AdminUserName,
                    EmailAddress = adminUserForHost.EmailAddress
                });

                _context.SaveChanges();
            }
        }