public IHttpActionResult GetBuildingTypes(int PlanetID) { try { return(Ok(PlanetDAL.GetBuildingTypes(PlanetID))); } catch (Exception e) { return(InternalServerError(e)); } }
public static PlanetDetail AddBuildingQueue(BuildingQue buildingQue) { List <PlanetBuildings> buildings = PlanetDAL.GetBuildingTypes(buildingQue.PlanetID); PlanetBuildings pb = buildings.Find(x => x.BuildingID == buildingQue.BuildingID); PlanetDetail pl = PlanetDAL.GetPlanet(buildingQue.PlanetID, buildingQue.UserID); if (pl.Materials < buildingQue.MaterialCost || pl.Population < pb.PopulationCost) { throw new Exception("Not enough resources"); } else { PlanetDAL.UpdatePopAndMats(buildingQue.PlanetID, pl.Materials - buildingQue.MaterialCost, pl.Population - (int)pb.PopulationCost.Value, pl.Military); pl.Materials -= buildingQue.MaterialCost; pl.Population -= (int)pb.PopulationCost.Value; } AllbuildQues BuildingsQueLeft = GetBuildingQueue(buildingQue.PlanetID, buildingQue.UserID); DateTime UTC = DateTime.UtcNow; BuildingQue bq = new BuildingQue(); bq.BuildingID = buildingQue.BuildingID; bq.PlanetID = buildingQue.PlanetID; bq.Seconds = buildingQue.Seconds; bq.UserID = buildingQue.UserID; bq.MaterialCost = buildingQue.MaterialCost; bq.Type = 1; DateTime?maxCompletetionDate = BuildingsQueLeft.buildingQue.FindAll(x => x.Type == 1).Max(x => x.CompletetionDate); if (maxCompletetionDate.HasValue) { bq.CompletetionDate = maxCompletetionDate.Value.AddSeconds(buildingQue.Seconds.Value); } else { bq.CompletetionDate = UTC.AddSeconds(buildingQue.Seconds.Value); } PlanetDAL.AddBuildingQue(bq); return(pl); }