コード例 #1
0
ファイル: Program.cs プロジェクト: Wreynk/CDCS-API
        private static int SaveOrganisationsToDb(OrganisationsInput organisations, CategoriesInput categories)
        {
            var changes = 0;

            using (var context = new CdcsContext()) {
                context.Database.EnsureDeleted();
                context.Database.EnsureCreated();

                context.Organisations.AddRange(organisations.Organisations);
                context.Accreditors.AddRange(organisations.Accreditors);
                context.Accreditations.AddRange(organisations.Accreditations);
                context.ContactModes.AddRange(organisations.ContactModes);
                context.GeographicalZones.AddRange(organisations.GeographicalZones);
                context.OrganisationLanguages.AddRange(organisations.OrganisationLanguages);
                context.OrganisationLegalStatuses.AddRange(organisations.OrganisationLegalStatuses);
                context.Languages.AddRange(organisations.Languages);

                context.Sectors.AddRange(categories.Sectors);
                context.Topics.AddRange(categories.Topics);
                context.Categories.AddRange(categories.Categories);
                context.SectorCategoriesHierarchies.AddRange(categories.SectorCategoriesHierarchies);

                changes = context.SaveChanges();
            }

            return(changes);
        }
コード例 #2
0
ファイル: Program.cs プロジェクト: Wreynk/CDCS-API
        private static int SaveToDb(IReadOnlyCollection <ICdcsIdentity> cdcs_objects)
        {
            var types         = cdcs_objects.Select(o => o.GetType()).Distinct();
            var nb_of_changes = 0;

            using (var context = new CdcsContext()) {
                context.Database.EnsureDeleted();
                context.Database.EnsureCreated();

                // context.Database.Migrate();

                foreach (var t in types)
                {
                    switch (t.Name)
                    {
                    case "CdcsActionZone":
                        context.CdcsActionZones.AddRange(GetCdcsObjectByType <CdcsActionZone>(cdcs_objects));
                        break;

                    case "CdcsAccreditationType":
                        context.CdcsAccreditationTypes.AddRange(GetCdcsObjectByType <CdcsAccreditationType>(cdcs_objects));
                        break;

                    case "CdcsAccreditor":
                        context.CdcsAccreditors.AddRange(GetCdcsObjectByType <CdcsAccreditor>(cdcs_objects));
                        break;

                    case "CdcsLanguage":
                        context.CdcsLanguages.AddRange(GetCdcsObjectByType <CdcsLanguage>(cdcs_objects));
                        break;

                    case "CdcsLegalStatus":
                        context.CdcsLegalStatuses.AddRange(GetCdcsObjectByType <CdcsLegalStatus>(cdcs_objects));
                        break;

                    case "CdcsSector":
                        context.CdcsSectors.AddRange(GetCdcsObjectByType <CdcsSector>(cdcs_objects));
                        break;

                    case "CdcsServiceType":
                        context.CdcsServiceTypes.AddRange(GetCdcsObjectByType <CdcsServiceType>(cdcs_objects));
                        break;
                    }
                }
                nb_of_changes = context.SaveChanges();
            }

            return(nb_of_changes);
        }
コード例 #3
0
ファイル: AppRepository.cs プロジェクト: Wreynk/CDCS-API
 public int SaveChanges()
 {
     return(_db.SaveChanges());
 }