Пример #1
0
        protected void UpdateFreezes <ACCOUNT_SNAPSHOT_ENTRY, ACCOUNT_FREEZE_SNAPSHOT_ENTRY>(ACCOUNT_SNAPSHOT_ENTRY snapshot, AccountId accountId, DbSet <ACCOUNT_FREEZE_SNAPSHOT_ENTRY> freezes)
            where ACCOUNT_SNAPSHOT_ENTRY : INeuraliumAccountSnapshot <ACCOUNT_FREEZE_SNAPSHOT_ENTRY>
            where ACCOUNT_FREEZE_SNAPSHOT_ENTRY : class, INeuraliumAccountFreezeEntry
        {
            var existingFreezes = this.QueryDbSetEntityEntries(freezes, a => a.AccountId == accountId.ToLongRepresentation());

            var snapshotFreezes = snapshot.AccountFreezes.ToList();

            var certificateIds       = existingFreezes.Select(a => a.FreezeId).ToList();
            var snapshotCertificates = snapshotFreezes.Select(a => a.FreezeId).ToList();

            // build the delta
            var newFreezes    = snapshotFreezes.Where(a => !certificateIds.Contains(a.FreezeId)).ToList();
            var modifyFreezes = snapshotFreezes.Where(a => certificateIds.Contains(a.FreezeId)).ToList();
            var removeFreezes = existingFreezes.Where(a => !snapshotCertificates.Contains(a.FreezeId)).ToList();

            foreach (ACCOUNT_FREEZE_SNAPSHOT_ENTRY attribute in newFreezes)
            {
                freezes.Add(attribute);
            }

            foreach (ACCOUNT_FREEZE_SNAPSHOT_ENTRY freeze in modifyFreezes)
            {
                ACCOUNT_FREEZE_SNAPSHOT_ENTRY dbEntry = existingFreezes.Single(a => a.FreezeId == freeze.FreezeId);
                this.GetNeuraliumCardUtils().Copy(freeze, dbEntry);
            }

            foreach (ACCOUNT_FREEZE_SNAPSHOT_ENTRY attribute in removeFreezes)
            {
                freezes.Remove(attribute);
            }
        }