Esempio n. 1
0
 public static void AddStatuses(NSCRegDbContext context)
 {
     context.Statuses.Add(new UnitStatus {
         Code = "1", Name = "Unit is active"
     });
     context.Statuses.Add(new UnitStatus {
         Code = "2", Name = "Unit is not active (inactive)"
     });
     context.Statuses.Add(new UnitStatus {
         Code = "3", Name = "Newly created statistical unit. Not yet active"
     });
     context.Statuses.Add(new UnitStatus {
         Code = "4", Name = "The unit is in liquidation phase"
     });
     context.Statuses.Add(new UnitStatus {
         Code = "5", Name = "Unit liquidated"
     });
     context.Statuses.Add(new UnitStatus {
         Code = "9", Name = "Unit deleted"
     });
     context.Statuses.Add(new UnitStatus {
         Code = "0", Name = "There is no information about the unit"
     });
     context.SaveChanges();
 }
Esempio n. 2
0
        public static void AddAnalysisLogs(NSCRegDbContext context)
        {
            var queueEntry = new AnalysisQueue
            {
                UserStartPeriod   = DateTime.Now,
                UserEndPeriod     = DateTime.Now,
                ServerStartPeriod = DateTime.Now,
                User = context.Users.First(),
            };

            var log = new[]
            {
                new AnalysisLog {
                    AnalyzedUnitId = 1, AnalyzedUnitType = StatUnitTypes.LocalUnit, SummaryMessages = "ConnectionRulesWarnings;MandatoryFieldsRulesWarnings", IssuedAt = DateTime.Parse("2017-12-22 19:09:25.7736777"), ResolvedAt = null, ErrorValues = "{'LegalUnitId':['AnalysisRelatedLegalUnit'],'Activities':['AnalysisRelatedActivity'],'Address':['AnalysisRelatedAddress'],'DataSourceClassificationId':['AnalysisMandatoryDataSource'],'ShortName':['AnalysisMandatoryShortName'],'TelephoneNo':['AnalysisMandatoryTelephoneNo'],'RegistrationReasonId':['AnalysisMandatoryRegistrationReason'],'ContactPerson':['AnalysisMandatoryContactPerson'],'Status':['AnalysisMandatoryStatusActive']}"
                },
                new AnalysisLog {
                    AnalyzedUnitId = 2, AnalyzedUnitType = StatUnitTypes.LocalUnit, SummaryMessages = "ConnectionRulesWarnings;MandatoryFieldsRulesWarnings", IssuedAt = DateTime.Parse("2017-12-22 19:09:28.4686079"), ResolvedAt = null, ErrorValues = "{'LegalUnitId':['AnalysisRelatedLegalUnit'],'Activities':['AnalysisRelatedActivity'],'Address':['AnalysisRelatedAddress'],'DataSourceClassificationId':['AnalysisMandatoryDataSource'],'ShortName':['AnalysisMandatoryShortName'],'TelephoneNo':['AnalysisMandatoryTelephoneNo'],'RegistrationReasonId':['AnalysisMandatoryRegistrationReason'],'ContactPerson':['AnalysisMandatoryContactPerson'],'Status':['AnalysisMandatoryStatusActive']}"
                },
                new AnalysisLog {
                    AnalyzedUnitId = 3, AnalyzedUnitType = StatUnitTypes.LegalUnit, SummaryMessages = "ConnectionRulesWarnings;MandatoryFieldsRulesWarnings", IssuedAt = DateTime.Parse("2017-12-22 19:09:30.3878882"), ResolvedAt = null, ErrorValues = "{'Address':['AnalysisRelatedAddress'],'DataSourceClassificationId':['AnalysisMandatoryDataSource'],'ShortName':['AnalysisMandatoryShortName'],'TelephoneNo':['AnalysisMandatoryTelephoneNo'],'RegistrationReasonId':['AnalysisMandatoryRegistrationReason'],'ContactPerson':['AnalysisMandatoryContactPerson'],'Status':['AnalysisMandatoryStatusActive'],'Persons':['AnalysisMandatoryPersonOwner']}"
                },
                new AnalysisLog {
                    AnalyzedUnitId = 4, AnalyzedUnitType = StatUnitTypes.EnterpriseUnit, SummaryMessages = "ConnectionRulesWarnings;MandatoryFieldsRulesWarnings;OrphanUnitsRulesWarnings", IssuedAt = DateTime.Parse("2017-12-22 19:09:32.1186972"), ResolvedAt = null, ErrorValues = "{'LegalUnits':['AnalysisRelatedLegalUnit'],'Activities':['AnalysisRelatedActivity'],'Address':['AnalysisRelatedAddress'],'DataSourceClassificationId':['AnalysisMandatoryDataSource'],'ShortName':['AnalysisMandatoryShortName'],'TelephoneNo':['AnalysisMandatoryTelephoneNo'],'RegistrationReasonId':['AnalysisMandatoryRegistrationReason'],'ContactPerson':['AnalysisMandatoryContactPerson'],'Status':['AnalysisMandatoryStatusActive'],'EntGroupId':['AnalysisOrphanEnterprise']}"
                },
                new AnalysisLog {
                    AnalyzedUnitId = 5, AnalyzedUnitType = StatUnitTypes.EnterpriseUnit, SummaryMessages = "ConnectionRulesWarnings;MandatoryFieldsRulesWarnings;OrphanUnitsRulesWarnings", IssuedAt = DateTime.Parse("2017-12-22 19:09:33.8364446"), ResolvedAt = null, ErrorValues = "{'LegalUnits':['AnalysisRelatedLegalUnit'],'Activities':['AnalysisRelatedActivity'],'Address':['AnalysisRelatedAddress'],'DataSourceClassificationId':['AnalysisMandatoryDataSource'],'ShortName':['AnalysisMandatoryShortName'],'TelephoneNo':['AnalysisMandatoryTelephoneNo'],'RegistrationReasonId':['AnalysisMandatoryRegistrationReason'],'ContactPerson':['AnalysisMandatoryContactPerson'],'Status':['AnalysisMandatoryStatusActive'],'EntGroupId':['AnalysisOrphanEnterprise']}"
                },
                new AnalysisLog {
                    AnalyzedUnitId = 6, AnalyzedUnitType = StatUnitTypes.EnterpriseUnit, SummaryMessages = "ConnectionRulesWarnings;MandatoryFieldsRulesWarnings;OrphanUnitsRulesWarnings", IssuedAt = DateTime.Parse("2017-12-22 19:09:35.5120566"), ResolvedAt = null, ErrorValues = "{'LegalUnits':['AnalysisRelatedLegalUnit'],'Activities':['AnalysisRelatedActivity'],'Address':['AnalysisRelatedAddress'],'DataSourceClassificationId':['AnalysisMandatoryDataSource'],'ShortName':['AnalysisMandatoryShortName'],'TelephoneNo':['AnalysisMandatoryTelephoneNo'],'RegistrationReasonId':['AnalysisMandatoryRegistrationReason'],'ContactPerson':['AnalysisMandatoryContactPerson'],'Status':['AnalysisMandatoryStatusActive'],'EntGroupId':['AnalysisOrphanEnterprise']}"
                },
                new AnalysisLog {
                    AnalyzedUnitId = 7, AnalyzedUnitType = StatUnitTypes.EnterpriseUnit, SummaryMessages = "ConnectionRulesWarnings;MandatoryFieldsRulesWarnings;OrphanUnitsRulesWarnings", IssuedAt = DateTime.Parse("2017-12-22 19:09:37.2072083"), ResolvedAt = null, ErrorValues = "{'LegalUnits':['AnalysisRelatedLegalUnit'],'Activities':['AnalysisRelatedActivity'],'Address':['AnalysisRelatedAddress'],'DataSourceClassificationId':['AnalysisMandatoryDataSource'],'ShortName':['AnalysisMandatoryShortName'],'TelephoneNo':['AnalysisMandatoryTelephoneNo'],'RegistrationReasonId':['AnalysisMandatoryRegistrationReason'],'ContactPerson':['AnalysisMandatoryContactPerson'],'Status':['AnalysisMandatoryStatusActive'],'EntGroupId':['AnalysisOrphanEnterprise']}"
                },
                new AnalysisLog {
                    AnalyzedUnitId = 8, AnalyzedUnitType = StatUnitTypes.EnterpriseUnit, SummaryMessages = "ConnectionRulesWarnings;MandatoryFieldsRulesWarnings;OrphanUnitsRulesWarnings", IssuedAt = DateTime.Parse("2017-12-22 19:09:39.0724324"), ResolvedAt = null, ErrorValues = "{'LegalUnits':['AnalysisRelatedLegalUnit'],'Activities':['AnalysisRelatedActivity'],'Address':['AnalysisRelatedAddress'],'DataSourceClassificationId':['AnalysisMandatoryDataSource'],'ShortName':['AnalysisMandatoryShortName'],'TelephoneNo':['AnalysisMandatoryTelephoneNo'],'RegistrationReasonId':['AnalysisMandatoryRegistrationReason'],'ContactPerson':['AnalysisMandatoryContactPerson'],'Status':['AnalysisMandatoryStatusActive'],'EntGroupId':['AnalysisOrphanEnterprise']}"
                },
                new AnalysisLog {
                    AnalyzedUnitId = 9, AnalyzedUnitType = StatUnitTypes.EnterpriseUnit, SummaryMessages = "ConnectionRulesWarnings;MandatoryFieldsRulesWarnings", IssuedAt = DateTime.Parse("2017-12-22 19:09:40.7310654"), ResolvedAt = null, ErrorValues = "{'Activities':['AnalysisRelatedActivity'],'Address':['AnalysisRelatedAddress'],'DataSourceClassificationId':['AnalysisMandatoryDataSource'],'ShortName':['AnalysisMandatoryShortName'],'TelephoneNo':['AnalysisMandatoryTelephoneNo'],'RegistrationReasonId':['AnalysisMandatoryRegistrationReason'],'ContactPerson':['AnalysisMandatoryContactPerson'],'Status':['AnalysisMandatoryStatusActive']}"
                },
                new AnalysisLog {
                    AnalyzedUnitId = 10, AnalyzedUnitType = StatUnitTypes.LegalUnit, SummaryMessages = "ConnectionRulesWarnings;MandatoryFieldsRulesWarnings", IssuedAt = DateTime.Parse("2017-12-22 19:09:42.3663417"), ResolvedAt = null, ErrorValues = "{'Address':['AnalysisRelatedAddress'],'DataSourceClassificationId':['AnalysisMandatoryDataSource'],'ShortName':['AnalysisMandatoryShortName'],'TelephoneNo':['AnalysisMandatoryTelephoneNo'],'RegistrationReasonId':['AnalysisMandatoryRegistrationReason'],'ContactPerson':['AnalysisMandatoryContactPerson'],'Status':['AnalysisMandatoryStatusActive'],'Persons':['AnalysisMandatoryPersonOwner']}"
                },
            };

            foreach (var entry in log)
            {
                entry.AnalysisQueue = queueEntry;
            }

            context.AnalysisLogs.AddRange(log);
            context.SaveChanges();
        }
