public static Fleet CreateFleet(string playerName, string password, int bodyID, IEnumerable<ShipTypeCount> fleetShips) { using (var t = new TransactionScope()) { var db = new DbDataContext(); var player = db.GetPlayer(playerName, password); var body = player.CelestialObjects.Single(x => x.CelestialObjectID == bodyID); var fleet = new Fleet(); fleet.Transit = new Transit(); fleet.Transit.OrbitsObjectID = bodyID; foreach (var order in fleetShips) { var garrisonCount = body.GetShipCount(order.ShipTypeID); if (order.Count > garrisonCount) throw new ApplicationException(string.Format("Not enough ships of type {0}", order.ShipTypeID)); body.SetShipCount(order.ShipTypeID, garrisonCount - order.Count); fleet.SetShipCount(order.ShipTypeID, order.Count); } player.Fleets.Add(fleet); db.MarkDirty(); db.SubmitChanges(); fleet.FleetShips.Load(); t.Complete(); return fleet; } }
partial void DeleteFleet(Fleet instance);
partial void UpdateFleet(Fleet instance);
partial void InsertFleet(Fleet instance);
private void detach_Fleets(Fleet entity) { this.SendPropertyChanging(); entity.Transit = null; }
private void attach_Fleets(Fleet entity) { this.SendPropertyChanging(); entity.Transit = this; }
private void detach_Fleets(Fleet entity) { this.SendPropertyChanging(); entity.CelestialObject = null; }
private void attach_Fleets(Fleet entity) { this.SendPropertyChanging(); entity.Player = this; }