< Summary

Class:MUNity.Database.Context.MunityContext
Assembly:MUNity.Database
File(s):C:\Users\aeuke\source\repos\PeerConradi\munity\src\MUNityDatabase\Context\MunityContext.cs
Covered lines:267
Uncovered lines:14
Coverable lines:281
Total lines:545
Line coverage:95% (267 of 281)
Covered branches:54
Total branches:64
Branch coverage:84.3% (54 of 64)
Covered methods:73
Total methods:74
Method coverage:98.6% (73 of 74)

Metrics

MethodBranch coverage Cyclomatic complexity Line coverage
get_Fluent()100%1100%
get_Countries()100%1100%
get_CountryNameTranslations()100%1100%
get_Organizations()100%1100%
get_OrganizationRoles()100%1100%
get_OrganizationMembers()100%1100%
get_Projects()100%1100%
get_Committees()100%1100%
get_Delegations()100%1100%
get_Delegates()100%1100%
get_ConferenceTeamRoles()100%1100%
get_SecretaryGenerals()100%1100%
get_Conferences()100%1100%
get_ConferenceParticipationCostRules()100%1100%
get_CommitteeTopics()100%1100%
get_AttendanceStates()100%1100%
get_AttendanceChecks()100%1100%
get_CommitteeSessions()100%1100%
get_Participations()100%1100%
get_ConferenceRoleAuthorizations()100%1100%
get_RoleApplications()100%1100%
get_DelegationApplications()100%1100%
get_DelegationApplicationUserEntries()100%1100%
get_DelegationApplicationPickedDelegations()100%1100%
get_ConferenceDelegationApplicationFieldInputs()100%1100%
get_FillApplications()100%1100%
get_ConferenceFillApplicationFieldInputs()100%1100%
get_TeamRoleGroups()100%1100%
get_ResolutionAuths()100%1100%
get_ResolutionUsers()100%1100%
get_ListOfSpeakers()100%1100%
get_Speakers()100%1100%
get_ListOfSpeakersLogs()100%1100%
get_Settings()100%1100%
get_Resolutions()100%1100%
get_PreambleParagraphs()100%1100%
get_OperativeParagraphs()100%1100%
get_ResolutionSupporters()100%1100%
get_ResolutionDeleteAmendments()100%1100%
get_ResolutionChangeAmendments()100%1100%
get_ResolutionMoveAmendments()100%1100%
get_ResolutionAddAmendments()100%1100%
get_ConferenceWebPages()100%1100%
get_ConferenceApplicationOptions()100%1100%
get_ConferenceApplicationFormulas()100%1100%
get_ConferenceApplicationFields()100%1100%
get_ConferencePageColorSchemes()100%1100%
get_UserNotifications()100%1100%
get_UserNotificationCategories()100%1100%
get_Schools()100%1100%
get_UsersInSchools()100%1100%
get_ConferenceDashboardCards()100%1100%
get_ConferenceWebMenuEntries()100%1100%
get_ConferenceWebPageDelegatesElements()100%1100%
get_ConferenceWebPageCommitteeTopicsElements()100%1100%
get_ConferenceWebPageTeamCardsElements()100%1100%
get_ConferenceWebPageTextElements()100%1100%
get_ConferenceWebPageRegisterElements()100%1100%
get_ConferenceWebsiteFooters()100%1100%
get_UserFriends()100%1100%
get_UserBlockedUsers()100%1100%
OnModelCreating(...)100%1100%
.ctor(...)100%1100%
SaveChanges()100%4100%
HandleEasyId()100%12100%
HandleEasyIdOrganization(...)87.5%891.66%
HandleEasyIdProject(...)87.5%891.66%
HandleEasyIdConference(...)75%866.66%
HandleEasyIdCommittee(...)80%1092.85%
HandleEasyDelegationId(...)60%1073.33%
SaveChangesWithoutSoftDelete()100%1100%
SaveChangesWithoutSoftDeleteAsync()100%10%
SaveChangesAsync(...)100%4100%
FromSqlLite(...)100%1100%

File(s)

C:\Users\aeuke\source\repos\PeerConradi\munity\src\MUNityDatabase\Context\MunityContext.cs