Esempio n. 3
0
        public static void AddLegalForms(NSCRegDbContext context)
        {
            context.LegalForms.Add(new LegalForm {
                Name = "Хозяйственные товарищества и общества"
            });
            context.SaveChanges();
            var ff = context.LegalForms.Where(x => x.Name == "Хозяйственные товарищества и общества").Select(x => x.Id).SingleOrDefault();

            context.LegalForms.AddRange(new LegalForm {
                Name = "Акционерное общество", ParentId = ff
            });

            context.SaveChanges();
        }
Esempio n. 4
0
 public static void AddPersonTypes(NSCRegDbContext context)
 {
     context.PersonTypes.Add(new PersonType {
         Name = "Контактное лицо", IsDeleted = false, NameLanguage1 = "ContactPerson", NameLanguage2 = "Байланышуучу адам"
     });
     context.PersonTypes.Add(new PersonType {
         Name = "Учредитель", IsDeleted = false, NameLanguage1 = "Founder", NameLanguage2 = "Уюмдаштыруучу"
     });
     context.PersonTypes.Add(new PersonType {
         Name = "Владелец", IsDeleted = false, NameLanguage1 = "Owner", NameLanguage2 = "Ээси"
     });
     context.PersonTypes.Add(new PersonType {
         Name = "Руководитель", IsDeleted = false, NameLanguage1 = "Director", NameLanguage2 = "Башкарма"
     });
     context.SaveChanges();
 }
Esempio n. 5
0
 public static void AddEnterpriseGroupTypes(NSCRegDbContext context)
 {
     if (!context.EnterpriseGroupTypes.Any())
     {
         context.EnterpriseGroupTypes.AddRange(
             new EnterpriseGroupType()
         {
             Name = "All-residents", NameLanguage1 = "Все резиденты", NameLanguage2 = "Бардык резидент"
         },
             new EnterpriseGroupType()
         {
             Name = "Multinational domestically controlled ", NameLanguage1 = "Многонациональный внутренний контроль", NameLanguage2 = "Көп улуттуу өлкө башкарылат"
         },
             new EnterpriseGroupType()
         {
             Name = "Multinational foreign controlled", NameLanguage1 = "Многонациональный иностранный контроль", NameLanguage2 = "Көп улуттуу чет элдик көзөмөлдө"
         });
         context.SaveChanges();
     }
 }
