Description of the object changes according to the preset conditions

change to the data object

There are times when you can prevent the changing of any fields in the object only if it satisfies certain conditions relative to the old value of the same field. However, at the time of exposure of the object in the business server (in method OnUpdate), information about the old value of the field is already missing.

The old value field, you can learn subtracts it from the database, because the changed object is stored in application memory, but the changes were not yet in the database.

Example

In the Bank in which you plan to use this system, you have the following rule: loan period defined for the customer when the loan may be extended, but it is sure to increase the amount of the loan (imposition of fines). Thus, the term of the loan may not be reduced, only increased.

  • Create business server for class Кредит (if it has not yet been created).
  • PstrfOnUpdate` in the method write the following code:
if (UpdatedObject.GetStatus() == ObjectStatus.Altered)
{
    var newValue = UpdatedObject;
    var ds = (MSSQLDataService)DataService;
    var oldValue = ds.Query<Кредит>(Кредит.Views.КредитE).Where(k => k.__PrimaryKey == UpdatedObject.__PrimaryKey).First();

    if (newValue.СрокКредита > oldValue.СрокКредита && newValue.СуммаКредита <= oldValue.СуммаКредита)
        throw new Exception("If you change the term of the loan the loan amount needs to increase.");

    if (newValue.СрокКредита < oldValue.СрокКредита)
        throw new Exception("The term of the loan can't decline.");
}

oldValue can be obtained, and thus:

LoadingCustomizationStruct lcs = LoadingCustomizationStruct.GetSimpleStruct(typeof(Кредит), Кредит.Views.КредитE);
var ld = SQLWhereLanguageDef.LanguageDef;
lcs.LimitFunction = ld.GetFunction(ld.funcEQ, new VariableDef(ld.GuidType, "Client"), UpdatedObject.Клиент.__PrimaryKey);
var oldValue = DataService.LoadObjects(lcs)[0) as Кредит;
UpdatedObject.GetStatus() == ObjectStatus.Altered

If such verification status are truncated when the object is created or deleted.

Thus we can check the entered data on the basis of already existing data.

Переведено сервисом «Яндекс.Переводчик» http://translate.yandex.ru