#LineLine coverage
 1using Microsoft.EntityFrameworkCore;
 2using System;
 3using System.Collections.Generic;
 4using System.Linq;
 5using System.Threading;
 6using System.Threading.Channels;
 7using System.Threading.Tasks;
 8using MUNityCore.Models.User;
 9using MUNityCore.Models;
 10using Microsoft.AspNetCore.Identity.EntityFrameworkCore;
 11using Microsoft.AspNetCore.Identity;
 12using Microsoft.EntityFrameworkCore.ChangeTracking;
 13using MUNity.Database.General;
 14using MUNity.Database.Models.User;
 15using MUNity.Database.Models.Conference;
 16using MUNity.Database.Models.Organization;
 17using MUNity.Database.Models.Conference.Roles;
 18using MUNity.Database.Models.Simulation;
 19using MUNity.Database.Models.LoS;
 20using MUNity.Database.Models;
 21using MUNity.Database.Models.Resolution;
 22using MUNity.Database.Models.Session;
 23using MUNity.Database.Interfaces;
 24using MUNity.Database.Models.Website;
 25using MUNity.Database.Models.General;
 26using MUNity.Database.FluentAPI;
 27using System.Diagnostics;
 28
 29namespace MUNity.Database.Context
 30{
 31    public class MunityContext
 32        : IdentityDbContext<MunityUser,
 33            MunityRole,
 34            string,
 35            IdentityUserClaim<string>,
 36            MunityUserRole,
 37            IdentityUserLogin<string>,
 38            IdentityRoleClaim<string>,
 39            IdentityUserToken<string>>
 40    {
 41
 9542        public FluentProvider Fluent { get; private set; }
 43
 91044        public DbSet<Country> Countries { get; set; }
 45
 3346        public DbSet<CountryNameTranslation> CountryNameTranslations { get; set; }
 47
 9448        public DbSet<Organization> Organizations { get; set; }
 49
 3450        public DbSet<OrganizationRole> OrganizationRoles { get; set; }
 51
 3652        public DbSet<OrganizationMember> OrganizationMembers { get; set; }
 53
 5154        public DbSet<Project> Projects { get; set; }
 55
 7556        public DbSet<Committee> Committees { get; set; }
 57
 13858        public DbSet<Delegation> Delegations { get; set; }
 59
 40460        public DbSet<ConferenceDelegateRole> Delegates { get; set; }
 61
 4062        public DbSet<ConferenceTeamRole> ConferenceTeamRoles { get; set; }
 63
 2864        public DbSet<ConferenceSecretaryGeneralRole> SecretaryGenerals { get; set; }
 65
 11566        public DbSet<Conference> Conferences { get; set; }
 67
 2868        public DbSet<ConferenceParticipationCostRule> ConferenceParticipationCostRules { get; set; }
 69
 3070        public DbSet<CommitteeTopic> CommitteeTopics { get; set; }
 71
 2672        public DbSet<AttendanceState> AttendanceStates { get; set; }
 73
 2674        public DbSet<AttendanceCheck> AttendanceChecks { get; set; }
 75
 2876        public DbSet<CommitteeSession> CommitteeSessions { get; set; }
 77
 3578        public DbSet<Participation> Participations { get; set; }
 79
 5080        public DbSet<ConferenceRoleAuth> ConferenceRoleAuthorizations { get; set; }
 81
 2882        public DbSet<RoleApplication> RoleApplications { get; set; }
 83
 3184        public DbSet<DelegationApplication> DelegationApplications { get; set; }
 85
 2786        public DbSet<DelegationApplicationUserEntry> DelegationApplicationUserEntries { get; set; }
 87
 2688        public DbSet<DelegationApplicationPickedDelegation> DelegationApplicationPickedDelegations { get; set; }
 89
 2590        public DbSet<ConferenceDelegationApplicationFieldInput> ConferenceDelegationApplicationFieldInputs { get; set; }
 91
 2592        public DbSet<FillApplication> FillApplications { get; set; }
 93
 2594        public DbSet<ConferenceFillApplicationFieldInput> ConferenceFillApplicationFieldInputs { get; set; }
 95
 3296        public DbSet<TeamRoleGroup> TeamRoleGroups { get; set; }
 97
 2898        public DbSet<ResolutionAuth> ResolutionAuths { get; set; }
 99
 26100        public DbSet<ResolutionUser> ResolutionUsers { get; set; }
 101
 102        //public DbSet<Simulation> Simulations { get; set; }
 103
 104        //public DbSet<SimulationRole> SimulationRoles { get; set; }
 105
 106        //public DbSet<SimulationUser> SimulationUser { get; set; }
 107
 108        //public DbSet<SimulationVoting> SimulationVotings { get; set; }
 109
 110        //public DbSet<SimulationVotingSlot> VotingSlots { get; set; }
 111
 112        //public DbSet<SimulationLog> SimulationLog { get; set; }
 113
 114        //public DbSet<SimulationInvite> SimulationInvites { get; set; }
 115
 116        //public DbSet<AgendaItem> AgendaItems { get; set; }
 117
 118        //public DbSet<PetitionType> PetitionTypes { get; set; }
 119
 120        //public DbSet<Petition> Petitions { get; set; }
 121
 122        //public DbSet<PetitionTypeSimulation> SimulationPetitionTypes { get; set; }
 123
 124        //public DbSet<SimulationStatus> SimulationStatuses { get; set; }
 125
 126        //public DbSet<SimulationPresents> PresentChecks { get; set; }
 127
 128        //public DbSet<PresentsState> PresentStates { get; set; }
 129
 26130        public DbSet<ListOfSpeakers> ListOfSpeakers { get; set; }
 131
 26132        public DbSet<Speaker> Speakers { get; set; }
 133
 26134        public DbSet<ListOfSpeakersLog> ListOfSpeakersLogs { get; set; }
 135
 28136        public DbSet<MunitySetting> Settings { get; set; }
 137
 57138        public DbSet<ResaElement> Resolutions { get; set; }
 139
 37140        public DbSet<ResaPreambleParagraph> PreambleParagraphs { get; set; }
 141
 68142        public DbSet<ResaOperativeParagraph> OperativeParagraphs { get; set; }
 143
 26144        public DbSet<ResaSupporter> ResolutionSupporters { get; set; }
 145
 29146        public DbSet<ResaDeleteAmendment> ResolutionDeleteAmendments { get; set; }
 28147        public DbSet<ResaChangeAmendment> ResolutionChangeAmendments { get; set; }
 28148        public DbSet<ResaMoveAmendment> ResolutionMoveAmendments { get; set; }
 26149        public DbSet<ResaAddAmendment> ResolutionAddAmendments { get; set; }
 150
 31151        public DbSet<ConferenceWebPage> ConferenceWebPages { get; set; }
 152
 27153        public DbSet<ConferenceApplicationOptions> ConferenceApplicationOptions { get; set; }
 154
 28155        public DbSet<ConferenceApplicationFormula> ConferenceApplicationFormulas { get; set; }
 26156        public DbSet<ConferenceApplicationField> ConferenceApplicationFields { get; set; }
 157
 25158        public DbSet<ConferencePageColorScheme> ConferencePageColorSchemes { get; set; }
 159
 160
 25161        public DbSet<UserNotification> UserNotifications { get; set; }
 162
 25163        public DbSet<UserNotificationCategory> UserNotificationCategories { get; set; }
 164
 25165        public DbSet<School> Schools { get; set; }
 166
 25167        public DbSet<UserInSchool> UsersInSchools { get; set; }
 168
 26169        public DbSet<ConferenceDashboardCard> ConferenceDashboardCards { get; set; }
 170
 29171        public DbSet<ConferenceWebMenuEntry> ConferenceWebMenuEntries { get; set; }
 172
 25173        public DbSet<CommitteeDelegatesElement> ConferenceWebPageDelegatesElements { get; set; }
 174
 25175        public DbSet<CommitteeTopicsElement> ConferenceWebPageCommitteeTopicsElements { get; set; }
 176
 25177        public DbSet<TeamCardsElement> ConferenceWebPageTeamCardsElements { get; set; }
 178
 25179        public DbSet<WebPageTextElement> ConferenceWebPageTextElements { get; set; }
 180
 25181        public DbSet<ConferenceRegisterElement> ConferenceWebPageRegisterElements { get; set; }
 182
 25183        public DbSet<ConferenceWebsiteFooter> ConferenceWebsiteFooters { get; set; }
 184
 25185        public DbSet<UserFriend> UserFriends { get; set; }
 186
 25187        public DbSet<UserBlocked> UserBlockedUsers { get; set; }
 188
 189        protected override void OnModelCreating(ModelBuilder modelBuilder)
 8190        {
 8191            base.OnModelCreating(modelBuilder);
 192
 8193            modelBuilder.Entity<Country>().HasMany(n => n.Translations)
 8194                .WithOne(n => n.Country)
 8195                .OnDelete(DeleteBehavior.Cascade);
 196
 197
 198
 8199            modelBuilder.Entity<CountryNameTranslation>()
 8200                .HasKey(n => new {n.CountryId, n.LanguageCode});
 201
 8202            modelBuilder.Entity<MunityUser>().HasKey(n => n.Id);
 203
 8204            modelBuilder.Entity<MunityUser>().HasMany(n => n.CreatedResolutions).WithOne(a => a.CreationUser).IsRequired
 205
 8206            modelBuilder.Entity<OrganizationRole>()
 8207                .HasOne(n => n.Organization)
 8208                .WithMany(a => a.Roles);
 209
 8210            modelBuilder.Entity<OrganizationMember>()
 8211                .HasOne(n => n.Organization)
 8212                .WithMany(n => n.Member);
 213
 8214            modelBuilder.Entity<OrganizationRole>()
 8215                .HasMany(n => n.MembersWithRole)
 8216                .WithOne(n => n.Role);
 217
 8218            modelBuilder.Entity<Project>()
 8219                .HasOne(n => n.ProjectOrganization)
 8220                .WithMany(n => n.Projects)
 8221                .IsRequired();
 222
 223
 224            // Conference
 8225            modelBuilder.Entity<Conference>().HasOne(n => n.ConferenceProject)
 8226                .WithMany(n => n.Conferences);
 227
 228
 8229            modelBuilder.Entity<AbstractConferenceRole>().HasOne(n => n.Conference).WithMany(n => n.Roles);
 230
 8231            modelBuilder.Entity<AbstractConferenceRole>().HasDiscriminator(n => n.RoleType)
 8232                .HasValue<ConferenceDelegateRole>("DelegateRole")
 8233                .HasValue<ConferenceSecretaryGeneralRole>("SecretaryGeneralRole")
 8234                .HasValue<ConferenceTeamRole>("TeamRole")
 8235                .HasValue<ConferenceVisitorRole>("VisitorRole");
 236
 8237            modelBuilder.Entity<AbstractConferenceRole>().HasMany(n => n.Participations)
 8238                .WithOne(n => n.Role);
 239
 8240            modelBuilder.Entity<ConferenceTeamRole>().HasOne(n => n.TeamRoleGroup).WithMany(n => n.TeamRoles);
 241
 242
 8243            modelBuilder.Entity<Committee>().HasMany(n => n.Sessions).WithOne(n =>
 8244                n.Committee);
 245
 8246            modelBuilder.Entity<Committee>().HasOne(n => n.Conference)
 8247                .WithMany(a => a.Committees).OnDelete(DeleteBehavior.Cascade);
 248
 8249            modelBuilder.Entity<Committee>().HasMany(n => n.Resolutions)
 8250                .WithOne(a => a.Committee).IsRequired(false);
 251
 8252            modelBuilder.Entity<Committee>().HasOne(n => n.ResolutlyCommittee)
 8253                .WithMany(n => n.ChildCommittees).IsRequired(false);
 254
 8255            modelBuilder.Entity<Delegation>()
 8256                .HasOne(n => n.ParentDelegation)
 8257                .WithMany(a => a.ChildDelegations)
 8258                .OnDelete(DeleteBehavior.SetNull);
 259
 260
 261            //modelBuilder.Entity<SimulationUser>().HasOne(n => n.Simulation).WithMany(n =>
 262            //    n.Users);
 263
 8264            modelBuilder.Entity<ListOfSpeakers>().HasMany(n => n.AllSpeakers).WithOne(n => n.ListOfSpeakers);
 265
 8266            modelBuilder.Entity<Speaker>().HasKey(n => n.Id);
 267
 268            // Resolution
 8269            modelBuilder.Entity<ResolutionAuth>()
 8270                .HasMany(n => n.Users).WithOne(n => n.Auth);
 271
 272
 8273            modelBuilder.Entity<ResolutionAuth>()
 8274                .HasOne(n => n.Simulation)
 8275                .WithMany(n => n.Resolutions);
 276
 8277            modelBuilder.Entity<ResaElement>()
 8278                .HasMany(n => n.PreambleParagraphs)
 8279                .WithOne(n => n.ResaElement)
 8280                .IsRequired();
 281
 8282            modelBuilder.Entity<ResaElement>()
 8283                .HasMany(n => n.OperativeParagraphs)
 8284                .WithOne(n => n.Resolution)
 8285                .IsRequired();
 286
 8287            modelBuilder.Entity<ResaElement>()
 8288                .HasOne(n => n.Authorization)
 8289                .WithOne(n => n.Resolution)
 8290                .IsRequired()
 8291                .OnDelete(DeleteBehavior.Cascade);
 292
 8293            modelBuilder.Entity<ResaOperativeParagraph>()
 8294                .HasOne(n => n.Parent)
 8295                .WithMany(n => n.Children)
 8296                .IsRequired(false)
 8297                .OnDelete(DeleteBehavior.Cascade);
 298
 8299            modelBuilder.Entity<ResaOperativeParagraph>()
 8300                .HasMany(n => n.DeleteAmendments)
 8301                .WithOne(n => n.TargetParagraph)
 8302                .IsRequired();
 303
 8304            modelBuilder.Entity<ResaOperativeParagraph>()
 8305                .HasMany(n => n.ChangeAmendments)
 8306                .WithOne(n => n.TargetParagraph)
 8307                .IsRequired();
 308
 8309            modelBuilder.Entity<ResaOperativeParagraph>()
 8310                .HasMany(n => n.MoveAmendments)
 8311                .WithOne(n => n.SourceParagraph)
 8312                .IsRequired();
 313
 8314            modelBuilder.Entity<ResaElement>()
 8315                .HasMany(n => n.AddAmendments)
 8316                .WithOne(n => n.Resolution);
 317
 318            // Simulations
 8319            modelBuilder.Entity<SimulationRole>().HasOne(n => n.Simulation).WithMany(n =>
 8320                n.Roles);
 321
 8322            modelBuilder.Entity<Simulation>().HasMany(n => n.Users).WithOne(n => n.Simulation);
 323
 324
 8325            modelBuilder.Entity<SimulationPresents>()
 8326                .HasMany(n => n.CheckedUsers)
 8327                .WithOne(n => n.SimulationPresents);
 328
 8329            modelBuilder.Entity<Simulation>().HasMany(n => n.PresentChecks).WithOne(n => n.Simulation);
 8330        }
 331
 25332        public MunityContext(DbContextOptions<MunityContext> options) : base(options)
 25333        {
 25334            this.Fluent = new FluentProvider(this);
 25335        }
 336
 337        public override int SaveChanges()
 149338        {
 149339            ChangeTracker.DetectChanges();
 340
 51266341            var markedAsDeleted = ChangeTracker.Entries().Where(x => x.State == EntityState.Deleted);
 342
 489343            foreach (var item in markedAsDeleted)
 21344            {
 21345                if (item.Entity is IIsDeleted entity)
 3346                {
 347                    // Set the entity to unchanged (if we mark the whole entity as Modified, every field gets sent to Db
 3348                    item.State = EntityState.Unchanged;
 349                    // Only update the IsDeleted flag - only this will get sent to the Db
 3350                    entity.IsDeleted = true;
 3351                }
 21352            }
 353
 149354            HandleEasyId();
 355
 356
 149357            return base.SaveChanges();
 149358        }
 359
 360        private void HandleEasyId()
 165361        {
 56344362            var markedAsNew = ChangeTracker.Entries().Where(x => x.State == EntityState.Added);
 3183363            foreach (var entityEntry in markedAsNew)
 1344364            {
 1344365                switch (entityEntry.Entity)
 366                {
 367                    case Organization organization:
 15368                        HandleEasyIdOrganization(organization);
 15369                        break;
 370                    case Project project:
 9371                        HandleEasyIdProject(project);
 9372                        break;
 373                    case Conference conference:
 8374                        HandleEasyIdConference(conference);
 8375                        break;
 376                    case Committee committee:
 14377                        HandleEasyIdCommittee(committee);
 14378                        break;
 379                    case Delegation delegation:
 39380                        HandleEasyDelegationId(delegation);
 39381                        break;
 382                }
 1344383            }
 165384        }
 385
 386
 387
 388        private void HandleEasyIdOrganization(Organization organization)
 15389        {
 16390            if (!string.IsNullOrWhiteSpace(organization.OrganizationId)) return;
 391
 14392            if (string.IsNullOrWhiteSpace(organization.OrganizationShort))
 4393            {
 4394                organization.OrganizationId = Guid.NewGuid().ToString();
 4395                return;
 396            }
 397
 10398            var easyId = Util.IdGenerator.AsPrimaryKey(organization.OrganizationShort);
 10399            if (string.IsNullOrWhiteSpace(easyId)) return;
 400
 10401            if (Organizations.All(n => n.OrganizationId != easyId))
 10402                organization.OrganizationId = easyId;
 403            else
 0404                organization.OrganizationId = Guid.NewGuid().ToString();
 405
 15406        }
 407
 408        private void HandleEasyIdProject(Project project)
 9409        {
 9410            if (!string.IsNullOrWhiteSpace(project.ProjectId)) return;
 411
 9412            if (string.IsNullOrWhiteSpace(project.ProjectShort))
 1413            {
 1414                project.ProjectId = Guid.NewGuid().ToString();
 1415                return;
 416            }
 417
 8418            var easyId = Util.IdGenerator.AsPrimaryKey(project.ProjectShort);
 8419            if (string.IsNullOrWhiteSpace(easyId)) return;
 420
 8421            if (Projects.All(n => n.ProjectId != easyId))
 8422                project.ProjectId = easyId;
 423            else
 0424                project.ProjectId = Guid.NewGuid().ToString();
 9425        }
 426
 427        private void HandleEasyIdConference(Conference conference)
 8428        {
 8429            if (!string.IsNullOrWhiteSpace(conference.ConferenceId)) return;
 430
 8431            if (string.IsNullOrWhiteSpace(conference.ConferenceShort))
 0432            {
 0433                conference.ConferenceId = Guid.NewGuid().ToString();
 0434                return;
 435            }
 436
 8437            var easyId = Util.IdGenerator.AsPrimaryKey(conference.ConferenceShort);
 8438            if (string.IsNullOrWhiteSpace(easyId)) return;
 439
 8440            if (Conferences.All(n => n.ConferenceId != easyId))
 8441                conference.ConferenceId = easyId;
 442            else
 0443                conference.ConferenceId = Guid.NewGuid().ToString();
 8444        }
 445
 446        private void HandleEasyIdCommittee(Committee committee)
 14447        {
 22448            if (!string.IsNullOrWhiteSpace(committee.CommitteeId)) return;
 449
 6450            if (committee.Conference == null || string.IsNullOrEmpty(committee.CommitteeShort))
 2451            {
 2452                committee.CommitteeId = Guid.NewGuid().ToString();
 2453                return;
 454            }
 455
 4456            var committeeEasy = Util.IdGenerator.AsPrimaryKey(committee.CommitteeShort);
 4457            if (string.IsNullOrWhiteSpace(committeeEasy)) return;
 458
 4459            var easyCommitteeId = committee.Conference.ConferenceId + "-" +
 4460                                  committeeEasy;
 461
 4462            if (this.Committees.All(n => n.CommitteeId != easyCommitteeId))
 4463                committee.CommitteeId = easyCommitteeId;
 464            else
 0465                committee.CommitteeId = Guid.NewGuid().ToString();
 14466        }
 467
 468        private void HandleEasyDelegationId(Delegation delegation)
 39469        {
 39470            if (!string.IsNullOrWhiteSpace(delegation.DelegationId)) return;
 471
 39472            if (delegation.Conference == null || string.IsNullOrWhiteSpace(delegation.Name))
 0473            {
 0474                delegation.DelegationId = Guid.NewGuid().ToString();
 0475                return;
 476            }
 477
 39478            var easyNameDelegation = Util.IdGenerator.AsPrimaryKey(delegation.Name);
 39479            var easyId = delegation.Conference.ConferenceId + "-" + easyNameDelegation;
 676480            if (this.Delegations.All(n => n.DelegationId != easyId) && this.ChangeTracker.Entries<Delegation>().All(n =>
 39481            {
 39482                Debug.WriteLine($"Assigning EasyId to Delegation {delegation.Name}: {easyId}");
 39483                delegation.DelegationId = easyId;
 484
 39485            }
 486            else
 0487                delegation.DelegationId = Guid.NewGuid().ToString();
 488
 489
 39490        }
 491
 492        /// <summary>
 493        /// Saves the Database Changes but ignores all elements that are protected by soft-deletion.
 494        /// This will completely remove these elements
 495        /// </summary>
 496        /// <returns></returns>
 497        public int SaveChangesWithoutSoftDelete()
 1498        {
 1499            return base.SaveChanges();
 1500        }
 501
 502        /// <summary>
 503        /// Saves the Database Changes but ignores all elements that are protected by soft-deletion.
 504        /// This will completely remove these elements
 505        /// </summary>
 506        /// <returns></returns>
 507        public Task<int> SaveChangesWithoutSoftDeleteAsync()
 0508        {
 0509            return base.SaveChangesAsync();
 0510        }
 511
 512        public override Task<int> SaveChangesAsync(CancellationToken cancellationToken = new CancellationToken())
 16513        {
 16514            ChangeTracker.DetectChanges();
 5078515            var markedAsDeleted = ChangeTracker.Entries().Where(x => x.State == EntityState.Deleted);
 516
 50517            foreach (var item in markedAsDeleted)
 1518            {
 1519                if (item.Entity is IIsDeleted entity)
 1520                {
 521                    // Set the entity to unchanged (if we mark the whole entity as Modified, every field gets sent to Db
 1522                    item.State = EntityState.Unchanged;
 523                    // Only update the IsDeleted flag - only this will get sent to the Db
 1524                    entity.IsDeleted = true;
 1525                }
 1526            }
 527
 16528            HandleEasyId();
 529
 16530            return base.SaveChangesAsync(cancellationToken);
 16531        }
 532
 533        public static MunityContext FromSqlLite(string databaseName)
 5534        {
 5535            var optionsBuilder = new DbContextOptionsBuilder<MunityContext>();
 5536            optionsBuilder.UseSqlite($"Data Source={databaseName}.db");
 537            //optionsBuilder.EnableSensitiveDataLogging();
 538            //optionsBuilder.LogTo(Console.WriteLine);
 5539            var context = new MunityContext(optionsBuilder.Options);
 5540            context.Database.EnsureCreated();
 5541            return context;
 5542        }
 543
 544    }
 545}

Methods/Properties

get_Fluent()
get_Countries()
get_CountryNameTranslations()
get_Organizations()
get_OrganizationRoles()
get_OrganizationMembers()
get_Projects()
get_Committees()
get_Delegations()
get_Delegates()
get_ConferenceTeamRoles()
get_SecretaryGenerals()
get_Conferences()
get_ConferenceParticipationCostRules()
get_CommitteeTopics()
get_AttendanceStates()
get_AttendanceChecks()
get_CommitteeSessions()
get_Participations()
get_ConferenceRoleAuthorizations()
get_RoleApplications()
get_DelegationApplications()
get_DelegationApplicationUserEntries()
get_DelegationApplicationPickedDelegations()
get_ConferenceDelegationApplicationFieldInputs()
get_FillApplications()
get_ConferenceFillApplicationFieldInputs()
get_TeamRoleGroups()
get_ResolutionAuths()
get_ResolutionUsers()
get_ListOfSpeakers()
get_Speakers()
get_ListOfSpeakersLogs()
get_Settings()
get_Resolutions()
get_PreambleParagraphs()
get_OperativeParagraphs()
get_ResolutionSupporters()
get_ResolutionDeleteAmendments()
get_ResolutionChangeAmendments()
get_ResolutionMoveAmendments()
get_ResolutionAddAmendments()
get_ConferenceWebPages()
get_ConferenceApplicationOptions()
get_ConferenceApplicationFormulas()
get_ConferenceApplicationFields()
get_ConferencePageColorSchemes()
get_UserNotifications()
get_UserNotificationCategories()
get_Schools()
get_UsersInSchools()
get_ConferenceDashboardCards()
get_ConferenceWebMenuEntries()
get_ConferenceWebPageDelegatesElements()
get_ConferenceWebPageCommitteeTopicsElements()
get_ConferenceWebPageTeamCardsElements()
get_ConferenceWebPageTextElements()
get_ConferenceWebPageRegisterElements()
get_ConferenceWebsiteFooters()
get_UserFriends()
get_UserBlockedUsers()
OnModelCreating(...)
.ctor(...)
SaveChanges()
HandleEasyId()
HandleEasyIdOrganization(...)
HandleEasyIdProject(...)
HandleEasyIdConference(...)
HandleEasyIdCommittee(...)
HandleEasyDelegationId(...)
SaveChangesWithoutSoftDelete()
SaveChangesWithoutSoftDeleteAsync()
SaveChangesAsync(...)
FromSqlLite(...)