delphimvcframework/samples/angular2/dmvcframeworkserver/CustomersControllerU.pas
2016-12-01 15:23:23 +01:00

73 lines
1.6 KiB
ObjectPascal

unit CustomersControllerU;
interface
uses
MVCFramework, CustomersTDGU;
type
[MVCPath('/api')]
TCustomersController = class(TMVCController)
private
FCustomersTDG: TCustomersTDG;
protected
function GetDAL: TCustomersTDG;
procedure MVCControllerBeforeDestroy; override;
public
[MVCPath('/customers')]
[MVCHTTPMethod([httpGET])]
procedure GetCustomers;
[MVCPath('/customers/($ID)')]
[MVCHTTPMethod([httpGET])]
procedure GetCustomer(const ID: UInt64);
procedure OnBeforeAction(Context: TWebContext; const AActionName: string;
var Handled: Boolean); override;
procedure OnAfterAction(Context: TWebContext; const AActionName: string); override;
end;
implementation
procedure TCustomersController.GetCustomer(const ID: UInt64);
begin
Render(GetDAL.GetCustomerById(ID), true, true);
end;
procedure TCustomersController.GetCustomers;
begin
Render(GetDAL.GetCustomers, true);
end;
function TCustomersController.GetDAL: TCustomersTDG;
begin
if not Assigned(FCustomersTDG) then
FCustomersTDG := TCustomersTDG.Create(nil);
Result := FCustomersTDG;
end;
procedure TCustomersController.MVCControllerBeforeDestroy;
begin
inherited;
FCustomersTDG.Free;
end;
procedure TCustomersController.OnAfterAction(Context: TWebContext; const AActionName: string);
begin
{ Executed after each action }
inherited;
end;
procedure TCustomersController.OnBeforeAction(Context: TWebContext; const AActionName: string;
var Handled: Boolean);
begin
{ Executed before each action
if handled is true (or an exception is raised) the actual
action will not be called }
inherited;
end;
end.