narsil/Tanshu.Accounts.Repository/VoucherDirtyInterceptor.cs

44 lines
1.3 KiB
C#
Raw Normal View History

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using NHibernate;
using Tanshu.Accounts.Entities;
namespace Tanshu.Accounts.Repository
{
public class VoucherDirty : EmptyInterceptor
{
public override int[] FindDirty(object entity, object id, object[] currentState, object[] previousState, string[] propertyNames, NHibernate.Type.IType[] types)
{
var result = new List<int>();
// we do not care about other entities here
if (!(entity is Voucher))
{
return null;
}
var length = propertyNames.Length;
// iterate all properties
for (var i = 0; i < length; i++)
{
bool areEqual;
if (currentState[i] == null)
areEqual = previousState[i] == null;
else
areEqual = currentState[i].Equals(previousState[i]);
var isResettingProperty = propertyNames[i] == "LastEditDate";
if (!areEqual || isResettingProperty)
{
result.Add(i); // the index of "Code" property will be added always
}
}
return result.ToArray();
}
}
}