Esempio n. 6
0
        /// <summary>
        /// Drop and re-create statunit search view
        /// </summary>
        /// <param name="context"></param>
        /// <param name="provider"></param>
        public static void CreateViewsProceduresAndFunctions(NSCRegDbContext context, ConnectionProvider provider, ReportingSettings reportingSettings = null)
        {
            IDbInitializer initializer;

            switch (provider)
            {
            case ConnectionProvider.InMemory: initializer = new InMemoryDbInitializer();
                break;

            case ConnectionProvider.SqlServer: initializer = new MsSqlDbInitializer();
                break;

            case ConnectionProvider.PostgreSql: initializer = new PostgreSqlDbInitializer();
                break;

            case ConnectionProvider.MySql: initializer = new MySqlDbInitializer();
                break;

            default: throw new Exception(Resources.Languages.Resource.ProviderIsNotSet);
            }

            initializer.Initialize(context, reportingSettings);
        }
Esempio n. 7
0
        public static void AddSectorCodes(NSCRegDbContext context)
        {
            context.SectorCodes.Add(new SectorCode {
                Name = "A Нефинансовые корпорации"
            });
            context.SaveChanges();

            var nonFinCorp = context.SectorCodes
                             .Where(x => x.Name == "A Нефинансовые корпорации")
                             .Select(x => x.Id)
                             .SingleOrDefault();

            context.SectorCodes.AddRange(
                new SectorCode
            {
                Name     = "государственные неинкорпорированные предприятия, принадлежащие центральному правительству",
                Code     = "1110",
                ParentId = nonFinCorp
            },
                new SectorCode
            {
                Name     = "государственные акционерные предприятия, принадлежащие центральному правительству",
                Code     = "1120",
                ParentId = nonFinCorp
            },
                new SectorCode
            {
                Name     = "государственные неинкорпорированные предприятия, принадлежащие местным органам власти",
                Code     = "1510",
                ParentId = nonFinCorp
            },
                new SectorCode
            {
                Name     = "государственные акционерные предприятия, принадлежащие местным органам власти",
                Code     = "1520",
                ParentId = nonFinCorp
            },
                new SectorCode
            {
                Name     = "частные нефинансовые объединенные предприятия",
                Code     = "2100",
                ParentId = nonFinCorp
            },
                new SectorCode
            {
                Name     = "частные нефинансовые неинкорпорированные предприятия",
                Code     = "2300",
                ParentId = nonFinCorp
            },
                new SectorCode
            {
                Name     = "частные некоммерческие организации, обслуживающие предприятия",
                Code     = "2500",
                ParentId = nonFinCorp
            });

            context.SectorCodes.Add(new SectorCode {
                Name = "B Финансовые корпорации"
            });
            context.SaveChanges();

            var financeCorp = context.SectorCodes
                              .Where(x => x.Name == "B Финансовые корпорации")
                              .Select(x => x.Id)
                              .SingleOrDefault();

            context.SectorCodes.AddRange(
                new SectorCode {
                Name = "Национальный банк", Code = "3100", ParentId = financeCorp
            },
                new SectorCode {
                Name = "банки", Code = "3200", ParentId = financeCorp
            },
                new SectorCode {
                Name = "ипотечные компании", Code = "3500", ParentId = financeCorp
            },
                new SectorCode {
                Name = "финансовые компании", Code = "3600", ParentId = financeCorp
            },
                new SectorCode {
                Name = "государственные кредитные организации", Code = "3900", ParentId = financeCorp
            },
                new SectorCode {
                Name = "финансовые холдинговые компании", Code = "4100", ParentId = financeCorp
            },
                new SectorCode {
                Name = "паевые инвестиционные фонды", Code = "4300", ParentId = financeCorp
            },
                new SectorCode
            {
                Name     = "инвестиционные трасты и фонды прямых инвестиций",
                Code     = "4500",
                ParentId = financeCorp
            },
                new SectorCode
            {
                Name     = "прочие финансовые предприятия, кроме страховых компаний и пенсионных фондов",
                Code     = "4900",
                ParentId = financeCorp
            },
                new SectorCode
            {
                Name     = "компании по страхованию жизни и пенсионные фонды",
                Code     = "5500",
                ParentId = financeCorp
            },
                new SectorCode
            {
                Name     = "компании, не связанные со страхованием жизни",
                Code     = "5700",
                ParentId = financeCorp
            });

            context.SectorCodes.Add(new SectorCode {
                Name = "C Общее правительство"
            });
            context.SaveChanges();

            var generalGov = context.SectorCodes
                             .Where(x => x.Name == "C Общее правительство")
                             .Select(x => x.Id)
                             .SingleOrDefault();

            context.SectorCodes.AddRange(
                new SectorCode {
                Name = "центральное правительство", Code = "6100", ParentId = generalGov
            },
                new SectorCode {
                Name = "местное самоуправление", Code = "6500", ParentId = generalGov
            });

            context.SectorCodes.Add(new SectorCode
            {
                Name = "D Некоммерческие организации, обслуживающие домашние хозяйства"
            });
            context.SaveChanges();

            var xx = context.SectorCodes
                     .Where(x => x.Name == "D Некоммерческие организации, обслуживающие домашние хозяйства")
                     .Select(x => x.Id)
                     .SingleOrDefault();

            context.SectorCodes.Add(new SectorCode
            {
                Name     = "некоммерческие организации, обслуживающие домашние хозяйства",
                Code     = "7000",
                ParentId = xx
            });

            context.SectorCodes.Add(new SectorCode {
                Name = "E Домохозяйства"
            });
            context.SaveChanges();

            var houseHolds = context.SectorCodes
                             .Where(x => x.Name == "E Домохозяйства")
                             .Select(x => x.Id).
                             SingleOrDefault();

            context.SectorCodes.AddRange(
                new SectorCode
            {
                Name     = "некорпоративные предприятия в домохозяйствах",
                Code     = "8200",
                ParentId = houseHolds
            },
                new SectorCode {
                Name = "жилищные кооперативы", Code = "8300", ParentId = houseHolds
            },
                new SectorCode
            {
                Name     = "сотрудники, получатели дохода от собственности, пенсий и социальных отчислений, студентов",
                Code     = "8500",
                ParentId = houseHolds
            });

            context.SectorCodes.Add(new SectorCode {
                Name = "F Остальной мир"
            });
            context.SaveChanges();

            var restWorld = context.SectorCodes
                            .Where(x => x.Name == "F Остальной мир")
                            .Select(x => x.Id)
                            .SingleOrDefault();

            context.SectorCodes.Add(new SectorCode {
                Name = "остальной мир", Code = "9000", ParentId = restWorld
            });
            context.SaveChanges();
        }
