public static void DeleteToon(Toon toon) { if (toon == null) { return; } //remove toonActiveSkills if (toon.DBToon.DBActiveSkills != null) { DBSessions.AccountSession.Delete(toon.DBToon.DBActiveSkills); toon.DBToon.DBActiveSkills = null; } //remove toon inventory var inventoryToDelete = DBSessions.AccountSession.Query <DBInventory>().Where(inv => inv.DBToon.Id == toon.DBToon.Id); foreach (var inv in inventoryToDelete) { //toon.DBToon.DBGameAccount.DBInventories.Remove(inv); DBSessions.AccountSession.Delete(inv); } //remove lastplayed hero if it was toon if (toon.DBToon.DBGameAccount.LastPlayedHero != null && toon.DBToon.DBGameAccount.LastPlayedHero.Id == toon.DBToon.Id) { toon.DBToon.DBGameAccount.LastPlayedHero = null; } //remove toon from dbgameaccount while (toon.DBToon.DBGameAccount.DBToons.Contains(toon.DBToon)) { toon.DBToon.DBGameAccount.DBToons.Remove(toon.DBToon); } //save all this thinks DBSessions.AccountSession.SaveOrUpdate(toon.DBToon.DBGameAccount); DBSessions.AccountSession.Delete(toon.DBToon); DBSessions.AccountSession.Flush(); //remove toon from loadedToon list if (LoadedToons.Contains(toon)) { LoadedToons.Remove(toon); } Logger.Debug("Deleting toon {0}", toon.PersistentID); }
public static void SaveToDB(Toon toon) { try { // save character base data var dbToon = DBSessions.AccountSession.Get <DBToon>(toon.PersistentID); dbToon.Name = toon.Name; /*dbToon.HashCode = toon.HashCode;*/ dbToon.Class = toon.Class; dbToon.Flags = toon.Flags; dbToon.Level = toon.Level; dbToon.Experience = toon.ExperienceNext; dbToon.DBGameAccount = DBSessions.AccountSession.Get <DBGameAccount>(toon.GameAccount.PersistentID); dbToon.TimePlayed = toon.TimePlayed; dbToon.Deleted = toon.Deleted; DBSessions.AccountSession.SaveOrUpdate(dbToon); DBSessions.AccountSession.Flush(); } catch (Exception e) { Logger.ErrorException(e, "Toon.SaveToDB()"); } }