public static bool PurchaseBuilding(int currencyRequired, int populationNeeded, Structure.StructureType strucureType) { IronTowerDBContext db = new IronTowerDBContext(); Game game = db.Games.FirstOrDefault(); if (game.TotalBalance < currencyRequired) { return(false); } if (game.TotalPopulation(game) - game.ConsumedPopulation(game) < populationNeeded) { return(false); } game.TotalBalance -= currencyRequired; Structure structure = new Structure(strucureType, game.TotalFloors(game) + 1); game.Structures.Add(structure); game.PeriodicRevenue += structure.Income; db.SaveChanges(); return(true); }