private string GetReceivedAddress(EmailQueue emailQueue)
        {
            try
            {
                if (emailQueue.IsInnerTransaction == false)
                {
                    return(GetTransaction(emailQueue).ToAddress);
                }
                using (var internalTransactionsRepository = new InternalTransactionsRepository(_connectionDb))
                {
                    var transaction = internalTransactionsRepository.FindById(emailQueue.TransactionId);

                    using (var userRepository = new UserRepository(_connectionDb))
                    {
                        var user = userRepository.FindById(transaction.ReceiverUserId);
                        return(user.mem_id);
                    }
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                throw;
            }
        }
        private string GetSender(EmailQueue emailQueue)
        {
            try
            {
                using (var internalTransactionsRepository = new InternalTransactionsRepository(_connectionDb))
                {
                    using (var userRepository = new UserRepository(_connectionDb))
                    {
                        var transaction = internalTransactionsRepository.FindById(emailQueue.TransactionId);

                        var user = userRepository.FindById(transaction.SenderUserId);
                        return(user.mem_id);
                    }
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                throw;
            }
        }
        private ReturnObject AddSendTransactionToEmailAddress(UserSendTransaction sendTransaction)
        {
            if (_connectionDb.State != ConnectionState.Open)
            {
                _connectionDb.Open();
            }


            using (var userRepository = new UserRepository(_connectionDb))
            {
                var sender   = userRepository.FindById(sendTransaction.UserId);
                var receiver = userRepository.FindByEmailAddress(sendTransaction.To);

                if (sender == null)
                {
                    return(new ReturnObject()
                    {
                        Status = Status.STATUS_ERROR,
                        Message = "Sender UserID not found in Vakapay system"
                    });
                }

                if (receiver == null)
                {
                    return(new ReturnObject()
                    {
                        Status = Status.STATUS_ERROR,
                        Message = "Email address not found in Vakapay system"
                    });
                }


                using (var sendTransactionRepository = new UserSendTransactionRepository(_connectionDb))
                {
                    var insertTrx = _connectionDb.BeginTransaction();
                    var insertRes = sendTransactionRepository.Insert(sendTransaction);

                    if (insertRes.Status == Status.STATUS_ERROR)
                    {
                        insertTrx.Rollback();
                        return(insertRes);
                    }

                    var internalTransactions = new InternalWithdrawTransaction()
                    {
                        SenderUserId   = sendTransaction.UserId,
                        ReceiverUserId = receiver.Id,
                        Amount         = sendTransaction.Amount,
                        PricePerCoin   = sendTransaction.PricePerCoin,
                        Currency       = sendTransaction.Currency,
                        Idem           = sendTransaction.Idem,
                        Description    = sendTransaction.Description
                    };

                    using (var internalTransactionsRepository = new InternalTransactionsRepository(_connectionDb))
                    {
                        insertRes = internalTransactionsRepository.Insert(internalTransactions);

                        if (insertRes.Status == Status.STATUS_ERROR)
                        {
                            insertTrx.Rollback();
                            return(insertRes);
                        }

                        insertTrx.Commit();

                        var sendTrx = _connectionDb.BeginTransaction();
                        var senRes  = SendInternalTransaction(internalTransactions);
                        if (senRes.Status == Status.STATUS_ERROR)
                        {
                            sendTrx.Rollback();
                            internalTransactionsRepository.Update(internalTransactions);
                            return(senRes);
                        }

                        var updateRes = internalTransactionsRepository.Update(internalTransactions);


                        if (updateRes.Status == Status.STATUS_ERROR)
                        {
                            sendTrx.Rollback();
                            return(new ReturnObject()
                            {
                                Status = Status.STATUS_ERROR,
                                Message = "Fail to update send status"
                            });
                        }


                        sendTrx.Commit();


                        var email = sender.Email;
                        if (email != null)
                        {
                            var res = SendMailBusiness.SendMailBusiness.CreateDataEmail(
                                "Notify send " + sendTransaction.Currency,
                                email, internalTransactions.Amount, internalTransactions.Id,
                                EmailTemplate.Sent, internalTransactions.Currency, _vakapayRepositoryFactory, true);
                            res.Wait();
                        }

                        var receiverEmail = receiver.Email;
                        if (receiverEmail != null)
                        {
                            var res = SendMailBusiness.SendMailBusiness.CreateDataEmail(
                                "Notify receive " + sendTransaction.Currency, receiverEmail,
                                internalTransactions.Amount,
                                internalTransactions.Id, EmailTemplate.ReceivedInternal, internalTransactions.Currency,
                                _vakapayRepositoryFactory, true);
                            res.Wait();
                        }

                        return(new ReturnObject()
                        {
                            Status = Status.STATUS_SUCCESS,
                            Message = "Transaction Sent!"
                        });
                    }
                }
            }
        }
Ejemplo n.º 4
0
        internal void Execute()
        {
            SkbRepository skbRepo = new SkbRepository();

            string bank = pathAnalyst.Bank;

            consoleReporter.WriteLine("Analysing bank: {0}", bank);
            Dictionary <string, int> countTypes = new Dictionary <string, int>();

            foreach (Account account in pathAnalyst.Accounts)
            {
                consoleReporter.WriteLine(account.Fullname);
                consoleReporter.WriteLine(account.ToString());

                foreach (var item in account.Items)
                {
                    skbRepo.Add(item);
                    if (!countTypes.ContainsKey(item.Type))
                    {
                        countTypes.Add(item.Type, 0);
                    }
                    countTypes[item.Type]++;
                }
            }

            foreach (var typecount in countTypes)
            {
                consoleReporter.WriteLine("{0}: {1}", typecount.Key, typecount.Value);
            }

            //Extract internal transactions
            consoleReporter.WriteLine("\n\nBegin: {0} lines", skbRepo.GetAll().Count);

            InternalTransactionsRepository internalRepo = new InternalTransactionsRepository();
            InternalMatcher internalMatcher             = new InternalMatcher(skbRepo, internalRepo);

            internalMatcher.Match(InternalMatcher.MatchOnAll);
            consoleReporter.WriteLine("\nAfter 1 run: {0} lines, {1} matches", skbRepo.GetAll().Count, internalRepo.GetAll().Count);

            internalMatcher.Match(InternalMatcher.MatchOnMost);
            consoleReporter.WriteLine("\nAfter 2 run: {0} lines, {1} matches", skbRepo.GetAll().Count, internalRepo.GetAll().Count);

            List <AccountLine> positiveLines = AccountLineFilterService.GetPositiveLines(internalRepo.GetAll());
            var internalSum = AccountLineAggregatorService.Sum(positiveLines);

            consoleReporter.WriteLine("\nTotal internal transactions: {0}", internalSum);
            //Extract internal transactions END

            PayeeRepository payeeRepo      = new PayeeRepository();
            PayeeExtractor  payeeExtractor = new PayeeExtractor(skbRepo, payeeRepo, consoleReporter);

            payeeExtractor.ExtractPayees();

            foreach (var payee in payeeRepo.GetAll())
            {
                consoleReporter.WriteLine("{0}", payee);
            }

            //consoleReporter.WriteLine("\n\nLines POST PROCESSING");
            //skbRepo.GetAll().ForEach(resitem => consoleReporter.WriteLine("{0}", resitem.Desc));

            ReportAllSkbLines(skbRepo, consoleReporter);

            this.filePersistor.Persist(skbRepo.GetAll());
        }