Esempio n. 8
0
        public static void AddStatUnits(NSCRegDbContext context)
        {
            var roleId       = context.Roles.FirstOrDefault(r => r.Name == DefaultRoleNames.Administrator)?.Id;
            var adminId      = context.UserRoles.FirstOrDefault(x => x.RoleId == roleId)?.UserId;
            var sysAdminUser = context.Users.FirstOrDefault(u => u.Id == adminId);

            context.StatisticalUnits.AddRange(new LocalUnit
            {
                Name        = "local unit 1",
                UserId      = sysAdminUser.Id,
                RegIdDate   = DateTime.Now,
                StartPeriod = DateTime.Now,
                EndPeriod   = DateTime.MaxValue,
                Address     = new Address {
                    AddressPart1 = "local address 1", RegionId = 1
                },
            }, new LocalUnit
            {
                Name        = "local unit 2",
                StatId      = "OKPO2LU",
                UserId      = sysAdminUser.Id,
                RegIdDate   = DateTime.Now,
                StartPeriod = DateTime.Now,
                EndPeriod   = DateTime.MaxValue,
                Address     = new Address {
                    AddressPart1 = "local address 2", RegionId = 1
                },
            });

            var le1 = new LegalUnit
            {
                Name        = "legal unit 1",
                UserId      = sysAdminUser.Id,
                RegIdDate   = DateTime.Now,
                StatId      = "OKPO2LEGALU",
                StartPeriod = DateTime.Now,
                EndPeriod   = DateTime.MaxValue,
                Address     = new Address
                {
                    AddressPart1 = "legal address 1",
                    RegionId     = 1
                },
                ActivitiesUnits = new List <ActivityStatisticalUnit>
                {
                    new ActivityStatisticalUnit
                    {
                        Activity = new Activity
                        {
                            IdDate           = new DateTime(2017, 03, 17),
                            Turnover         = 2000,
                            ActivityType     = ActivityTypes.Primary,
                            UpdatedByUser    = sysAdminUser,
                            ActivityYear     = DateTime.Today.Year,
                            ActivityCategory = context.ActivityCategories.Single(v => v.Code == "11.07.9")
                        },
                    },
                    new ActivityStatisticalUnit
                    {
                        Activity =
                            new Activity
                        {
                            IdDate           = new DateTime(2017, 03, 28),
                            Turnover         = 4000,
                            ActivityType     = ActivityTypes.Secondary,
                            UpdatedByUser    = sysAdminUser,
                            ActivityYear     = 2006,
                            ActivityCategory = context.ActivityCategories.Single(v => v.Code == "91.01.9")
                        }
                    }
                },
            };

            context.StatisticalUnits.AddRange(le1, new LegalUnit
            {
                Name        = "legal unit 2",
                UserId      = sysAdminUser.Id,
                IsDeleted   = true,
                RegIdDate   = DateTime.Now,
                StartPeriod = DateTime.Now,
                EndPeriod   = DateTime.MaxValue,
                Address     = new Address
                {
                    AddressPart1 = "legal address 2",
                    RegionId     = 1
                },
            });

            var eu1 = new EnterpriseUnit
            {
                Name        = "enterprise unit 1",
                StatId      = "OKPO1EU",
                UserId      = sysAdminUser.Id,
                RegIdDate   = DateTime.Now,
                StartPeriod = DateTime.Now,
                EndPeriod   = DateTime.MaxValue,
            };

            var eu2 = new EnterpriseUnit
            {
                Name        = "enterprise unit 2",
                StatId      = "OKPO2EU",
                UserId      = sysAdminUser.Id,
                RegIdDate   = DateTime.Now,
                StartPeriod = DateTime.Now,
                EndPeriod   = DateTime.MaxValue,
                Address     = new Address
                {
                    AddressPart1 = "enterprise address 2",
                    RegionId     = 1
                },
            };

            context.EnterpriseUnits.AddRange(eu1, eu2, new EnterpriseUnit
            {
                Name        = "enterprise unit 3",
                StatId      = "OKPO3EU",
                UserId      = sysAdminUser.Id,
                IsDeleted   = true,
                RegIdDate   = DateTime.Now,
                StartPeriod = DateTime.Now,
                EndPeriod   = DateTime.MaxValue,
                Address     = new Address
                {
                    AddressPart1 = "enterprise address 2",
                    RegionId     = 1
                },
            }, new EnterpriseUnit
            {
                StatId      = "OKPO4EU",
                Name        = "enterprise unit 4",
                UserId      = sysAdminUser.Id,
                RegIdDate   = DateTime.Now,
                StartPeriod = DateTime.Now,
                EndPeriod   = DateTime.MaxValue,
                Address     = new Address
                {
                    AddressPart1 = "enterprise address 2",
                    RegionId     = 1
                },
            }, new EnterpriseUnit
            {
                Name        = "enterprise unit 5",
                UserId      = sysAdminUser.Id,
                RegIdDate   = DateTime.Now,
                StartPeriod = DateTime.Now,
                EndPeriod   = DateTime.MaxValue,
                Address     = new Address
                {
                    AddressPart1 = "enterprise address 2",
                    RegionId     = 1
                },
            }, new EnterpriseUnit
            {
                Name        = "enterprise unit 6",
                UserId      = sysAdminUser.Id,
                RegIdDate   = DateTime.Now,
                StartPeriod = DateTime.Now,
                EndPeriod   = DateTime.MaxValue,
                Address     = new Address
                {
                    AddressPart1 = "enterprise address 2",
                    RegionId     = 1
                },
            });

            var eg1 = new EnterpriseGroup
            {
                Name        = "enterprise group 1",
                UserId      = sysAdminUser.Id,
                StatId      = "EG1",
                RegIdDate   = DateTime.Now,
                StartPeriod = DateTime.Now,
                EndPeriod   = DateTime.MaxValue,
                Address     =
                    new Address {
                    AddressPart1 = "ent. group address 1", RegionId = 1
                },
            };

            var eg2 = new EnterpriseGroup
            {
                Name        = "enterprise group 2",
                StatId      = "EG2",
                UserId      = sysAdminUser.Id,
                RegIdDate   = DateTime.Now,
                StartPeriod = DateTime.Now,
                EndPeriod   = DateTime.MaxValue,
                Address     =
                    new Address {
                    AddressPart1 = "ent. group address 2", RegionId = 1
                }
            };

            context.EnterpriseGroups.AddRange(eg1, eg2);

            //Links:
            eu1.EnterpriseGroup = eg1;
            le1.EnterpriseUnit  = eu1;

            context.SaveChanges();
        }
