Extending the API Controllers
In this task, you will add a new custom action method to CarsController:
- In the SofiaCarRentalWebApp project, open the CarsController.cs(vb) file.
-
Add the following references:
using System.Collections.Generic; using System.Linq;
Imports System.Collections.Generic Imports System.Linq
-
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
Save the file.