public void Delete(BookingRecord deleteThis)
        {
            _dataEngine.InitialiseParameterList();
            _dataEngine.AddParameter("@Id", deleteThis.Id.ToString());

            _sqlToExecute = "DELETE FROM [dbo].[BookingRecord] WHERE Id = " + _dataEngine.GetParametersForQuery();

            if (!_dataEngine.ExecuteSql(_sqlToExecute))
                throw new Exception("BookingRecord - Delete failed");
        }
 public void Delete(BookingRecord deleteThis)
 {
     try
     {
         if (deleteThis.Id > 0)
         {
             _db.Bookings.DeleteOnSubmit(deleteThis);
             _db.SubmitChanges(ConflictMode.FailOnFirstConflict);
         }
     }
     catch (Exception e)
     {
         throw new Exception(e.Message);
     }
 }
 public int Insert(BookingRecord saveThis)
 {
     try
        {
        _db.Bookings.InsertOnSubmit(saveThis);
        _db.SubmitChanges();
        return saveThis.Id;
        }
        catch (Exception e)
        {
        throw new Exception(e.Message);
        }
 }
 public void Update(BookingRecord updateThis)
 {
     try
     {
         _db.Bookings.Attach(updateThis);
         _db.Refresh(RefreshMode.KeepCurrentValues, updateThis);
         _db.SubmitChanges();
     }
     catch (Exception e)
     {
         throw new Exception(e.Message);
     }
 }
        /// <summary>
        /// Creates the object from the data returned from the database
        /// </summary>
        /// <returns></returns>
        private BookingRecord CreateBookingRecordFromData()
        {
            var bookingRecord = new BookingRecord
            {
                TimeArrived = int.Parse(_dataEngine.Dr["TimeArrived"].ToString()),
                ArrivalRegistrationMethod = (ArrivalRegistrationMethod)int.Parse(_dataEngine.Dr["ArrivalRegistrationMethod"].ToString()),
                BookingStatus = (BookingStatus)int.Parse(_dataEngine.Dr["BookingStatus"].ToString()),
                BookingRecordUniqueId = _dataEngine.Dr["BookingRecordUniqueId"].ToString(),
                BookingRecordPin = int.Parse(_dataEngine.Dr["BookingRecordPin"].ToString()),
                Id = int.Parse(_dataEngine.Dr["Id"].ToString())
            };

            return bookingRecord;
        }
        public void Update(BookingRecord saveThis)
        {
            _dataEngine.InitialiseParameterList();
            _dataEngine.AddParameter("@TimeArrived", saveThis.TimeArrived.ToString());
            _dataEngine.AddParameter("@ArrivalRegistrationMethod", ((int)saveThis.ArrivalRegistrationMethod).ToString());
            _dataEngine.AddParameter("@BookingStatus", ((int)saveThis.BookingStatus).ToString());
            _dataEngine.AddParameter("@BookingRecordUniqueId", saveThis.BookingRecordUniqueId.ToString());
            _dataEngine.AddParameter("@BookingRecordPin", saveThis.BookingRecordPin.ToString());

            _sqlToExecute = "UPDATE [dbo].[BookingRecord] SET ";
            _sqlToExecute += "[TimeArrived] = @TimeArrived";
            _sqlToExecute += ",[ArrivalRegistrationMethod] = @ArrivalRegistrationMethod";
            _sqlToExecute += ",[BookingStatus] = @BookingStatus";
            _sqlToExecute += ",[BookingRecordUniqueId] = @BookingRecordUniqueId";
            _sqlToExecute += ",[BookingRecordPin] = @BookingRecordPin ";
            _sqlToExecute += "WHERE [Id] = " + saveThis.Id;

            if (!_dataEngine.ExecuteSql(_sqlToExecute))
                throw new Exception("BookingRecord - Update failed");
        }
        public int Insert(BookingRecord saveThis)
        {
            _dataEngine.InitialiseParameterList();
            _dataEngine.AddParameter("@TimeArrived", saveThis.TimeArrived.ToString());
            _dataEngine.AddParameter("@ArrivalRegistrationMethod", ((int)saveThis.ArrivalRegistrationMethod).ToString());
            _dataEngine.AddParameter("@BookingStatus", ((int)saveThis.BookingStatus).ToString());
            _dataEngine.AddParameter("@BookingRecordUniqueId", saveThis.BookingRecordUniqueId.ToString());
            _dataEngine.AddParameter("@BookingRecordPin", saveThis.BookingRecordPin.ToString());

            _sqlToExecute = "INSERT INTO [dbo].[BookingRecord] ";
            _sqlToExecute += "([TimeArrived]";
            _sqlToExecute += ",[ArrivalRegistrationMethod]";
            _sqlToExecute += ",[BookingStatus]";
            _sqlToExecute += ",[BookingRecordUniqueId]";
            _sqlToExecute += ",[BookingRecordPin]) ";
            _sqlToExecute += "OUTPUT INSERTED.Id ";
            _sqlToExecute += "VALUES ";
            _sqlToExecute += "(";
            _sqlToExecute += _dataEngine.GetParametersForQuery();
            _sqlToExecute += ")";

            int insertedRowId = 0;

            if (!_dataEngine.ExecuteSql(_sqlToExecute, out insertedRowId))
                throw new Exception("BookingRecord - Save failed");

            return insertedRowId;
        }