TopShelfCustomer/TopShelfCustomer.Api/Controllers/ProductController.cs
/// <summary>
/// GetProductById:
///
/// Overload of the Get method.
/// Fetches a specific Product from the database and returns it
/// to the caller of this API method.
/// Matches based off of the passed Product Id.
/// </summary>
/// <param name="id"> The Id to match </param>
/// <returns> The first Product returned that matches the id argument </returns>


Overload of the Get method.
Fetches a specific Product from the database and returns it
to the caller of this API method.
Matches based off of the passed Product Id.
Overload of the Get method . Fetches a specific Product from the database and returns it to the caller of this API method . Matches based off of the passed Product Id .
[Route( "api/Product/GetProductById/{id:int}" )]
        [HttpGet]
        public Product Get ( int id ) {
            ProductData data = new ProductData();
            var product = data.GetProductById( id );        
            try {               
                if ( product[0] == null ) { return new Product(); }
            } catch ( ArgumentOutOfRangeException e ) {
                Debug.WriteLine( e.Message );
                return new Product();
            } catch ( Exception e ) {
                Debug.WriteLine( e.Message );
                return new Product();
            }
            return product[0];      
        }
[ Route ( " " ) ] [ HttpGet ] public Product Get ( int id ) { ProductData data = new ProductData ( ) ; var product = data . GetProductById ( id ) ; try { if ( product [ 0 ] == null ) { return new Product ( ) ; } } catch ( ArgumentOutOfRangeException e ) { Debug . WriteLine ( e . Message ) ; return new Product ( ) ; } catch ( Exception e ) { Debug . WriteLine ( e . Message ) ; return new Product ( ) ; } return product [ 0 ] ; }
GetProductById:
GetProductById :
//Store return value of database fetch //Catch exceptions thrown by null Products //Return first match
The first Product returned that matches the id argument
The first Product returned that matches the id argument
id
int
The Id to match
The Id to match