/// <summary>
        /// Gets the inner error of the specified error from the database
        /// </summary>
        /// <param name="conn">Open connection to the database</param>
        /// <param name="outerError">Outer error</param>
        /// <returns>Inner error of the specified error, loaded from the database</returns>
        public static Business.Error GetErrorByOuterError(SqlConnection conn, Business.Error outerError)
        {
            try
            {
                sql.SqlCommand cmd = new sql.SqlCommand("GetErrorByOuterErrorId", conn);
                cmd.Parameters.AddWithValue("OuterErrorId", DbType.Int32, outerError.Id);

                Business.Error[] errors = cmd.ExecuteMappedReader <Business.Error, Int32>();

                switch (errors.Length)
                {
                case 0:
                    return(null);

                case 1:
                    return(errors[0]);

                default:
                    throw new SpecifiedSqlDbObjectNotFoundException(String.Format("{0} rows found in the database", errors.Length));
                }
            }
            catch (System.Exception e)
            {
                throw new SpecifiedSqlDbObjectNotFoundException("Could not load error", e);
            }
        }
Exemple #2
0
        /// <summary>
        /// Gets the number of unread messages that belong to the invite with the specified unique identifier
        /// </summary>
        /// <param name="conn">Open connection to the database</param>
        /// <param name="inviteId">Unique identifier of the invite</param>
        /// <param name="isRequesterAdmin">Value determining whether or not the invite requesting the messages is an admin user</param>
        /// <returns>Number of unread messages that belong to the invite with the specified unique identifier</returns>
        internal static Int32 GetInviteUnreadMessageCount(SqlConnection conn, Int32 inviteId, Boolean isRequesterAdmin)
        {
            sql.SqlCommand cmd = new sql.SqlCommand("GetInviteUnreadMessageCount", conn);
            cmd.Parameters.AddWithValue("InviteId", DbType.Int32, inviteId);
            cmd.Parameters.AddWithValue("IsRequesterAdmin", DbType.Boolean, isRequesterAdmin);

            return(cmd.ExecuteScalar <Int32>());
        }
 /// <summary>
 /// Gets all invites currently in the system
 /// </summary>
 /// <param name="conn">Open connection to the database</param>
 /// <returns>All invites currently in the system</returns>
 public static Business.Invite[] GetInvites(SqlConnection conn)
 {
     try
     {
         sql.SqlCommand cmd = new sql.SqlCommand("GetInvites", conn);
         return(cmd.ExecuteMappedReader <Business.Invite, Int32>());
     }
     catch (System.Exception e)
     {
         throw new SpecifiedSqlDbObjectNotFoundException("Could not load invites", e);
     }
 }
        /// <summary>
        /// Gets the guests that have not yet been assigned to a table
        /// </summary>
        /// <param name="conn">Open connection to the database</param>
        /// <returns>Guests that have not yet been assigned to a table</returns>
        public static Business.Guest[] GetUnassignedTableGuests(SqlConnection conn)
        {
            try
            {
                sql.SqlCommand cmd = new sql.SqlCommand("GetUnassignedTableGuests", conn);

                return(cmd.ExecuteMappedReader <Business.Guest, Int32>((row => Business.Guest.FromDataRow(row))));
            }
            catch (System.Exception e)
            {
                throw new SpecifiedSqlDbObjectNotFoundException("Could not get guests", e);
            }
        }
        /// <summary>
        /// Loads the invite with the specified unique identifier from the database
        /// </summary>
        /// <param name="conn">Open connection to the database</param>
        /// <param name="inviteId">Unique identifier of the invite</param>
        /// <returns>Invite with the specified unique identifier, loaded from the database</returns>
        public static Business.Invite GetInviteById(SqlConnection conn, Int32 inviteId)
        {
            try
            {
                sql.SqlCommand cmd = new sql.SqlCommand("GetInviteById", conn);
                cmd.Parameters.AddWithValue("InviteId", DbType.Int32, inviteId);

                return(cmd.ExecuteMappedSingleReader <Business.Invite, Int32>());
            }
            catch (System.Exception e)
            {
                throw new SpecifiedSqlDbObjectNotFoundException("Could not load invite", e);
            }
        }
