예제 #1
0
            static async Task <(int Count, string Message, Meeting?Entity)> UpdateExisting(ModulesDbContext dbContext, Meeting entity, Meeting existing)
            {
                dbContext.Entry(existing).CurrentValues.SetValues(entity);
                AddOrRemoveLayouts(dbContext, entity, existing);
                if (IsUnchanged(dbContext, existing))
                {
                    return((-1).SaveResult(existing));
                }
                var result = await dbContext.SaveChangesAsync();

                return(result.SaveResult(existing));
            }
        static async Task <(int Count, string Message, Module?Entity)> UpdateExisting(ModulesDbContext dbContext, Module entity, Module existing)
        {
            if (await IfStationWillHaveNoReferringModules(dbContext, entity, existing))
            {
                return(Strings.StationMustHaveAtLeastOneModuleReferringToIt.SaveResult(entity));
            }
            dbContext.Entry(existing).CurrentValues.SetValues(entity);
            AddOrRemoveExits(dbContext, entity, existing);
            if (IsUnchanged(dbContext, existing))
            {
                return((-1).SaveResult(existing));
            }
            var result = await dbContext.SaveChangesAsync();

            return(result.SaveResult(existing));
예제 #3
0
        static async Task <(int Count, string Message, Meeting?Entity)> UpdateExisting(ModulesDbContext dbContext, Meeting entity, Meeting existing)
        {
            if (IsMovedTooFarInTime(existing, entity))
            {
                return(0, "MeetingDatesCannotBeChanged", entity);
            }
            dbContext.Entry(existing).CurrentValues.SetValues(entity);
            AddOrRemoveLayouts(dbContext, entity, existing);
            if (IsUnchanged(dbContext, existing))
            {
                return((-1).SaveResult(existing));
            }
            var result = await dbContext.SaveChangesAsync().ConfigureAwait(false);

            return(result.SaveResult(existing));
        }
예제 #4
0
 static void AddOrRemoveLayouts(ModulesDbContext dbContext, Meeting entity, Meeting existing)
 {
     foreach (var layout in entity.Layouts)
     {
         var existingGable = existing.Layouts.AsQueryable().FirstOrDefault(g => g.Id == layout.Id);
         if (existingGable is null)
         {
             existing.Layouts.Add(layout);
         }
         else
         {
             dbContext.Entry(existingGable).CurrentValues.SetValues(layout);
         }
     }
     foreach (var gable in existing.Layouts)
     {
         if (!entity.Layouts.Any(mg => mg.Id == gable.Id))
         {
             dbContext.Remove(gable);
         }
     }
 }
            static void AddOrRemoveExits(ModulesDbContext dbContext, Module entity, Module existing)
            {
                foreach (var exit in entity.ModuleExits)
                {
                    var existingExit = existing.ModuleExits.AsQueryable().FirstOrDefault(g => g.Id == exit.Id);

                    if (existingExit is null)
                    {
                        existing.ModuleExits.Add(exit);
                    }
                    else
                    {
                        dbContext.Entry(existingExit).CurrentValues.SetValues(exit);
                    }
                }
                foreach (var exit in existing.ModuleExits)
                {
                    if (!entity.ModuleExits.Any(mg => mg.Id == exit.Id))
                    {
                        dbContext.Remove(exit);
                    }
                }
            }
예제 #6
0
 static bool IsUnchanged(ModulesDbContext dbContext, Meeting entity) =>
 dbContext.Entry(entity).State == EntityState.Unchanged &&
 entity.Layouts.All(mg => dbContext.Entry(mg).State == EntityState.Unchanged);
 static bool IsUnchanged(ModulesDbContext dbContext, Module entity) =>
 dbContext.Entry(entity).State == EntityState.Unchanged &&
 entity.ModuleExits.All(mg => dbContext.Entry(mg).State == EntityState.Unchanged) &&
 entity.ModuleOwnerships.All(mo => dbContext.Entry(mo).State == EntityState.Unchanged);