Skip to content

Commit

Permalink
Improved address appearance in change log
Browse files Browse the repository at this point in the history
  • Loading branch information
tatarincev committed Apr 17, 2018
1 parent aee36a8 commit e2d2b20
Showing 1 changed file with 15 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Threading.Tasks;
using VirtoCommerce.Domain.Commerce.Model;
using VirtoCommerce.Domain.Common.Events;
Expand Down Expand Up @@ -141,16 +142,28 @@ protected virtual IEnumerable<string> GetAddressChanges(IOperation operation, IE
{
if (state == EntryState.Added)
{
result.Add(string.Format(OrderResources.AddressAdded, operation.OperationType, operation.Number, target.ToString()));
result.Add(string.Format(OrderResources.AddressAdded, operation.OperationType, operation.Number, StringifyAddress(target)));
}
else if (state == EntryState.Deleted)
{
result.Add(string.Format(OrderResources.AddressRemoved, operation.OperationType, operation.Number, target.ToString()));
result.Add(string.Format(OrderResources.AddressRemoved, operation.OperationType, operation.Number, StringifyAddress(target)));
}
});
return result;
}

protected virtual string StringifyAddress(Address address)
{
var result = "";
if(address != null)
{
return string.Join(", ", typeof(Address).GetProperties(BindingFlags.Instance | BindingFlags.Public)
.OrderBy(p => p.Name)
.Select(p=> p.GetValue(address))
.Where(x=> x != null));
}
return result;
}

protected virtual OperationLog GetLogRecord(IOperation operation, string template)
{
Expand Down

2 comments on commit e2d2b20

@Woland2k
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@tatarincev why not add .ToString() override in Address object instead?

@tatarincev
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change was required Core module modifications (because valueObject.ToString() doesn't produce right string for log). I'll definitely add this method to Address in next Core module release.

Please sign in to comment.