delphimvcframework/samples/ISAPI/Controllers/RoutingSampleControllerU.pas

76 lines
1.7 KiB
ObjectPascal
Raw Normal View History

2014-03-10 17:39:29 +01:00
unit RoutingSampleControllerU;
interface
uses
2017-10-10 12:54:04 +02:00
MVCFramework, MVCFramework.Commons;
2014-03-10 17:39:29 +01:00
type
[MVCPath('/')]
TRoutingSampleController = class(TMVCController)
public
[MVCPath('/')]
procedure Index(CTX: TWebContext);
[MVCHTTPMethod([httpGet])]
[MVCPath('/search/($searchtext)/($page)')]
[MVCProduces('text/plain', 'UTF-8')]
[MVCConsumes('text/html')]
procedure SearchCustomers(CTX: TWebContext);
[MVCHTTPMethod([httpGet])]
[MVCPath('/people/($id)')]
[MVCProduces('application/json')]
2016-11-18 14:09:54 +01:00
procedure GetPerson(const id: Integer);
2014-03-10 17:39:29 +01:00
end;
implementation
uses
System.SysUtils, BusinessObjectsU, Data.DBXJSON;
{ TRoutingSampleController }
2016-11-18 14:09:54 +01:00
procedure TRoutingSampleController.GetPerson(const id: Integer);
2014-03-10 17:39:29 +01:00
var
P: TPerson;
begin
{
2016-11-18 14:09:54 +01:00
Use ID to load the person from a database...
2014-03-10 17:39:29 +01:00
In this example, we're creating a fake person
}
P := TPerson.Create;
P.FirstName := 'Daniele';
P.LastName := 'Teti';
P.DOB := EncodeDate(1975, 5, 2);
P.Married := True;
Render(P);
end;
procedure TRoutingSampleController.Index(CTX: TWebContext);
begin
Render('This is the root path');
end;
procedure TRoutingSampleController.SearchCustomers(CTX: TWebContext);
var
search: string;
P: Integer;
orderby: string;
begin
search := CTX.Request.Params['searchtext'];
P := CTX.Request.ParamsAsInteger['page'];
orderby := '';
if CTX.Request.QueryStringParamExists('order') then
orderby := CTX.Request.QueryStringParam('order');
Render(Format(
'SEARCHTEXT: "%s"' + sLineBreak +
'PAGE: %d' + sLineBreak +
'ORDERBYFIELD: "%s"',
[search, P, orderby]));
end;
end.