delphimvcframework/samples/routingsample/RoutingSampleControllerU.pas

65 lines
1.5 KiB
ObjectPascal
Raw Normal View History

2013-11-09 10:32:54 +01:00
unit RoutingSampleControllerU;
interface
uses
2013-11-10 01:03:53 +01:00
MVCFramework, MVCFramework.Commons, ObjectsMappers;
2013-11-09 10:32:54 +01:00
type
[MVCPath('/')]
TRoutingSampleController = class(TMVCController)
public
[MVCHTTPMethod([httpGet])]
2013-11-10 01:03:53 +01:00
[MVCPath('/search/($searchtext)/($page)')]
[MVCProduces('text/plain')]
2013-11-09 10:32:54 +01:00
procedure SearchCustomers(CTX: TWebContext);
2013-11-10 01:03:53 +01:00
[MVCHTTPMethod([httpGet])]
[MVCPath('/people/($id)')]
[MVCProduces('application/json')]
procedure GetPerson(CTX: TWebContext);
2013-11-09 10:32:54 +01:00
end;
implementation
uses
2013-11-10 01:03:53 +01:00
System.SysUtils, BusinessObjectsU, Data.DBXJSON;
2013-11-09 10:32:54 +01:00
{ TRoutingSampleController }
2013-11-10 01:03:53 +01:00
procedure TRoutingSampleController.GetPerson(CTX: TWebContext);
var
P: TPerson;
IDPerson: Integer;
begin
IDPerson := CTX.Request.ParamsAsInteger['id'];
{
Use IDPerson to load the person from a database...
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;
2013-11-09 10:32:54 +01:00
procedure TRoutingSampleController.SearchCustomers(CTX: TWebContext);
var
search: string;
2013-11-10 01:03:53 +01:00
P: Integer;
2013-11-09 10:32:54 +01:00
orderby: string;
begin
search := CTX.Request.Params['searchtext'];
2013-11-10 01:03:53 +01:00
P := CTX.Request.ParamsAsInteger['page'];
2013-11-09 10:32:54 +01:00
orderby := '';
if CTX.Request.QueryStringParamExists('order') then
orderby := CTX.Request.QueryStringParam('order');
2013-11-10 01:03:53 +01:00
Render(Format('SEARCHTEXT: "%s", PAGE: %d, ORDERBYFIELD: "%s"', [search, P, orderby]));
2013-11-09 10:32:54 +01:00
end;
end.