public virtual void Save(ORM.Database database) { lock (Locker) { foreach (var item in Items.Where(item => !item.Value.IsTemporarily)) { if (item.Value.Record.IsNew) { database.Insert(item.Value.Record); item.Value.OnPersistantItemAdded(); item.Value.Record.IsNew = false; } else if (item.Value.Record.IsDirty) { database.Update(item.Value.Record); item.Value.OnPersistantItemUpdated(); } } while (ItemsToDelete.Count > 0) { var item = ItemsToDelete.Dequeue(); database.Delete(item.Record); item.OnPersistantItemDeleted(); } } }
public void Save(ORM.Database database, bool updateAccount) { lock (Locker) { foreach (var item in Items.Where(item => Tokens == null || item.Value != Tokens).Where(item => !item.Value.IsTemporarily)) { if (item.Value.Record.IsNew) { database.Insert(item.Value.Record); item.Value.OnPersistantItemAdded(); item.Value.Record.IsNew = false; } else if (item.Value.Record.IsDirty) { database.Update(item.Value.Record); item.Value.OnPersistantItemUpdated(); } } foreach (var preset in Presets) { if (preset.IsNew) { database.Insert(preset); preset.IsNew = false; } else if (preset.IsDirty) { database.Update(preset); } } while (ItemsToDelete.Count > 0) { var item = ItemsToDelete.Dequeue(); database.Delete(item.Record); item.OnPersistantItemDeleted(); } while (PresetsToDelete.Count > 0) { var preset = PresetsToDelete.Dequeue(); database.Delete(preset); } Owner.WorldAccount.Tokens = Tokens == null ? 0 : (int)Tokens.Stack; if (updateAccount) { database.Update(Owner.WorldAccount); } } }