/// <summary> /// Creates a new ship in the DB. /// </summary> /// <param name="ship"></param> /// <returns>bool</returns> public bool CreateShip(db_Ship ship) { try { _context.MySqlDb.Query <db_Ship>("INSERT INTO ship (board_id, ship_type_id, is_placed) VALUES (" + ship.Board_Id + ", " + ship.Ship_Type_Id + ", " + ship.Is_Placed + ");", commandType: CommandType.Text); return(true); } catch (MySqlException mysqlex) { Debug.WriteLine("MYSQL EXCEPTION IN CreateShip"); Debug.WriteLine(mysqlex.InnerException); return(false); } catch (InvalidOperationException ioe) { Debug.WriteLine("INVALID OPERATION EXCEPTION IN CreateShip"); Debug.WriteLine(ioe.InnerException); return(false); } catch (Exception e) { Debug.WriteLine("EXCEPTION IN CreateShip"); Debug.WriteLine(e.InnerException); return(false); } }
public bool MakeStartingShips(int boardId) { var carrier = new db_Ship() { Board_Id = boardId, Ship_Type_Id = 1, Is_Placed = 0, Is_Sunk = 0 }; var battleship = new db_Ship() { Board_Id = boardId, Ship_Type_Id = 2, Is_Placed = 0, Is_Sunk = 0 }; var submarine = new db_Ship() { Board_Id = boardId, Ship_Type_Id = 3, Is_Placed = 0, Is_Sunk = 0 }; var cruiser = new db_Ship() { Board_Id = boardId, Ship_Type_Id = 4, Is_Placed = 0, Is_Sunk = 0 }; var destroyer = new db_Ship() { Board_Id = boardId, Ship_Type_Id = 5, Is_Placed = 0, Is_Sunk = 0 }; return(_shipRepo.CreateShip(carrier) && _shipRepo.CreateShip(battleship) && _shipRepo.CreateShip(submarine) && _shipRepo.CreateShip(cruiser) && _shipRepo.CreateShip(destroyer)); }