Пример #1
0
        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);
        }
Пример #2
0
        /// <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);
        }
Пример #3
0
        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");
            }
        }
Пример #4
0
 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);
     }
 }
Пример #5
0
 public int Insert(CourtBookingSheet saveThis)
 {
     try
     {
         _db.CourtBookingSheets.InsertOnSubmit(saveThis);
         _db.SubmitChanges();
         return(saveThis.Id);
     }
     catch (Exception e)
     {
         throw new Exception(e.Message);
     }
 }
Пример #6
0
 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);
     }
 }
Пример #7
0
        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");
            }
        }
Пример #8
0
        public IQueryable <CourtBookingSheet> GetAll()
        {
            var courtBookingSheetList = new List <CourtBookingSheet>();

            _sqlToExecute = "SELECT * FROM [dbo].[CourtBookingSheet]";

            if (!_dataEngine.CreateReaderFromSql(_sqlToExecute))
            {
                throw new Exception("CourtBookingSheet - GetAll failed");
            }

            while (_dataEngine.Dr.Read())
            {
                CourtBookingSheet courtBookingSheet = CreateCourtBookingSheetRecordFromData();
                courtBookingSheetList.Add(courtBookingSheet);
            }

            return(courtBookingSheetList.AsQueryable());
        }
Пример #9
0
        public CourtBookingSheet GetById(int id)
        {
            _dataEngine.InitialiseParameterList();
            _dataEngine.AddParameter("@Id", id.ToString());

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

            if (!_dataEngine.CreateReaderFromSql(_sqlToExecute))
            {
                throw new Exception("CourtBookingSheet - GetById failed");
            }

            if (_dataEngine.Dr.Read())
            {
                CourtBookingSheet courtBookingSheet = CreateCourtBookingSheetRecordFromData();
                return(courtBookingSheet);
            }
            else
            {
                throw new Exception("CourtBookingSheet Id " + id.ToString() + " does not exist in database");
            }
        }