Esempio n. 9
0
        public static void AddCountries(NSCRegDbContext context)
        {
            context.Countries.AddRange(
                new Country {
                Name = "Andorra", Code = "AD"
            },
                new Country {
                Name = "United Arab Emirates", Code = "AE"
            },
                new Country {
                Name = "Afghanistan", Code = "AF"
            },
                new Country {
                Name = "Antigua and Barbuda", Code = "AG"
            },
                new Country {
                Name = "Anguilla", Code = "AI"
            },
                new Country {
                Name = "Albania", Code = "AL"
            },
                new Country {
                Name = "Armenia", Code = "AM"
            },
                new Country {
                Name = "Netherlands Antilles", Code = "AN"
            },
                new Country {
                Name = "Angola", Code = "AO"
            },
                new Country {
                Name = "Antarctica", Code = "AQ"
            },
                new Country {
                Name = "Argentina", Code = "AR"
            },
                new Country {
                Name = "American Samoa", Code = "AS"
            },
                new Country {
                Name = "Austria", Code = "AT"
            },
                new Country {
                Name = "Australia", Code = "AU"
            },
                new Country {
                Name = "Aruba", Code = "AW"
            },
                new Country {
                Name = "Azerbaijan", Code = "AZ"
            },
                new Country {
                Name = "Bosnia and Herzegovina", Code = "BA"
            },
                new Country {
                Name = "Barbados", Code = "BB"
            },
                new Country {
                Name = "Bangladesh", Code = "BD"
            },
                new Country {
                Name = "Belgium", Code = "BE"
            },
                new Country {
                Name = "Burkina Faso", Code = "BF"
            },
                new Country {
                Name = "Bulgaria", Code = "BG"
            },
                new Country {
                Name = "Bahrain", Code = "BH"
            },
                new Country {
                Name = "Burundi", Code = "BI"
            },
                new Country {
                Name = "Benin", Code = "BJ"
            },
                new Country {
                Name = "Saint Barthelemy", Code = "BL"
            },
                new Country {
                Name = "Bermuda", Code = "BM"
            },
                new Country {
                Name = "Brunei", Code = "BN"
            },
                new Country {
                Name = "Bolivia", Code = "BO"
            },
                new Country {
                Name = "Brazil", Code = "BR"
            },
                new Country {
                Name = "Bahamas", Code = "BS"
            },
                new Country {
                Name = "Bhutan", Code = "BT"
            },
                new Country {
                Name = "Botswana", Code = "BW"
            },
                new Country {
                Name = "Belarus", Code = "BY"
            },
                new Country {
                Name = "Belize", Code = "BZ"
            },
                new Country {
                Name = "Canada", Code = "CA"
            },
                new Country {
                Name = "Cocos Islands", Code = "CC"
            },
                new Country {
                Name = "Democratic Republic of the Congo", Code = "CD"
            },
                new Country {
                Name = "Central African Republic", Code = "CF"
            },
                new Country {
                Name = "Republic of the Congo", Code = "CG"
            },
                new Country {
                Name = "Switzerland", Code = "CH"
            },
                new Country {
                Name = "Ivory Coast", Code = "CI"
            },
                new Country {
                Name = "Cook Islands", Code = "CK"
            },
                new Country {
                Name = "Chile", Code = "CL"
            },
                new Country {
                Name = "Cameroon", Code = "CM"
            },
                new Country {
                Name = "China", Code = "CN"
            },
                new Country {
                Name = "Colombia", Code = "CO"
            },
                new Country {
                Name = "Costa Rica", Code = "CR"
            },
                new Country {
                Name = "Cuba", Code = "CU"
            },
                new Country {
                Name = "Cape Verde", Code = "CV"
            },
                new Country {
                Name = "Curacao", Code = "CW"
            },
                new Country {
                Name = "Christmas Island", Code = "CX"
            },
                new Country {
                Name = "Cyprus", Code = "CY"
            },
                new Country {
                Name = "Czech Republic", Code = "CZ"
            },
                new Country {
                Name = "Germany", Code = "DE"
            },
                new Country {
                Name = "Djibouti", Code = "DJ"
            },
                new Country {
                Name = "Denmark", Code = "DK"
            },
                new Country {
                Name = "Dominica", Code = "DM"
            },
                new Country {
                Name = "Dominican Republic", Code = "DO"
            },
                new Country {
                Name = "Algeria", Code = "DZ"
            },
                new Country {
                Name = "Ecuador", Code = "EC"
            },
                new Country {
                Name = "Estonia", Code = "EE"
            },
                new Country {
                Name = "Egypt", Code = "EG"
            },
                new Country {
                Name = "Western Sahara", Code = "EH"
            },
                new Country {
                Name = "Eritrea", Code = "ER"
            },
                new Country {
                Name = "Spain", Code = "ES"
            },
                new Country {
                Name = "Ethiopia", Code = "ET"
            },
                new Country {
                Name = "Finland", Code = "FI"
            },
                new Country {
                Name = "Fiji", Code = "FJ"
            },
                new Country {
                Name = "Falkland Islands", Code = "FK"
            },
                new Country {
                Name = "Micronesia", Code = "FM"
            },
                new Country {
                Name = "Faroe Islands", Code = "FO"
            },
                new Country {
                Name = "France", Code = "FR"
            },
                new Country {
                Name = "Gabon", Code = "GA"
            },
                new Country {
                Name = "United Kingdom", Code = "GB"
            },
                new Country {
                Name = "Grenada", Code = "GD"
            },
                new Country {
                Name = "Georgia", Code = "GE"
            },
                new Country {
                Name = "Guernsey", Code = "GG"
            },
                new Country {
                Name = "Ghana", Code = "GH"
            },
                new Country {
                Name = "Gibraltar", Code = "GI"
            },
                new Country {
                Name = "Greenland", Code = "GL"
            },
                new Country {
                Name = "Gambia", Code = "GM"
            },
                new Country {
                Name = "Guinea", Code = "GN"
            },
                new Country {
                Name = "Equatorial Guinea", Code = "GQ"
            },
                new Country {
                Name = "Greece", Code = "GR"
            },
                new Country {
                Name = "Guatemala", Code = "GT"
            },
                new Country {
                Name = "Guam", Code = "GU"
            },
                new Country {
                Name = "Guinea-Bissau", Code = "GW"
            },
                new Country {
                Name = "Guyana", Code = "GY"
            },
                new Country {
                Name = "Hong Kong", Code = "HK"
            },
                new Country {
                Name = "Honduras", Code = "HN"
            },
                new Country {
                Name = "Croatia", Code = "HR"
            },
                new Country {
                Name = "Haiti", Code = "HT"
            },
                new Country {
                Name = "Hungary", Code = "HU"
            },
                new Country {
                Name = "Indonesia", Code = "ID"
            },
                new Country {
                Name = "Ireland", Code = "IE"
            },
                new Country {
                Name = "Israel", Code = "IL"
            },
                new Country {
                Name = "Isle of Man", Code = "IM"
            },
                new Country {
                Name = "India", Code = "IN"
            },
                new Country {
                Name = "British Indian Ocean Territory", Code = "IO"
            },
                new Country {
                Name = "Iraq", Code = "IQ"
            },
                new Country {
                Name = "Iran", Code = "IR"
            },
                new Country {
                Name = "Iceland", Code = "IS"
            },
                new Country {
                Name = "Italy", Code = "IT"
            },
                new Country {
                Name = "Jersey", Code = "JE"
            },
                new Country {
                Name = "Jamaica", Code = "JM"
            },
                new Country {
                Name = "Jordan", Code = "JO"
            },
                new Country {
                Name = "Japan", Code = "JP"
            },
                new Country {
                Name = "Kenya", Code = "KE"
            },
                new Country {
                Name = "Kyrgyzstan", Code = "KG"
            },
                new Country {
                Name = "Cambodia", Code = "KH"
            },
                new Country {
                Name = "Kiribati", Code = "KI"
            },
                new Country {
                Name = "Comoros", Code = "KM"
            },
                new Country {
                Name = "Saint Kitts and Nevis", Code = "KN"
            },
                new Country {
                Name = "North Korea", Code = "KP"
            },
                new Country {
                Name = "South Korea", Code = "KR"
            },
                new Country {
                Name = "Kuwait", Code = "KW"
            },
                new Country {
                Name = "Cayman Islands", Code = "KY"
            },
                new Country {
                Name = "Kazakhstan", Code = "KZ"
            },
                new Country {
                Name = "Laos", Code = "LA"
            },
                new Country {
                Name = "Lebanon", Code = "LB"
            },
                new Country {
                Name = "Saint Lucia", Code = "LC"
            },
                new Country {
                Name = "Liechtenstein", Code = "LI"
            },
                new Country {
                Name = "Sri Lanka", Code = "LK"
            },
                new Country {
                Name = "Liberia", Code = "LR"
            },
                new Country {
                Name = "Lesotho", Code = "LS"
            },
                new Country {
                Name = "Lithuania", Code = "LT"
            },
                new Country {
                Name = "Luxembourg", Code = "LU"
            },
                new Country {
                Name = "Latvia", Code = "LV"
            },
                new Country {
                Name = "Libya", Code = "LY"
            },
                new Country {
                Name = "Morocco", Code = "MA"
            },
                new Country {
                Name = "Monaco", Code = "MC"
            },
                new Country {
                Name = "Moldova", Code = "MD"
            },
                new Country {
                Name = "Montenegro", Code = "ME"
            },
                new Country {
                Name = "Saint Martin", Code = "MF"
            },
                new Country {
                Name = "Madagascar", Code = "MG"
            },
                new Country {
                Name = "Marshall Islands", Code = "MH"
            },
                new Country {
                Name = "Macedonia", Code = "MK"
            },
                new Country {
                Name = "Mali", Code = "ML"
            },
                new Country {
                Name = "Myanmar", Code = "MM"
            },
                new Country {
                Name = "Mongolia", Code = "MN"
            },
                new Country {
                Name = "Macau", Code = "MO"
            },
                new Country {
                Name = "Northern Mariana Islands", Code = "MP"
            },
                new Country {
                Name = "Mauritania", Code = "MR"
            },
                new Country {
                Name = "Montserrat", Code = "MS"
            },
                new Country {
                Name = "Malta", Code = "MT"
            },
                new Country {
                Name = "Mauritius", Code = "MU"
            },
                new Country {
                Name = "Maldives", Code = "MV"
            },
                new Country {
                Name = "Malawi", Code = "MW"
            },
                new Country {
                Name = "Mexico", Code = "MX"
            },
                new Country {
                Name = "Malaysia", Code = "MY"
            },
                new Country {
                Name = "Mozambique", Code = "MZ"
            },
                new Country {
                Name = "Namibia", Code = "NA"
            },
                new Country {
                Name = "New Caledonia", Code = "NC"
            },
                new Country {
                Name = "Niger", Code = "NE"
            },
                new Country {
                Name = "Nigeria", Code = "NG"
            },
                new Country {
                Name = "Nicaragua", Code = "NI"
            },
                new Country {
                Name = "Netherlands", Code = "NL"
            },
                new Country {
                Name = "Norway", Code = "NO"
            },
                new Country {
                Name = "Nepal", Code = "NP"
            },
                new Country {
                Name = "Nauru", Code = "NR"
            },
                new Country {
                Name = "Niue", Code = "NU"
            },
                new Country {
                Name = "New Zealand", Code = "NZ"
            },
                new Country {
                Name = "Oman", Code = "OM"
            },
                new Country {
                Name = "Panama", Code = "PA"
            },
                new Country {
                Name = "Peru", Code = "PE"
            },
                new Country {
                Name = "French Polynesia", Code = "PF"
            },
                new Country {
                Name = "Papua New Guinea", Code = "PG"
            },
                new Country {
                Name = "Philippines", Code = "PH"
            },
                new Country {
                Name = "Pakistan", Code = "PK"
            },
                new Country {
                Name = "Poland", Code = "PL"
            },
                new Country {
                Name = "Saint Pierre and Miquelon", Code = "PM"
            },
                new Country {
                Name = "Pitcairn", Code = "PN"
            },
                new Country {
                Name = "Puerto Rico", Code = "PR"
            },
                new Country {
                Name = "Palestine", Code = "PS"
            },
                new Country {
                Name = "Portugal", Code = "PT"
            },
                new Country {
                Name = "Palau", Code = "PW"
            },
                new Country {
                Name = "Paraguay", Code = "PY"
            },
                new Country {
                Name = "Qatar", Code = "QA"
            },
                new Country {
                Name = "Reunion", Code = "RE"
            },
                new Country {
                Name = "Romania", Code = "RO"
            },
                new Country {
                Name = "Serbia", Code = "RS"
            },
                new Country {
                Name = "Russia", Code = "RU"
            },
                new Country {
                Name = "Rwanda", Code = "RW"
            },
                new Country {
                Name = "Saudi Arabia", Code = "SA"
            },
                new Country {
                Name = "Solomon Islands", Code = "SB"
            },
                new Country {
                Name = "Seychelles", Code = "SC"
            },
                new Country {
                Name = "Sudan", Code = "SD"
            },
                new Country {
                Name = "Sweden", Code = "SE"
            },
                new Country {
                Name = "Singapore", Code = "SG"
            },
                new Country {
                Name = "Saint Helena", Code = "SH"
            },
                new Country {
                Name = "Slovenia", Code = "SI"
            },
                new Country {
                Name = "Svalbard and Jan Mayen", Code = "SJ"
            },
                new Country {
                Name = "Slovakia", Code = "SK"
            },
                new Country {
                Name = "Sierra Leone", Code = "SL"
            },
                new Country {
                Name = "San Marino", Code = "SM"
            },
                new Country {
                Name = "Senegal", Code = "SN"
            },
                new Country {
                Name = "Somalia", Code = "SO"
            },
                new Country {
                Name = "Suriname", Code = "SR"
            },
                new Country {
                Name = "South Sudan", Code = "SS"
            },
                new Country {
                Name = "Sao Tome and Principe", Code = "ST"
            },
                new Country {
                Name = "El Salvador", Code = "SV"
            },
                new Country {
                Name = "Sint Maarten", Code = "SX"
            },
                new Country {
                Name = "Syria", Code = "SY"
            },
                new Country {
                Name = "Swaziland", Code = "SZ"
            },
                new Country {
                Name = "Turks and Caicos Islands", Code = "TC"
            },
                new Country {
                Name = "Chad", Code = "TD"
            },
                new Country {
                Name = "Togo", Code = "TG"
            },
                new Country {
                Name = "Thailand", Code = "TH"
            },
                new Country {
                Name = "Tajikistan", Code = "TJ"
            },
                new Country {
                Name = "Tokelau", Code = "TK"
            },
                new Country {
                Name = "East Timor", Code = "TL"
            },
                new Country {
                Name = "Turkmenistan", Code = "TM"
            },
                new Country {
                Name = "Tunisia", Code = "TN"
            },
                new Country {
                Name = "Tonga", Code = "TO"
            },
                new Country {
                Name = "Turkey", Code = "TR"
            },
                new Country {
                Name = "Trinidad and Tobago", Code = "TT"
            },
                new Country {
                Name = "Tuvalu", Code = "TV"
            },
                new Country {
                Name = "Taiwan", Code = "TW"
            },
                new Country {
                Name = "Tanzania", Code = "TZ"
            },
                new Country {
                Name = "Ukraine", Code = "UA"
            },
                new Country {
                Name = "Uganda", Code = "UG"
            },
                new Country {
                Name = "United States", Code = "US"
            },
                new Country {
                Name = "Uruguay", Code = "UY"
            },
                new Country {
                Name = "Uzbekistan", Code = "UZ"
            },
                new Country {
                Name = "Vatican", Code = "VA"
            },
                new Country {
                Name = "Saint Vincent and the Grenadines", Code = "VC"
            },
                new Country {
                Name = "Venezuela", Code = "VE"
            },
                new Country {
                Name = "British Virgin Islands", Code = "VG"
            },
                new Country {
                Name = "U.S. Virgin Islands", Code = "VI"
            },
                new Country {
                Name = "Vietnam", Code = "VN"
            },
                new Country {
                Name = "Vanuatu", Code = "VU"
            },
                new Country {
                Name = "Wallis and Futuna", Code = "WF"
            },
                new Country {
                Name = "Samoa", Code = "WS"
            },
                new Country {
                Name = "Kosovo", Code = "XK"
            },
                new Country {
                Name = "Yemen", Code = "YE"
            },
                new Country {
                Name = "Mayotte", Code = "YT"
            },
                new Country {
                Name = "South Africa", Code = "ZA"
            },
                new Country {
                Name = "Zambia", Code = "ZM"
            },
                new Country {
                Name = "Zimbabwe", Code = "ZW"
            });

            context.SaveChanges();
        }
