delphimvcframework/samples/soaprest/webservices/rest/RESTControllerCustomerU.pas

59 lines
1.2 KiB
ObjectPascal
Raw Normal View History

unit RESTControllerCustomerU;
interface
uses
MVCFramework, MVCFramework.Commons, WSHelperCustomersU;
type
2015-12-04 16:55:11 +01:00
[MVCPath('/')]
TControllerCustomer = class(TMVCController)
private
FWSHelperCustomers: TWSHelperCustomers;
protected
procedure OnBeforeAction(Context: TWebContext; const AActionNAme: string;
var Handled: Boolean); override;
procedure OnAfterAction(Context: TWebContext;
const AActionNAme: string); override;
public
2015-12-04 16:55:11 +01:00
[MVCPath('/customers')]
[MVCHTTPMethod([httpGET])]
procedure GetCustomers(ctx: TWebContext);
2015-12-04 16:55:11 +01:00
[MVCPath('/')]
[MVCHTTPMethod([httpGET])]
procedure Index(ctx: TWebContext);
end;
implementation
uses
System.SysUtils, BOCustomersU;
procedure TControllerCustomer.OnBeforeAction(Context: TWebContext;
const AActionNAme: string; var Handled: Boolean);
begin
FWSHelperCustomers := TWSHelperCustomers.Create;
end;
2015-12-04 16:55:11 +01:00
procedure TControllerCustomer.Index(ctx: TWebContext);
begin
Redirect('/index.html');
end;
procedure TControllerCustomer.OnAfterAction(Context: TWebContext;
const AActionNAme: string);
begin
FreeAndNil(FWSHelperCustomers);
end;
procedure TControllerCustomer.GetCustomers(ctx: TWebContext);
begin
Render<TCustomer>(FWSHelperCustomers.GetCustomers);
end;
end.