public override int GetHashCode() { unchecked { return((BankAccountId.GetHashCode() * 397) ^ UnixTimestamp.GetHashCode()); } }
public async Task Handle(RefundMoney refundMoney, IMessageHandlerContext context) { try { log.Info($"RefundMoneyHandler, BankAccountId = {refundMoney.BankAccountId}"); var nHibernateSession = context.SynchronizedStorageSession.Session(); var bankAccountId = BankAccountId.FromExisting(refundMoney.BankAccountId); var bankAccount = nHibernateSession.Get <BankAccount>(bankAccountId) ?? BankAccount.NonExisting(); if (bankAccount.DoesNotExist()) { var fromBankAccountNotFound = new FromBankAccountNotFound(refundMoney.BankAccountId); await context.Publish(fromBankAccountNotFound); return; } bankAccount.Refund(refundMoney.Amount); nHibernateSession.Save(bankAccount); var moneyRefunded = new MoneyRefunded ( bankAccount.BankAccountId.Id, refundMoney.Amount ); await context.Publish(moneyRefunded); } catch (Exception ex) { log.Error(ex.Message + " ** " + ex.StackTrace); } }
public TransferAccount(BankAccountId id, BankAccountName name, BankName bank, TransferAccountType accountType) { Id = id; Name = name; Bank = bank; AccountType = accountType; }
public async Task <IEnumerable <WireTransfer> > GetIncomingTransfers( BankAccountId beneficiaryBankAccountId, TransactionId transactionId) { var builder = Builders <WireTransferMongoDocument> .Filter; var filterByTransaction = builder.Eq(x => x.BeneficiaryAccountId, beneficiaryBankAccountId.Value.ToString()); if (!transactionId.Value.Equals(Guid.Empty)) { filterByTransaction &= builder.Eq(x => x.TransactionId, transactionId.Value.ToString()); } var connection = _connectionFactory.GetCqrsConnection(); var wireTransferCollection = connection.GetCollection <WireTransferMongoDocument>(DbNames.WireTransfersInCqrsCollectionName); var document = await wireTransferCollection .Find(filterByTransaction).ToListAsync(); if (!document.Any()) { throw new NotFoundException("No wire transfers found for this beneficiary"); } return(document.Select(x => x.WrapToWireTransfer())); }
public WithdrawTransactionReadiedDomainEvent( BankAccountId accountId, WithdrawTransactionStatus status) { AccountId = accountId; Status = status; }
public async Task Handle(DepositMoney depositMoney, IMessageHandlerContext context) { try { log.Info($"DepositMoneyHandler, TransactionId = {depositMoney.TransactionId}"); var nHibernateSession = context.SynchronizedStorageSession.Session(); var bankAccountId = BankAccountId.FromExisting(depositMoney.ToBankAccountId); var toBankAccount = nHibernateSession.Get <BankAccount>(bankAccountId) ?? BankAccount.NonExisting(); if (toBankAccount.DoesNotExist()) { var toBankAccountNotFound = new ToBankAccountNotFound(depositMoney.TransactionId); await context.Publish(toBankAccountNotFound); return; } toBankAccount.Deposit(depositMoney.Amount); toBankAccount.ChangeUpdatedAt(); nHibernateSession.Save(toBankAccount); var moneyDeposited = new MoneyDeposited ( depositMoney.TransactionId, toBankAccount.BankAccountId.Id, depositMoney.Amount, toBankAccount.Balance.Amount ); await context.Publish(moneyDeposited); } catch (Exception ex) { log.Error(ex.Message + " ** " + ex.StackTrace); } }
public DepositTransactionReadiedDomainEvent( BankAccountId accountId, DepositTransactionStatus status) { AccountId = accountId; Status = status; }
public WithdrawTransactionStartedDomainEvent( BankAccountId accountId, BankAccountName accountName, BankName bank, Money money) { AccountId = accountId; AccountName = accountName; Bank = bank; Money = money; }
public WithdrawTransaction( WithdrawTransactionId id, BankAccountId accountId, BankAccountName accountName, BankName bank, Money money) : base(id) { AccountId = accountId; AccountName = accountName; Bank = bank; Money = money; Status = WithdrawTransactionStatus.Started; }
public StartWithdrawTransactionDomainCommand( WithdrawTransactionId transactionId, BankAccountId accountId, BankAccountName accountName, Money money, BankName bank) { AggregateRootId = transactionId; AccountId = accountId; AccountName = accountName; Money = money; Bank = bank; }
public bool Equals(BankAccountEvent?other) { if (ReferenceEquals(null, other)) { return(false); } if (ReferenceEquals(this, other)) { return(true); } return(BankAccountId.Equals(other.BankAccountId) && UnixTimestamp == other.UnixTimestamp); }
public static BankAccount NonExisting() { DateTime Now = DateTime.Now; BankAccountId bankAccountId = BankAccountId.FromExisting(null); CustomerId customerId = CustomerId.FromExisting(null); return(new BankAccount( bankAccountId, null, null, BankAccountStateId.NULL, Now, Now, customerId)); }
public static Transaction NonExisting() { DateTime Now = DateTime.Now; TransactionId transactionId = TransactionId.FromExisting(null); BankAccountId fromBankAccountId = BankAccountId.FromExisting(null); BankAccountId toBankAccountId = BankAccountId.FromExisting(null); return(new Transaction( transactionId, fromBankAccountId, toBankAccountId, null, TransactionStateId.NULL, Now, Now)); }
protected BankAccount( BankAccountId bankAccountId, BankAccountNumber bankAccountNumber, Money balance, BankAccountStateId bankAccountStateId, DateTime createdAt, DateTime updatedAt, CustomerId customerId) { BankAccountId = bankAccountId; BankAccountNumber = bankAccountNumber; Balance = balance; BankAccountStateId = bankAccountStateId; CreatedAt = createdAt; UpdatedAt = updatedAt; CustomerId = customerId; }
public static BankAccount From( BankAccountId bankAccountId, BankAccountNumber bankAccountNumber, Money balance, BankAccountStateId bankAccountStateId, DateTime createdAt, DateTime updatedAt, CustomerId customerId) { return(new BankAccount( bankAccountId, bankAccountNumber, balance, bankAccountStateId, createdAt, updatedAt, customerId)); }
public Transaction( TransactionId transactionId, BankAccountId fromBankAccountId, BankAccountId toBankAccountId, Money amount, TransactionStateId transactionStateId, DateTime createdAt, DateTime updatedAt ) { TransactionId = transactionId; FromBankAccountId = fromBankAccountId; ToBankAccountId = toBankAccountId; Amount = amount; TransactionStateId = transactionStateId; CreatedAt = createdAt; UpdatedAt = updatedAt; }
/// <summary> /// When user change the BankID of transaction it is necessary to delete this transaction from BankAccount that not belong to anymore And add transaction to the list of transaction of new BankAccount. /// /// <para>This function fires up an event that BankAccount Subscribed, and the BankAccount fires up an event that User subscribe. /// If User private delegate will say that BankAccount with given ID exists it will move transaction to choosen BankAccount list. </para> /// /// <para>Throws DomainException with error code= "bank_acc_nfound" if BankAccount with given ID won't be found</para> /// </summary> /// <param name="bankAccountId"> id of new bank account</param> public virtual void setBankAccount(int bankAccountId) { if (bankAccountId.isEmpty()) { throw new DomainException(DomainErrorCodes.EmptyId); } if (BankAccountId.isEmpty()) { BankAccountId = bankAccountId; } else if (BankAccountId != bankAccountId) { if (BankAccountIDChanedEvent.Invoke(this, bankAccountId)) { BankAccountId = bankAccountId; } } }
public async Task Handle(WithdrawMoney withdrawMoney, IMessageHandlerContext context) { try { log.Info($"WithdrawMoneyHandler, TransactionId = {withdrawMoney.TransactionId}"); var nHibernateSession = context.SynchronizedStorageSession.Session(); var bankAccountId = BankAccountId.FromExisting(withdrawMoney.FromBankAccountId); var fromBankAccount = nHibernateSession.Get <BankAccount>(bankAccountId) ?? BankAccount.NonExisting(); if (fromBankAccount.DoesNotExist()) { var fromBankAccountNotFound = new FromBankAccountNotFound(withdrawMoney.TransactionId); await context.Publish(fromBankAccountNotFound); return; } if (fromBankAccount.CanBeWithdrawed(withdrawMoney.Amount)) { fromBankAccount.Withdraw(withdrawMoney.Amount); fromBankAccount.ChangeUpdatedAt(); nHibernateSession.Save(fromBankAccount); var moneyWithdrawn = new MoneyWithdrawn ( withdrawMoney.TransactionId, withdrawMoney.FromBankAccountId, withdrawMoney.Amount, fromBankAccount.Balance.Amount ); await context.Publish(moneyWithdrawn); return; } var withdrawRejected = new WithdrawRejected ( withdrawMoney.TransactionId ); await context.Publish(withdrawRejected); } catch (Exception ex) { log.Error(ex.Message + " ** " + ex.StackTrace); } }
public override int GetHashCode() { int hashCode = 388412647; if (Context != null) { hashCode += Context.GetHashCode(); } if (Id != null) { hashCode += Id.GetHashCode(); } if (Status != null) { hashCode += Status.GetHashCode(); } if (TotalMoney != null) { hashCode += TotalMoney.GetHashCode(); } if (InitiatedAt != null) { hashCode += InitiatedAt.GetHashCode(); } if (BankAccountId != null) { hashCode += BankAccountId.GetHashCode(); } if (Entries != null) { hashCode += Entries.GetHashCode(); } return(hashCode); }
public override bool Equals(object obj) { if (obj == null) { return(false); } if (obj == this) { return(true); } return(obj is V1Settlement other && ((Context == null && other.Context == null) || (Context?.Equals(other.Context) == true)) && ((Id == null && other.Id == null) || (Id?.Equals(other.Id) == true)) && ((Status == null && other.Status == null) || (Status?.Equals(other.Status) == true)) && ((TotalMoney == null && other.TotalMoney == null) || (TotalMoney?.Equals(other.TotalMoney) == true)) && ((InitiatedAt == null && other.InitiatedAt == null) || (InitiatedAt?.Equals(other.InitiatedAt) == true)) && ((BankAccountId == null && other.BankAccountId == null) || (BankAccountId?.Equals(other.BankAccountId) == true)) && ((Entries == null && other.Entries == null) || (Entries?.Equals(other.Entries) == true))); }
public async Task <WireTransfer> GetIncomingTransferById(BankAccountId beneficiaryBankAccountId, WireTransferId wireTransferId) { var builder = Builders <WireTransferMongoDocument> .Filter; var filterByTransaction = builder.Where(x => x.WireTransferId == wireTransferId.Value.ToString() && x.BeneficiaryAccountId == beneficiaryBankAccountId.Value.ToString()); var connection = _connectionFactory.GetCqrsConnection(); var wireTransferCollection = connection.GetCollection <WireTransferMongoDocument>(DbNames.WireTransfersInCqrsCollectionName); var document = await wireTransferCollection .Find(filterByTransaction).FirstOrDefaultAsync(); if (document is null) { throw new NotFoundException("No wire transfers found for this code"); } return(document.WrapToWireTransfer()); }
/// <summary> /// Throws Exception When Trying to add emptyID, when bankAccountId was not found or when trying to set Source and Destination Bank Id to the same value /// </summary> /// <param name="bankAccountId"></param> public void setSourceBankAccount(int bankAccountId) { if (bankAccountId.isEmpty()) { throw new DomainException(DomainErrorCodes.EmptyId); } if (bankAccountId == DestinationBankAccountId) { throw new DomainException(DomainErrorCodes.SourceAndDestiantionIDCantBeSame); } if (BankAccountId.isEmpty()) { BankAccountId = bankAccountId; } else if (BankAccountId != bankAccountId) { if (SourceBankAccountIDChanedEvent.Invoke(this, bankAccountId)) { BankAccountId = bankAccountId; } } }
public TransferTransactionReadiedDomainEvent(BankAccountId sourceAccountId, BankAccountId sinkAccountId, TransferTransactionStatus status) { SourceAccountId = sourceAccountId; SinkAccountId = sinkAccountId; Status = status; }
private int generateTransactionId() { String bankAccId = BankAccountId.ToString() + TransactionHistory.Count.ToString(); return(int.Parse(bankAccId)); }
public virtual bool Exist() { return(BankAccountId != null && BankAccountId.Ok()); }
public virtual bool DoesNotExist() { return(BankAccountId == null || !BankAccountId.Ok()); }
public BankAccountImpl(BankAccountId id, Money barance) { Id = id; Barance = barance; }
public BankAccountImpl(BankAccountId id) : this(id, Money.Zero()) { }
/// <summary> /// Gets the hash code /// </summary> /// <returns>Hash code</returns> public override int GetHashCode() { unchecked // Overflow is fine, just wrap { var hashCode = 41; // Suitable nullity checks etc, of course :) if (BankAccountId != null) { hashCode = hashCode * 59 + BankAccountId.GetHashCode(); } if (Nickname != null) { hashCode = hashCode * 59 + Nickname.GetHashCode(); } if (CurrencyId != null) { hashCode = hashCode * 59 + CurrencyId.GetHashCode(); } if (AccountHolder != null) { hashCode = hashCode * 59 + AccountHolder.GetHashCode(); } if (AccountNumber != null) { hashCode = hashCode * 59 + AccountNumber.GetHashCode(); } if (Iban != null) { hashCode = hashCode * 59 + Iban.GetHashCode(); } if (BankName != null) { hashCode = hashCode * 59 + BankName.GetHashCode(); } if (SortCode != null) { hashCode = hashCode * 59 + SortCode.GetHashCode(); } if (RoutingNumber != null) { hashCode = hashCode * 59 + RoutingNumber.GetHashCode(); } if (SwiftBic != null) { hashCode = hashCode * 59 + SwiftBic.GetHashCode(); } if (IfscCode != null) { hashCode = hashCode * 59 + IfscCode.GetHashCode(); } if (RoutingCode != null) { hashCode = hashCode * 59 + RoutingCode.GetHashCode(); } if (UserAddressId != null) { hashCode = hashCode * 59 + UserAddressId.GetHashCode(); } if (BankAddress != null) { hashCode = hashCode * 59 + BankAddress.GetHashCode(); } return(hashCode); } }
/// <summary> /// Returns true if BankAccount instances are equal /// </summary> /// <param name="other">Instance of BankAccount to be compared</param> /// <returns>Boolean</returns> public bool Equals(BankAccount other) { if (ReferenceEquals(null, other)) { return(false); } if (ReferenceEquals(this, other)) { return(true); } return (( BankAccountId == other.BankAccountId || BankAccountId != null && BankAccountId.Equals(other.BankAccountId) ) && ( Nickname == other.Nickname || Nickname != null && Nickname.Equals(other.Nickname) ) && ( CurrencyId == other.CurrencyId || CurrencyId != null && CurrencyId.Equals(other.CurrencyId) ) && ( AccountHolder == other.AccountHolder || AccountHolder != null && AccountHolder.Equals(other.AccountHolder) ) && ( AccountNumber == other.AccountNumber || AccountNumber != null && AccountNumber.Equals(other.AccountNumber) ) && ( Iban == other.Iban || Iban != null && Iban.Equals(other.Iban) ) && ( BankName == other.BankName || BankName != null && BankName.Equals(other.BankName) ) && ( SortCode == other.SortCode || SortCode != null && SortCode.Equals(other.SortCode) ) && ( RoutingNumber == other.RoutingNumber || RoutingNumber != null && RoutingNumber.Equals(other.RoutingNumber) ) && ( SwiftBic == other.SwiftBic || SwiftBic != null && SwiftBic.Equals(other.SwiftBic) ) && ( IfscCode == other.IfscCode || IfscCode != null && IfscCode.Equals(other.IfscCode) ) && ( RoutingCode == other.RoutingCode || RoutingCode != null && RoutingCode.Equals(other.RoutingCode) ) && ( UserAddressId == other.UserAddressId || UserAddressId != null && UserAddressId.Equals(other.UserAddressId) ) && ( BankAddress == other.BankAddress || BankAddress != null && BankAddress.Equals(other.BankAddress) )); }
public BankAccountBuilder WithBankAccountId(Guid bankAccountId) { BankAccountId = new BankAccountId(bankAccountId); return(this); }