public IHttpActionResult GetShipDesignbyUser(int UserID)
 {
     try
     {
         return(Ok(ShipDAL.GetShipDesignbyUser(UserID)));;
     }
     catch (Exception e)
     {
         return(InternalServerError(e));
     }
 }
Exemplo n.º 2
0
        public static PlanetDetail AddShipQueue(BuildingQue buildingQue)
        {
            PlanetDetail pl   = PlanetDAL.GetPlanet(buildingQue.PlanetID, buildingQue.UserID);
            UserDesigns  ship = ShipDAL.GetShipDesignbyUser(buildingQue.UserID).Find(x => x.ShipDesignID == buildingQue.BuildingID);

            if (pl.Materials < ship.MaterialCost || pl.Military < ship.MilitaryCost)
            {
                throw new Exception("Not enough resources");
            }
            else
            {
                PlanetDAL.UpdatePopAndMats(buildingQue.PlanetID, pl.Materials - buildingQue.MaterialCost, pl.Population, pl.Military - (int)ship.MilitaryCost.Value);
                pl.Materials -= buildingQue.MaterialCost;
                pl.Military  -= (int)ship.MilitaryCost.Value;
            }


            AllbuildQues BuildingsQueLeft = PlanetBLL.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.Movement     = buildingQue.Movement;
            bq.Type         = 3;

            DateTime?maxCompletetionDate = BuildingsQueLeft.shipQue.FindAll(x => x.Type == 3).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);
        }