50 lines
1.4 KiB
C#
50 lines
1.4 KiB
C#
using Matrix42.Behaviors.Contracts;
|
|
using System;
|
|
using System.Diagnostics;
|
|
using update4u.SPS.Security;
|
|
|
|
namespace Imagoverum.FleetManagement.BizLogic
|
|
{
|
|
public class CarBehavior() : CustomGenericBehavior
|
|
{
|
|
private static readonly string Secured = "***Secured***";
|
|
|
|
private const string PasswordField = "FuelCardPinCode";
|
|
|
|
public override void OnAdding(DbRecord dbRecord, BehaviorActionContext context)
|
|
{
|
|
if (dbRecord.Data["IMGVCarClass"]["Name"].ToString() == "Test")
|
|
{
|
|
dbRecord.Data["IMGVCarClass"]["Name"] = "Specify choice";
|
|
}
|
|
|
|
EncryptPasswordField(dbRecord, context, isNew: true);
|
|
|
|
base.OnAdding(dbRecord, context);
|
|
}
|
|
|
|
public override void OnModifing(DbRecord dbRecord, BehaviorActionContext context)
|
|
{
|
|
EncryptPasswordField(dbRecord, context, isNew: false);
|
|
|
|
base.OnModifing(dbRecord, context);
|
|
}
|
|
|
|
private void EncryptPasswordField(DbRecord dbRecord, BehaviorActionContext context, bool isNew)
|
|
{
|
|
if (isNew || dbRecord.Data["IMGVCarClass"][PasswordField].ToString() != Secured)
|
|
{
|
|
dbRecord.Data["IMGVCarClass"][PasswordField] = CryptoManager.Instance.EncryptDBText(dbRecord.Data["IMGVCarClass"][PasswordField].ToString());
|
|
}
|
|
else if (dbRecord.Data["IMGVCarClass"][PasswordField].ToString() == Secured)
|
|
{
|
|
var oldRecordData = context?.OldValue?.Data;
|
|
if (oldRecordData != null)
|
|
{
|
|
dbRecord.Data["IMGVCarClass"][PasswordField] = oldRecordData["IMGVCarClass"][PasswordField];
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|