Exemple #6
0
        /// <summary>
        /// Loads the room with the specified unique identifier from the database
        /// </summary>
        /// <param name="conn">Open connection to the database</param>
        /// <param name="roomId">Unique identifier of the room</param>
        /// <returns>Room with the specified unique identifier, loaded from the database</returns>
        internal static Business.Room GetRoomById(SqlConnection conn, Int32 roomId)
        {
            try
            {
                sql.SqlCommand cmd = new sql.SqlCommand("GetRoomById", conn);
                cmd.Parameters.AddWithValue("RoomId", DbType.Int32, roomId);

                return(cmd.ExecuteMappedSingleReader <Business.Room, Int32>());
            }
            catch (System.Exception e)
            {
                throw new SpecifiedSqlDbObjectNotFoundException("Could not load room.", e);
            }
        }
        /// <summary>
        /// Gets the guests that are assigned to the room with the specified unique identifier
        /// </summary>
        /// <param name="conn">Open connection to the database</param>
        /// <param name="roomId">Unique identifier of the room</param>
        /// <returns>Guests that are assigned to the room with the specified unique identifier</returns>
        public static Business.Guest[] GetGuestsByRoomId(SqlConnection conn, Int32 roomId)
        {
            try
            {
                sql.SqlCommand cmd = new sql.SqlCommand("GetGuestsByRoomId", conn);
                cmd.Parameters.AddWithValue("RoomId", DbType.Int32, roomId);

                return(cmd.ExecuteMappedReader <Business.Guest, Int32>((row => Business.Guest.FromDataRow(row))));
            }
            catch (System.Exception e)
            {
                throw new SpecifiedSqlDbObjectNotFoundException("Could not get guests.", e);
            }
        }
        /// <summary>
        /// Deletes a guest from the database
        /// </summary>
        /// <param name="conn">Open connection to the database</param>
        /// <param name="guest">Guest being deleted from the database</param>
        public static void DeleteGuest(SqlConnection conn, Int32 guestId)
        {
            try
            {
                sql.SqlCommand cmd = new sql.SqlCommand("DeleteGuest", conn);
                cmd.Parameters.AddWithValue("GuestId", DbType.Int32, guestId);

                cmd.ExecuteNonQuery();
            }
            catch (System.Exception e)
            {
                throw new DeleteSqlDbObjectException("Could not delete guest", e);
            }
        }
        /// <summary>
        /// Updates a guest in the database
        /// </summary>
        /// <param name="conn">Open connection to the database</param>
        /// <param name="inviteId">Unique identifier of the invite the guest is a member of</param>
        /// <param name="guest">Guest being updated in the database</param>
        public static void UpdateGuest(SqlConnection conn, Int32 inviteId, Business.Guest guest)
        {
            try
            {
                sql.SqlCommand cmd = new sql.SqlCommand("UpdateGuest", conn);
                cmd.Parameters.AddRange(guest.GetParametersForStoredProcedure(inviteId, true));

                cmd.ExecuteNonQuery();
            }
            catch (System.Exception e)
            {
                throw new UpdateSqlDbObjectException("Could not update guest", e);
            }
        }
Exemple #10
0
        /// <summary>
        /// Adds a guest to the database
        /// </summary>
        /// <param name="conn">Open connection to the database</param>
        /// <param name="inviteId">Unique identifier of the invite the guest is a member of</param>
        /// <param name="guest">Guest being added to the database</param>
        /// <returns>Unique identifier of the guest, generated by the database</returns>
        public static Int32 AddGuest(SqlConnection conn, Int32 inviteId, Business.Guest guest)
        {
            try
            {
                sql.SqlCommand cmd = new sql.SqlCommand("AddGuest", conn);
                cmd.Parameters.AddRange(guest.GetParametersForStoredProcedure(inviteId, false));

                return(cmd.ExecuteScalar <Int32>());
            }
            catch (System.Exception e)
            {
                throw new AddSqlDbObjectException("Could not add guest", e);
            }
        }
Exemple #11
0
        /// <summary>
        /// Loads a video from the database
        /// </summary>
        /// <param name="conn">Open connection to the database</param>
        /// <param name="videoId">Unique identifier of the video being loaded</param>
        /// <returns>Video object loaded from the database</returns>
        public static Business.Video GetVideoById(SqlConnection conn, Int64 videoId)
        {
            try
            {
                sql.SqlCommand cmd = new sql.SqlCommand("GetVideoById", conn);
                cmd.Parameters.AddWithValue("VideoId", DbType.Int64, videoId);

                return(cmd.ExecuteMappedSingleReader <Business.Video>(row => Business.MediaItem.FromDataRow(conn, row) as Business.Video));
            }
            catch (System.Exception e)
            {
                throw new SpecifiedSqlDbObjectNotFoundException("Could not load specified video", e);
            }
        }
Exemple #12
0
        /// <summary>
        /// Sets the room ID of the guest with the specified unique identifier
        /// </summary>
        /// <param name="conn">Open connection to the database</param>
        /// <param name="guestId">Unique identifier of the guest</param>
        /// <param name="roomId">Unique identifier of the room</param>
        public static void SetGuestRoomId(SqlConnection conn, Int32 guestId, Int32?roomId)
        {
            try
            {
                sql.SqlCommand cmd = new sql.SqlCommand("SetGuestRoomId", conn);
                cmd.Parameters.AddWithValue("GuestId", DbType.Int32, guestId);
                cmd.Parameters.AddWithValue("RoomId", DbType.Int32, roomId);

                cmd.ExecuteNonQuery();
            }
            catch (System.Exception e)
            {
                throw new UpdateSqlDbObjectException("Could not set guest room ID", e);
            }
        }
Exemple #13
0
        /// <summary>
        /// Loads the unread messages that belong to the invite with the specified unique identifier from the database
        /// </summary>
        /// <param name="conn">Open connection to the database</param>
        /// <param name="inviteId">Unique identifier of the invite</param>
        /// <param name="isRequesterAdmin">Value determining whether or not the invite requesting the messages is an admin user</param>
        /// <returns>Unread messages that belong to the invite with the specified unique identifier from the database</returns>
        internal static Business.Message[] GetUnreadMessagesByInviteId(SqlConnection conn, Int32 inviteId, Boolean isRequesterAdmin)
        {
            try
            {
                sql.SqlCommand cmd = new sql.SqlCommand("GetUnreadMessagesByInviteId", conn);
                cmd.Parameters.AddWithValue("InviteId", DbType.Int32, inviteId);
                cmd.Parameters.AddWithValue("IsRequesterAdmin", DbType.Boolean, isRequesterAdmin);

                return(cmd.ExecuteMappedReader <Business.Message, Int32>());
            }
            catch (System.Exception e)
            {
                throw new SpecifiedSqlDbObjectNotFoundException("Could not load messages.", e);
            }
        }