/// <summary> /// Delete a row representing a board action from the database. /// </summary> /// <param name="boardActionId">The board action Id</param> /// <returns>True if the delete was successful</returns> public bool DeleteBoardAction(long boardActionId) { int entitiesDeleted; using (Bol_Model_DBEntities ctx = new Bol_Model_DBEntities()) { BoardAction bda = ctx.BoardActions.Find(boardActionId); ctx.BoardActions.Remove(bda); entitiesDeleted = ctx.SaveChanges(); } return(IsSuccessfulDelete(entitiesDeleted)); }
/// <summary> /// Insert a row representing a board action (a card coming on board [flop, turn, river]) into the database. /// </summary> /// <param name="handId">The hand Id</param> /// <param name="boardCard">The board card</param> /// <param name="handActionNumber">The hand action number</param> /// <param name="errorMessagesTextBox">The textbox for logging erros</param> /// <returns>The board action Id</returns> public long InsertBoardAction(long handId, short boardCard, int handActionNumber, TextBox errorMessagesTextBox) { // Create a board action object to insert into the database BoardAction boardAction = new BoardAction { HandId = handId, BoardCard = boardCard, HandActionNumber = handActionNumber }; using (Bol_Model_DBEntities ctx = new Bol_Model_DBEntities()) { try { ctx.BoardActions.Add(boardAction); int numRecordsWritten = ctx.SaveChanges(); // Check for errors if (numRecordsWritten != 1) { // ctx.SaveChanges() returns the number of records written to the DB. This method only writes one record at a time so if // the number of records written is != 1 there was a problem WriteErrorMessage("Wrong number of records written inside InsertBoardAction. " + numRecordsWritten + " Records Written", errorMessagesTextBox); } } catch (System.Data.Entity.Infrastructure.DbUpdateConcurrencyException ex) { WriteErrorMessage("DbUpdateConcurrencyException inside InsertBoardAction. " + ex.Message, errorMessagesTextBox); } catch (Exception ex) { WriteErrorMessage("Some unexpected exception occured inside InsertBoardAction. " + ex.Message, errorMessagesTextBox); } } return(boardAction.Id); }