Data Access has been discontinued. Please refer to this page for more information.

Extending the API Controllers

In this task, you will add a new custom action method to CarsController:

  1. In the SofiaCarRentalWebApp project, open the CarsController.cs(vb) file.
  2. Add the following references:

    using System.Collections.Generic;
    using System.Linq;
    Imports System.Collections.Generic
    Imports System.Linq
  3. Add a new action method named GetCarsByMake. It will return all cars filtered by the specified make.

    public virtual IEnumerable<Car> GetCarsByMake( string make )
       return this.repository.GetAll().Where( c => c.Make == make );
    Public Overridable Function GetCarsByMake(ByVal make As String) As IEnumerable(Of Car)
        Return Me.repository.GetAll().Where(Function(c) c.Make = make)
    End Function
  4. Save the file.