TopShelfCustomer/TopShelfCustomer.Api/Controllers/UserController.cs
/// <summary>
/// GetUserById:
///
/// Overload of the Get request method.
/// Fetches a single user from the database and returns it
/// to the caller of this API method.
/// Matches based off of the passed userId argument.
/// </summary>
/// <param name="userId"> The Id of the requested User </param>
/// <returns> a User with a matching Id </returns>


Overload of the Get request method.
Fetches a single user from the database and returns it
to the caller of this API method.
Matches based off of the passed userId argument.
Overload of the Get request method . Fetches a single user from the database and returns it to the caller of this API method . Matches based off of the passed userId argument .
[Route( "api/User/GetUserById/{userId:int}" )]
        [HttpGet]
        public User Get ( int userId ) {
            UserData data = new UserData();     
            var user = data.GetUserById( userId );      
            try {               
                if ( user[0] == null ) { return new User(); }
            } catch ( ArgumentOutOfRangeException e ) {
                Debug.WriteLine( e.Message );
                return new User();
            } catch ( Exception e ) {
                Debug.WriteLine( e.Message );
                return new User();
            }
            return user[0];
        }
[ Route ( " " ) ] [ HttpGet ] public User Get ( int userId ) { UserData data = new UserData ( ) ; var user = data . GetUserById ( userId ) ; try { if ( user [ 0 ] == null ) { return new User ( ) ; } } catch ( ArgumentOutOfRangeException e ) { Debug . WriteLine ( e . Message ) ; return new User ( ) ; } catch ( Exception e ) { Debug . WriteLine ( e . Message ) ; return new User ( ) ; } return user [ 0 ] ; }
GetUserById:
GetUserById :
//Create new UserData object to interact with DB //Get user from DB //Catch exceptions thrown by null User
a User with a matching Id
a User with a matching Id
userId
int
The Id of the requested User
The Id of the requested User