Esempio n. 10
0
        public static void AddDataSources(NSCRegDbContext context)
        {
            var ds1 = new DataSource
            {
                Name              = "data source #1",
                Description       = "data source #1 detailed description",
                Priority          = DataSourcePriority.Ok,
                StatUnitType      = StatUnitTypes.LegalUnit,
                Restrictions      = null,
                VariablesMapping  = "id-RegId,name-Name",
                AttributesToCheck = "id,name,something",
                AllowedOperations = DataSourceAllowedOperation.CreateAndAlter,
                CsvDelimiter      = ",",
                CsvSkipCount      = 0,
            };
            var ds2 = new DataSource
            {
                Name              = "data source #2",
                Description       = "data source #2 detailed description",
                Priority          = DataSourcePriority.Trusted,
                StatUnitType      = StatUnitTypes.LocalUnit,
                Restrictions      = null,
                VariablesMapping  = "id-RegId,whatever-Name",
                AttributesToCheck = "id,salary,whatever",
                AllowedOperations = DataSourceAllowedOperation.Create,
                CsvDelimiter      = ",",
                CsvSkipCount      = 0,
            };

            context.DataSources.AddRange(ds1, ds2);
            context.SaveChanges();

            var dsq1 = new DataSourceQueue
            {
                DataSource         = ds1,
                DataSourceFileName = "qwe.xml",
                DataSourcePath     = ".\\",
                DataUploadingLogs  = new[]
                {
                    new DataUploadingLog
                    {
                        StartImportDate = DateTime.Now,
                        EndImportDate   = DateTime.Now,
                        StatUnitName    = "qwe",
                        SerializedUnit  =
                            JsonConvert.SerializeObject(new LegalUnit {
                            Name = "42", DataSource = "qwe.xml"
                        }),
                        Status = DataUploadingLogStatuses.Warning,
                        Errors = JsonConvert.SerializeObject(
                            new Dictionary <string, string[]> {
                            [nameof(LegalUnit.UnitStatusId)] = new[] { "err1", "err2" }
                        }),
                    }
                },
                EndImportDate   = DateTime.Now,
                StartImportDate = DateTime.Now,
                User            = context.Users.FirstOrDefault(),
                Status          = DataSourceQueueStatuses.DataLoadCompletedPartially,
            };

            context.DataSourceQueues.Add(dsq1);
            context.SaveChanges();
        }
