Beispiel #1
0
        /// <summary>
        /// Add a new entry to the SeatingReservation table
        /// </summary>
        public static SeatingReservation Add(int customerId, DateTime reservationTime,
                                             int partySize, int seatingId, int employeeId)
        {
            SeatingReservation result       = null;
            DateTime           purchaseTime = DateTime.Now;

            partySize = MathHelper.Clamp(partySize, short.MinValue, short.MaxValue);

            SqlConnection cn  = GetConnection();
            string        cmd = "AddSeatingReservation";

            using (SqlCommand sqlCmd = new SqlCommand(cmd, cn))
            {
                sqlCmd.CommandType = CommandType.StoredProcedure;
                BuildSqlParameter(sqlCmd, "@SeatingReservationCustomerId", SqlDbType.Int, customerId);
                BuildSqlParameter(sqlCmd, "@SeatingReservationTime", SqlDbType.DateTime, reservationTime);
                BuildSqlParameter(sqlCmd, "@SeatingReservationPartySize", SqlDbType.SmallInt, partySize);
                BuildSqlParameter(sqlCmd, "@SeatingReservationSeatingId", SqlDbType.Int, seatingId);
                BuildSqlParameter(sqlCmd, "@SeatingReservationEmployeeId", SqlDbType.Int, employeeId);
                BuildSqlParameter(sqlCmd, "@SeatingReservationId", SqlDbType.Int, ParameterDirection.ReturnValue);
                if (sqlCmd.ExecuteNonQuery() > 0)
                {
                    result = new SeatingReservation(Convert.ToInt32(sqlCmd.Parameters["@SeatingReservationId"].Value),
                                                    customerId, reservationTime, partySize, seatingId, employeeId);
                }
            }
            FinishedWithConnection(cn);
            return(result);
        }
Beispiel #2
0
        /// <summary>
        /// Update an entry in the SeatingReservation table
        /// </summary>
        public static bool Update(SeatingReservation seatingReservation)
        {
            bool result = false;

            SqlConnection cn = GetConnection();

            result = Update(cn, seatingReservation);
            FinishedWithConnection(cn);

            return(result);
        }
Beispiel #3
0
        /// <summary>
        /// Get an entry from the SeatingReservation table
        /// </summary>
        public static SeatingReservation Get(int id)
        {
            SeatingReservation result = null;

            SqlConnection cn = GetConnection();

            result = Get(cn, id);
            FinishedWithConnection(cn);

            return(result);
        }
Beispiel #4
0
        private static SeatingReservation Get(SqlConnection cn, int id)
        {
            SeatingReservation result = null;

            using (SqlCommand cmd = new SqlCommand("SELECT * FROM SeatingReservation WHERE SeatingReservationId=" + id, cn))
            {
                using (SqlDataReader rdr = cmd.ExecuteReader())
                {
                    if (rdr.Read())
                    {
                        result = BuildSeatingReservation(rdr);
                    }
                }
            }
            return(result);
        }
Beispiel #5
0
        /// <summary>
        /// Delete an entry from the SeatingReservation table
        /// </summary>
        public static bool Delete(int id)
        {
            Int32              rowsAffected       = 0;
            SqlConnection      cn                 = GetConnection();
            SeatingReservation seatingReservation = Get(cn, id);

            if (seatingReservation != null)
            {
                using (SqlCommand sqlCmd = cn.CreateCommand())
                {
                    sqlCmd.CommandText = "DELETE FROM SeatingReservation WHERE SeatingReservationId=" + id;
                    rowsAffected       = sqlCmd.ExecuteNonQuery();
                }
            }
            FinishedWithConnection(cn);
            return(rowsAffected != 0);
        }
Beispiel #6
0
        private static bool Update(SqlConnection cn, SeatingReservation seatingReservation)
        {
            Int32 rowsAffected = 0;

            using (SqlCommand sqlCmd = cn.CreateCommand())
            {
                sqlCmd.CommandText = "UPDATE SeatingReservation SET SeatingReservationCustomerId=@SeatingReservationCustomerId,SeatingReservationTime=@SeatingReservationTime,SeatingReservationPartySize=@SeatingReservationPartySize,SeatingReservationSeatingId=@SeatingReservationSeatingId,SeatingReservationEmployeeId=@SeatingReservationEmployeeId WHERE SeatingReservationId=@SeatingReservationId";

                BuildSqlParameter(sqlCmd, "@SeatingReservationId", SqlDbType.Int, seatingReservation.Id);
                BuildSqlParameter(sqlCmd, "@SeatingReservationCustomerId", SqlDbType.Int, seatingReservation.CustomerId);
                BuildSqlParameter(sqlCmd, "@SeatingReservationTime", SqlDbType.DateTime, seatingReservation.ReservationTime);
                BuildSqlParameter(sqlCmd, "@SeatingReservationPartySize", SqlDbType.SmallInt, seatingReservation.PartySize);
                BuildSqlParameter(sqlCmd, "@SeatingReservationSeatingId", SqlDbType.Int, seatingReservation.SeatingId);
                BuildSqlParameter(sqlCmd, "@SeatingReservationEmployeeId", SqlDbType.Int, seatingReservation.EmployeeId);

                rowsAffected = sqlCmd.ExecuteNonQuery();
            }
            return(rowsAffected != 0);
        }