delphimvcframework/samples/articles_crud_server/BusinessObjects.pas

126 lines
2.7 KiB
ObjectPascal
Raw Normal View History

2014-06-27 15:30:39 +02:00
unit BusinessObjects;
interface
uses
2020-02-05 23:46:38 +01:00
MVCFramework.Serializer.Commons, MVCFramework.Nullables;
2014-06-27 15:30:39 +02:00
type
TBaseBO = class
private
FID: Integer;
procedure SetID(const Value: Integer);
public
procedure CheckInsert; virtual;
procedure CheckUpdate; virtual;
procedure CheckDelete; virtual;
property ID: Integer read FID write SetID;
end;
[MVCNameCase(ncLowerCase)]
2014-06-27 15:30:39 +02:00
TArticle = class(TBaseBO)
private
FPrice: Currency;
FCode: string;
2020-02-05 23:46:38 +01:00
FDescription: String;
2020-11-05 15:42:31 +01:00
FUpdatedAt: TDateTime;
FCreatedAt: TDateTime;
2014-06-27 15:30:39 +02:00
procedure SetCode(const Value: string);
2020-02-05 23:46:38 +01:00
procedure SetDescription(const Value: String);
2014-06-27 15:30:39 +02:00
procedure SetPrice(const Value: Currency);
2020-11-05 15:42:31 +01:00
procedure SetCreatedAt(const Value: TDateTime);
procedure SetUpdatedAt(const Value: TDateTime);
2014-06-27 15:30:39 +02:00
public
2014-06-30 12:32:43 +02:00
procedure CheckInsert; override;
procedure CheckUpdate; override;
2014-06-27 15:30:39 +02:00
procedure CheckDelete; override;
[MVCColumn('CODICE')]
2014-06-27 15:30:39 +02:00
property Code: string read FCode write SetCode;
[MVCColumn('DESCRIZIONE')]
2020-02-05 23:46:38 +01:00
property Description: String read FDescription write SetDescription;
[MVCColumn('PREZZO')]
2014-06-27 15:30:39 +02:00
property Price: Currency read FPrice write SetPrice;
2020-11-05 15:42:31 +01:00
[MVCColumn('CREATED_AT')]
property CreatedAt: TDateTime read FCreatedAt write SetCreatedAt;
[MVCColumn('UPDATED_AT')]
property UpdatedAt: TDateTime read FUpdatedAt write SetUpdatedAt;
2014-06-27 15:30:39 +02:00
end;
implementation
uses
System.SysUtils, System.RegularExpressions;
2014-06-27 15:30:39 +02:00
{ TBaseBO }
procedure TBaseBO.CheckDelete;
begin
end;
procedure TBaseBO.CheckInsert;
begin
end;
procedure TBaseBO.CheckUpdate;
begin
end;
procedure TBaseBO.SetID(const Value: Integer);
begin
FID := Value;
end;
{ TArticolo }
procedure TArticle.CheckDelete;
begin
inherited;
if Price <= 5 then
raise Exception.Create('Cannot delete an article with a price below 5 euros (yes, it is a silly check)');
2014-06-27 15:30:39 +02:00
end;
2014-06-30 12:32:43 +02:00
procedure TArticle.CheckInsert;
begin
inherited;
if not TRegEx.IsMatch(Code, '^C[0-9]{2,4}') then
raise Exception.Create('Article code must be in the format "CXX or CXXX or CXXXX"');
2014-06-30 12:32:43 +02:00
end;
procedure TArticle.CheckUpdate;
begin
inherited;
CheckInsert;
if Price <= 2 then
raise Exception.Create('We cannot sell so low cost pizzas!');
2014-06-30 12:32:43 +02:00
end;
2014-06-27 15:30:39 +02:00
procedure TArticle.SetCode(const Value: string);
begin
FCode := Value;
end;
2020-11-05 15:42:31 +01:00
procedure TArticle.SetCreatedAt(const Value: TDateTime);
begin
FCreatedAt := Value;
end;
2020-02-05 23:46:38 +01:00
procedure TArticle.SetDescription(const Value: String);
2014-06-27 15:30:39 +02:00
begin
FDescription := Value;
end;
procedure TArticle.SetPrice(const Value: Currency);
begin
FPrice := Value;
end;
2020-11-05 15:42:31 +01:00
procedure TArticle.SetUpdatedAt(const Value: TDateTime);
begin
FUpdatedAt := Value;
end;
2014-06-27 15:30:39 +02:00
end.