Esempio n. 11
0
        /// <summary>
        /// Method for initializing data in a database
        /// </summary>
        /// <param name="context"></param>
        public static void Seed(NSCRegDbContext context)
        {
            if (!context.Regions.Any())
            {
                SeedData.AddRegions(context);
            }

            if (!context.ActivityCategories.Any())
            {
                SeedData.AddActivityCategories(context);
            }

            if (!context.LegalForms.Any())
            {
                context.LegalForms.Add(new LegalForm {
                    Name = "Хозяйственные товарищества и общества"
                });
                context.SaveChanges();
                var lf = context.LegalForms
                         .Where(x => x.Name == "Хозяйственные товарищества и общества")
                         .Select(x => x.Id)
                         .SingleOrDefault();
                context.LegalForms.AddRange(new LegalForm {
                    Name = "Акционерное общество", ParentId = lf
                });
                context.SaveChanges();
            }

            if (!context.SectorCodes.Any())
            {
                SeedData.AddSectorCodes(context);
            }

            if (!context.StatisticalUnits.Any())
            {
                SeedData.AddStatUnits(context);
            }

            if (!context.DataSources.Any())
            {
                SeedData.AddDataSources(context);
            }

            if (!context.LegalForms.Any())
            {
                SeedData.AddLegalForms(context);
            }

            if (!context.Countries.Any())
            {
                SeedData.AddCountries(context);
            }

            if (!context.AnalysisLogs.Any())
            {
                SeedData.AddAnalysisLogs(context);
            }

            if (!context.Statuses.Any())
            {
                SeedData.AddStatuses(context);
            }

            if (!context.PersonTypes.Any())
            {
                SeedData.AddPersonTypes(context);
            }

            SeedData.AddEnterpriseGroupTypes(context);
        }
