Exemplo n.º 1
0
        public static Transaction ToEntity(this TransactionModel model)
        {
            var transaction = new Transaction(
                CurrencyType.FromValue(model.Currency).ToCurrency(model.Amount),
                new TransactionDescription(model.Description),
                TransactionType.FromValue(model.Type),
                new DateTimeProvider(model.Timestamp),
                new TransactionMetadata(model.Metadata.ToDictionary(metadata => metadata.Key, metadata => metadata.Value)));

            transaction.SetEntityId(model.Id);

            var status = TransactionStatus.FromValue(model.Status);

            if (status == TransactionStatus.Succeeded)
            {
                transaction.MarkAsSucceeded();
            }

            if (status == TransactionStatus.Failed)
            {
                transaction.MarkAsFailed();
            }

            transaction.ClearDomainEvents();

            return(transaction);
        }