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

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

            if (!_dataEngine.ExecuteSql(_sqlToExecute))
                throw new Exception("CourtBookingSheet - Delete failed");
        }
 public int Insert(CourtBookingSheet saveThis)
 {
     try
        {
        _db.CourtBookingSheets.InsertOnSubmit(saveThis);
        _db.SubmitChanges();
        return saveThis.Id;
        }
        catch (Exception e)
        {
        throw new Exception(e.Message);
        }
 }
 public void Delete(CourtBookingSheet deleteThis)
 {
     try
     {
         if (deleteThis.Id > 0)
         {
             _db.CourtBookingSheets.DeleteOnSubmit(deleteThis);
             _db.SubmitChanges(ConflictMode.FailOnFirstConflict);
         }
     }
     catch (Exception e)
     {
         throw new Exception(e.Message);
     }
 }
        public int Insert(CourtBookingSheet saveThis)
        {
            _dataEngine.InitialiseParameterList();
            _dataEngine.AddParameter("@CourtBookingStartTime", saveThis.CourtBookingStartTime.ToString());
            _dataEngine.AddParameter("@CourtBookingEndTime", saveThis.CourtBookingEndTime.ToString());
            _dataEngine.AddParameter("@CourtBookingDate", DataFormatting.FormatDateTime(saveThis.CourtBookingDate));

            _sqlToExecute = "INSERT INTO [dbo].[CourtBookingSheet] ";
            _sqlToExecute += "([CourtBookingStartTime]";
            _sqlToExecute += ",[CourtBookingEndTime]";
            _sqlToExecute += ",[CourtBookingDate]) ";
            _sqlToExecute += "OUTPUT INSERTED.Id ";
            _sqlToExecute += "VALUES ";
            _sqlToExecute += "(";
            _sqlToExecute += _dataEngine.GetParametersForQuery();
            _sqlToExecute += ")";

            int insertedRowId = 0;

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

            return insertedRowId;
        }
        /// <summary>
        /// Creates the object from the data returned from the database
        /// </summary>
        /// <returns></returns>
        private CourtBookingSheet CreateCourtBookingSheetRecordFromData()
        {
            var courtBookingSheet = new CourtBookingSheet
            {
                CourtBookingStartTime = int.Parse(_dataEngine.Dr["CourtBookingStartTime"].ToString()),
                CourtBookingEndTime = int.Parse(_dataEngine.Dr["CourtBookingEndTime"].ToString()),
                CourtBookingDate = Convert.ToDateTime(_dataEngine.Dr["CourtBookingDate"]),
                Id = int.Parse(_dataEngine.Dr["Id"].ToString())
            };

            return courtBookingSheet;
        }
        public void Update(CourtBookingSheet saveThis)
        {
            _dataEngine.InitialiseParameterList();
            _dataEngine.AddParameter("@CourtBookingStartTime", saveThis.CourtBookingStartTime.ToString());
            _dataEngine.AddParameter("@CourtBookingEndTime", saveThis.CourtBookingEndTime.ToString());
            _dataEngine.AddParameter("@CourtBookingDate", DataFormatting.FormatDateTime(saveThis.CourtBookingDate));

            _sqlToExecute = "UPDATE [dbo].[CourtBookingSheet] SET ";
            _sqlToExecute += "[CourtBookingStartTime] = @CourtBookingStartTime";
            _sqlToExecute += ",[CourtBookingEndTime] = @CourtBookingEndTime";
            _sqlToExecute += ",[CourtBookingDate] = CourtBookingDate ";
            _sqlToExecute += "WHERE [Id] = " + saveThis.Id; ;

            if (!_dataEngine.ExecuteSql(_sqlToExecute))
                throw new Exception("CourtBookingSheet - Update failed");
        }
 public void Update(CourtBookingSheet updateThis)
 {
     try
     {
         _db.CourtBookingSheets.Attach(updateThis);
         _db.Refresh(RefreshMode.KeepCurrentValues, updateThis);
         _db.SubmitChanges();
     }
     catch (Exception e)
     {
         throw new Exception(e.Message);
     }
 }