public static Faction PerformLeaveFaction(int accountID, bool keepClan = false, ZkDataContext db = null) { if (db == null) { db = new ZkDataContext(); } Account acc = db.Accounts.Single(x => x.AccountID == Global.AccountID); Faction faction = acc.Faction; if (!keepClan && acc.Clan != null) { ClansController.PerformLeaveClan(Global.AccountID); } db.AccountRoles.DeleteAllOnSubmit(acc.AccountRolesByAccountID.Where(x => !keepClan || x.ClanID == null)); acc.ResetQuotas(); foreach (var ps in acc.PlanetStructures) { ps.OwnerAccountID = null; } foreach (var planet in acc.Planets) { planet.OwnerAccountID = null; } // delete channel subscription if (!acc.IsZeroKAdmin || acc.IsZeroKAdmin) { var channelSub = db.LobbyChannelSubscriptions.FirstOrDefault(x => x.Account == acc && x.Channel == acc.Faction.Name); db.LobbyChannelSubscriptions.DeleteOnSubmit(channelSub); } db.Events.InsertOnSubmit(Global.CreateEvent("{0} leaves faction {1}", acc, acc.Faction)); db.SubmitChanges(); PlanetwarsController.SetPlanetOwners(db); using (var db2 = new ZkDataContext()) { Account acc2 = db2.Accounts.Single(x => x.AccountID == Global.AccountID); acc2.FactionID = null; db2.SubmitAndMergeChanges(); PlanetwarsController.SetPlanetOwners(db2); } return(faction); }
public static Faction PerformLeaveFaction(int accountID, bool keepClan = false, ZkDataContext db = null) { if (db == null) { db = new ZkDataContext(); } Account acc = db.Accounts.Single(x => x.AccountID == Global.AccountID); Faction faction = acc.Faction; if (!keepClan && acc.Clan != null) { ClansController.PerformLeaveClan(Global.AccountID); } db.AccountRoles.DeleteAllOnSubmit(acc.AccountRolesByAccountID.Where(x => !keepClan || x.ClanID == null).ToList()); acc.ResetQuotas(); foreach (var ps in acc.PlanetStructures) { ps.OwnerAccountID = null; } foreach (var planet in acc.Planets) { planet.OwnerAccountID = null; } db.Events.InsertOnSubmit(PlanetwarsEventCreator.CreateEvent("{0} leaves faction {1}", acc, acc.Faction)); db.SaveChanges(); PlanetWarsTurnHandler.SetPlanetOwners(new PlanetwarsEventCreator(), db); using (var db2 = new ZkDataContext()) { Account acc2 = db2.Accounts.Single(x => x.AccountID == Global.AccountID); acc2.FactionID = null; db2.SaveChanges(); Global.Server.PublishAccountUpdate(acc2); Global.Server.PublishUserProfileUpdate(acc2); PlanetWarsTurnHandler.SetPlanetOwners(new PlanetwarsEventCreator(), db2); } return(faction); }