Esempio n. 12
0
 /// <summary>
 /// Add or ensure Enterprise Group Types
 /// </summary>
 /// <param name="context"></param>
 public static void EnsureEntGroupTypes(NSCRegDbContext context) => SeedData.AddEnterpriseGroupTypes(context);
Esempio n. 13
0
 /// <summary>
 /// Add or ensure System Administrator role and its access rules
 /// </summary>
 /// <param name="context"></param>
 public static void EnsureRoles(NSCRegDbContext context) => SeedData.AddUsersAndRoles(context);
Esempio n. 14
0
 /// <summary>
 /// Drop database if exists and create new one, then apply migrations
 /// </summary>
 /// <param name="context"></param>
 public static void RecreateDb(NSCRegDbContext context)
 {
     context.Database.EnsureDeleted();
     context.Database.Migrate();
 }
Esempio n. 15
0
        public static void AddUsersAndRoles(NSCRegDbContext context)
        {
            var usedByServerFields = typeof(EnterpriseGroup).GetProperties()
                                     .Where(p => p.GetCustomAttribute <UsedByServerSideAttribute>() != null).Select(p => p.Name)
                                     .Union(typeof(EnterpriseUnit).GetProperties()
                                            .Where(p => p.GetCustomAttribute <UsedByServerSideAttribute>() != null).Select(p => p.Name))
                                     .Union(typeof(LegalUnit).GetProperties()
                                            .Where(p => p.GetCustomAttribute <UsedByServerSideAttribute>() != null).Select(p => p.Name))
                                     .Union(typeof(LocalUnit).GetProperties()
                                            .Where(p => p.GetCustomAttribute <UsedByServerSideAttribute>() != null).Select(p => p.Name))
                                     .ToList();

            var daa = typeof(EnterpriseGroup).GetProperties()
                      .Select(x => $"{nameof(EnterpriseGroup)}.{x.Name}")
                      .Union(typeof(EnterpriseUnit).GetProperties()
                             .Select(x => $"{nameof(EnterpriseUnit)}.{x.Name}"))
                      .Union(typeof(LegalUnit).GetProperties()
                             .Select(x => $"{nameof(LegalUnit)}.{x.Name}"))
                      .Union(typeof(LocalUnit).GetProperties()
                             .Select(x => $"{nameof(LocalUnit)}.{x.Name}"))
                      .ToArray();

            var adminRole = context.Roles.FirstOrDefault(r => r.Name == DefaultRoleNames.Administrator);

            if (adminRole == null)
            {
                adminRole = new Role
                {
                    Name           = DefaultRoleNames.Administrator,
                    Status         = RoleStatuses.Active,
                    Description    = "System administrator role",
                    NormalizedName = DefaultRoleNames.Administrator.ToUpper(),
                    AccessToSystemFunctionsArray =
                        ((SystemFunctions[])Enum.GetValues(typeof(SystemFunctions))).Select(x => (int)x),
                    StandardDataAccessArray =
                        new DataAccessPermissions(daa.Select(x =>
                                                             new Permission(x, true, !usedByServerFields.Any(x.Contains)))),
                };
                context.Roles.Add(adminRole);
            }
            else
            {
                adminRole.AccessToSystemFunctionsArray =
                    ((SystemFunctions[])Enum.GetValues(typeof(SystemFunctions))).Select(x => (int)x);
                adminRole.StandardDataAccessArray =
                    new DataAccessPermissions(daa.Select(x =>
                                                         new Permission(x, true, !usedByServerFields.Any(x.Contains))));
            }

            var employeeRole = context.Roles.FirstOrDefault(r => r.Name == DefaultRoleNames.Employee);

            if (employeeRole == null)
            {
                employeeRole = new Role
                {
                    Name           = DefaultRoleNames.Employee,
                    Status         = RoleStatuses.Active,
                    Description    = "NSC employee role",
                    NormalizedName = DefaultRoleNames.Employee.ToUpper(),
                    AccessToSystemFunctionsArray = GetFunctionsForRole(DefaultRoleNames.Employee),
                    StandardDataAccessArray      =
                        new DataAccessPermissions(daa.Select(x =>
                                                             new Permission(x, true, !usedByServerFields.Contains(x)))),
                };
                context.Roles.Add(employeeRole);
            }
            else
            {
                employeeRole.AccessToSystemFunctionsArray = GetFunctionsForRole(DefaultRoleNames.Employee);
                employeeRole.StandardDataAccessArray      =
                    new DataAccessPermissions(daa.Select(x =>
                                                         new Permission(x, true, !usedByServerFields.Contains(x))));
            }

            var externalRole = context.Roles.FirstOrDefault(r => r.Name == DefaultRoleNames.ExternalUser);

            if (externalRole == null)
            {
                externalRole = new Role
                {
                    Name           = DefaultRoleNames.ExternalUser,
                    Status         = RoleStatuses.Active,
                    Description    = "External user role",
                    NormalizedName = DefaultRoleNames.ExternalUser.ToUpper(),
                    AccessToSystemFunctionsArray = GetFunctionsForRole(DefaultRoleNames.ExternalUser),
                    StandardDataAccessArray      =
                        new DataAccessPermissions(daa.Select(x => new Permission(x, true, false))),
                };
                context.Roles.Add(externalRole);
            }
            else
            {
                externalRole.AccessToSystemFunctionsArray = GetFunctionsForRole(DefaultRoleNames.ExternalUser);
                externalRole.StandardDataAccessArray      =
                    new DataAccessPermissions(daa.Select(x => new Permission(x, true, false)));
            }

            var sysAdminUser = context.Users.FirstOrDefault(u => u.Login == "admin");

            if (sysAdminUser == null)
            {
                sysAdminUser = new User
                {
                    Login        = "******",
                    PasswordHash =
                        "AQAAAAEAACcQAAAAEF+cTdTv1Vbr9+QFQGMo6E6S5aGfoFkBnsrGZ4kK6HIhI+A9bYDLh24nKY8UL3XEmQ==",
                    SecurityStamp      = "9479325a-6e63-494a-ae24-b27be29be015",
                    Name               = "Admin user",
                    PhoneNumber        = "555123456",
                    Email              = "*****@*****.**",
                    NormalizedEmail    = "*****@*****.**".ToUpper(),
                    Status             = UserStatuses.Active,
                    Description        = "System administrator account",
                    NormalizedUserName = "******".ToUpper(),
                    DataAccessArray    = daa,
                };
                context.Users.Add(sysAdminUser);
            }

            if (!context.UserRoles.Any(x => x.RoleId == adminRole.Id && x.UserId == sysAdminUser.Id))
            {
                var adminUserRoleBinding = new UserRole
                {
                    RoleId = adminRole.Id,
                    UserId = sysAdminUser.Id,
                };
                context.UserRoles.Add(adminUserRoleBinding);
            }

            context.SaveChanges();
        }