/// <summary> /// Adds a territory to the Planet /// x and y are bound to between 0 and column(x)/Rows(y) /// If location is taken, it returns false. /// </summary> /// <param name="x"/> /// <param name="y"/> /// <param name="terr">The territory to add.</param> /// <param name="context">The context of the planet.</param> public bool AddTerritoryToLocation(int x, int y, Territory terr, EconSimContext context) { // if the location is already taken, return false. if (Territories.Any(t => t.X == x && t.Y == y && t.Z == HexZ(x, y))) { return(false); } // it's not taken, so add it. terr.PlanetId = Id; Territories.Add(terr); context.Territories.AddOrUpdate(terr); context.SaveChanges(); return(true); }