public async Task AddPaymentTransferRefundAsync(PaymentTransferDto paymentTransfer)
        {
            using (var context = _contextFactory.CreateDataContext())
            {
                var historyEntity  = TransactionHistoryEntity.CreateForPaymentTransferRefund(paymentTransfer);
                var transferEntity = PaymentTransferRefundEntity.Create(paymentTransfer);

                var burnRule =
                    await context.BurnRules.FindAsync(paymentTransfer.BurnRuleId);

                if (burnRule != null && burnRule.BurnRuleName != paymentTransfer.BurnRuleName)
                {
                    burnRule.BurnRuleName = paymentTransfer.BurnRuleName;
                }

                if (burnRule == null)
                {
                    burnRule = BurnRuleEntity.Create(paymentTransfer.BurnRuleId, paymentTransfer.BurnRuleName);
                }

                transferEntity.BurnRule = burnRule;

                context.RefundedPaymentTransfers.Add(transferEntity);
                context.TransactionHistories.Add(historyEntity);

                await context.SaveChangesAsync();
            }
        }
Пример #2
0
        public async Task AddAsync(BonusCashInDto bonusCashIn)
        {
            using (var context = _contextFactory.CreateDataContext())
            {
                var historyEntity = TransactionHistoryEntity.Create(bonusCashIn);
                var bonusEntity   = BonusCashInEntity.Create(bonusCashIn);

                var campaign = await context.Campaigns.FindAsync(bonusCashIn.CampaignId);

                if (campaign != null && campaign.CampaignName != bonusCashIn.CampaignName)
                {
                    campaign.CampaignName = bonusCashIn.CampaignName;
                }

                if (campaign == null)
                {
                    campaign = CampaignEntity.Create(bonusCashIn.CampaignId, bonusCashIn.CampaignName);
                }

                bonusEntity.Campaign = campaign;

                context.BonusCashIns.Add(bonusEntity);
                context.TransactionHistories.Add(historyEntity);

                await context.SaveChangesAsync();
            }
        }
        public async Task AddReferralStakeReleasedAsync(ReferralStakeDto referralStake)
        {
            using (var context = _contextFactory.CreateDataContext())
            {
                var historyEntity = TransactionHistoryEntity.CreateForReferralStakeTokensRelease(referralStake);
                var releasedReferralStakeEntity = ReleasedReferralStakeEntity.Create(referralStake);

                var campaign = await context.Campaigns.FindAsync(referralStake.CampaignId);

                if (campaign != null && campaign.CampaignName != referralStake.CampaignName)
                {
                    campaign.CampaignName = referralStake.CampaignName;
                }

                if (campaign == null)
                {
                    campaign = CampaignEntity.Create(referralStake.CampaignId, referralStake.CampaignName);
                }

                releasedReferralStakeEntity.Campaign = campaign;

                context.ReleasedReferralStakes.Add(releasedReferralStakeEntity);
                context.TransactionHistories.Add(historyEntity);

                await context.SaveChangesAsync();
            }
        }
        public void RunTradingSimulation()
        {
            TradingSimulation tradingSimulation = new TradingSimulation(dbContext);
            UserEntity        seller            = tradingSimulation.ChooseARandomUser();
            UserEntity        customer          = tradingSimulation.ChooseARandomUser();

            while (seller.Equals(customer))
            {
                customer = tradingSimulation.ChooseARandomUser();
            }

            UserAndSharesEntity sellerSharesToThUserEntity = tradingSimulation.SelectSharesAndUser(seller);

            SharesEntity sellerShares = tradingSimulation.ChooseShareskValue(sellerSharesToThUserEntity);

            UserAndSharesEntity customerSharesToThUserEntity = tradingSimulation.SelectStocksForUserObjectParameters(customer, sellerShares);

            int Price = tradingSimulation.RandomNumberGenerator((int)sellerShares.Price);

            int NumberOfShares = tradingSimulation.RandomNumberGenerator(sellerSharesToThUserEntity.AmountStocks);

            tradingSimulation.StockPurchaseTransaction(seller, customer, Price, NumberOfShares, sellerSharesToThUserEntity, customerSharesToThUserEntity);

            TransactionHistoryEntity transactionHistoryEntity = new TransactionHistoryEntity()
            {
                DateTimeBay = DateTime.Now,
                SellerId    = seller.Id,
                CustomerId  = customer.Id,
                AmountShare = NumberOfShares,
                Cost        = Price
            };
            TransactionService transactionService = new TransactionService(dbContext);

            transactionService.RegisterNewTransactionHistory(transactionHistoryEntity);
        }
        public async Task InsertAsync(VoucherPurchasePaymentDto voucherPurchasePaymentOperation)
        {
            using (var context = _contextFactory.CreateDataContext())
            {
                var historyEntity = TransactionHistoryEntity.CreateForVoucherTokenReservation(voucherPurchasePaymentOperation);
                var voucherPurchasePaymentEntity = new VoucherPurchasePaymentEntity(voucherPurchasePaymentOperation);

                context.VoucherPurchasePayments.Add(voucherPurchasePaymentEntity);
                context.TransactionHistories.Add(historyEntity);

                await context.SaveChangesAsync();
            }
        }
        public async Task AddPartnerPaymentRefundAsync(PartnerPaymentDto partnerPayment)
        {
            var historyEntity        = TransactionHistoryEntity.CreateForPartnersPaymentRefund(partnerPayment);
            var partnerPaymentEntity = PartnersPaymentRefundEntity.Create(partnerPayment);

            using (var context = _contextFactory.CreateDataContext())
            {
                context.RefundedPartnersPayments.Add(partnerPaymentEntity);
                context.TransactionHistories.Add(historyEntity);

                await context.SaveChangesAsync();
            }
        }
        public async Task AddAsync(ISmartVoucherPayment payment)
        {
            using (var context = _contextFactory.CreateDataContext())
            {
                var entity        = SmartVoucherPaymentEntity.Create(payment);
                var historyEntity = TransactionHistoryEntity.CreateForSmartVoucherPayment(payment);

                context.SmartVoucherPayments.Add(entity);
                context.TransactionHistories.Add(historyEntity);

                await context.SaveChangesAsync();
            }
        }
Пример #8
0
        private void WriteTransactionHistory(TransactionArguments args, decimal sum)
        {
            var transaction = new TransactionHistoryEntity()
            {
                Seller     = clientTableRepository.GetById(args.SellerId),
                Buyer      = clientTableRepository.GetById(args.BuyerId),
                SelledItem = sharesTableRepository.GetById(args.SharesId),
                Quantity   = args.Quantity,
                Total      = sum,
                DateTime   = DateTime.Now
            };

            transactionHistoryTableRepository.Add(transaction);
            transactionHistoryTableRepository.SaveChanges();
        }
        public async Task AddUseAsync(SmartVoucherUseDto smartVoucher)
        {
            using (var context = _contextFactory.CreateDataContext())
            {
                var entity        = SmartVoucherUseEntity.Create(smartVoucher);
                var historyEntity = TransactionHistoryEntity.CreateForSmartVoucherUse(smartVoucher);

                entity.Campaign = await GetAndUpdateCampaign(context, smartVoucher.CampaignId, smartVoucher.CampaignName);

                context.SmartVoucherUses.Add(entity);
                context.TransactionHistories.Add(historyEntity);

                await context.SaveChangesAsync();
            }
        }
        public async Task AddPaymentAsync(SmartVoucherPaymentDto payment)
        {
            using (var context = _contextFactory.CreateDataContext())
            {
                var entity        = SmartVoucherPaymentEntity.Create(payment);
                var historyEntity = TransactionHistoryEntity.CreateForSmartVoucherPayment(payment);

                entity.Campaign = await GetAndUpdateCampaign(context, payment.CampaignId, payment.CampaignName);

                context.SmartVoucherPayments.Add(entity);
                context.TransactionHistories.Add(historyEntity);

                await context.SaveChangesAsync();
            }
        }
        public async Task AddAsync(LinkedWalletTransferDto transfer)
        {
            using (var context = _contextFactory.CreateDataContext())
            {
                var entity = LinkedWalletTransferEntity.Create(transfer);

                var historyEntity = TransactionHistoryEntity.CreateForLinkedWalletTransfer(transfer);

                context.LinkedWalletTransfers.Add(entity);

                context.TransactionHistories.Add(historyEntity);

                await context.SaveChangesAsync();
            }
        }
        public async Task AddAsync(ITransfer transfer)
        {
            using (var context = _contextFactory.CreateDataContext())
            {
                var transferEntity     = TransferEntity.Create(transfer);
                var historyForSender   = TransactionHistoryEntity.CreateForSender(transfer);
                var historyForReceiver = TransactionHistoryEntity.CreateForReceiver(transfer);

                context.Transfers.Add(transferEntity);
                context.TransactionHistories.Add(historyForSender);
                context.TransactionHistories.Add(historyForReceiver);

                await context.SaveChangesAsync();
            }
        }
Пример #13
0
        public async Task AddAsync(FeeCollectedOperationDto operation)
        {
            using (var context = _contextFactory.CreateDataContext())
            {
                var entity = FeeCollectedOperationEntity.Create(operation);

                var historyEntity = TransactionHistoryEntity.Create(operation);

                context.FeeCollectedOperations.Add(entity);

                context.TransactionHistories.Add(historyEntity);

                await context.SaveChangesAsync();
            }
        }
Пример #14
0
        public int TransactionHistoryLogger(TransactionInfo args, StockEntity stock)
        {
            int transactionID;
            TransactionHistoryEntity historyEntity = new TransactionHistoryEntity();

            historyEntity.SellerBalanceID     = args.SellerBalanceID;
            historyEntity.BuyerBalanceID      = args.BuyerBalanceID;
            historyEntity.StockName           = stock.Type;
            historyEntity.StockAmount         = args.StockAmount;
            historyEntity.TransactionQuantity = args.StockAmount * stock.Price;
            historyEntity.TimeOfTransaction   = args.dateTime;
            transactionID = historyTableRepository.Add(historyEntity);
            historyTableRepository.SaveChanges();
            return(transactionID);
        }
Пример #15
0
        public void Run()
        {
            Console.WriteLine("#################################");
            Console.WriteLine("Welcome to the: Trading Simulator");
            Console.WriteLine("#################################");
            Console.WriteLine(@"The database already contains some values necessary to run the application!");
            Console.WriteLine("-----------------------------------------------------------------------------");
            Console.WriteLine("press '1' to start bidding!");
            int userSelectedNumber = int.Parse(Console.ReadLine());

            Console.Clear();
            Console.WriteLine("Bidding start:");
            while (true)
            {
                if (userSelectedNumber == 1)
                {
                    Thread.Sleep(5000);
                    UserEntity seller   = tradingSimulation.ChooseARandomUser();
                    UserEntity customer = tradingSimulation.ChooseARandomUser();
                    while (seller.Equals(customer))
                    {
                        customer = tradingSimulation.ChooseARandomUser();
                    }

                    AddingSharesToThUserEntity sellerSharesToThUserEntity = tradingSimulation.SelectSharesAndUser(seller);

                    SharesEntity sellerShares = tradingSimulation.ChooseShareskValue(sellerSharesToThUserEntity);

                    AddingSharesToThUserEntity customerSharesToThUserEntity = tradingSimulation.SelectStocksForUserObjectParameters(customer, sellerShares);

                    int Price = tradingSimulation.RandomNumberGenerator((int)sellerShares.Price);

                    int NumberOfShares = tradingSimulation.RandomNumberGenerator(sellerSharesToThUserEntity.AmountStocks);

                    tradingSimulation.StockPurchaseTransaction(seller, customer, Price, NumberOfShares, sellerSharesToThUserEntity, customerSharesToThUserEntity);

                    TransactionHistoryEntity transactionHistoryEntity = new TransactionHistoryEntity()
                    {
                        DateTimeBay = DateTime.Now,
                        SellerId    = seller.Id,
                        CustomerId  = customer.Id,
                        AmountShare = NumberOfShares,
                        Cost        = Price
                    };
                    transactionService.RegisterNewTransactionHistory(transactionHistoryEntity);
                }
            }
        }
Пример #16
0
        public void RegisterNewTransactionHistory(TransactionHistoryEntity transactionHistoryEntity)
        {
            var entityToAdd = new TransactionHistoryEntity()
            {
                DateTimeBay = transactionHistoryEntity.DateTimeBay,
                SellerId    = transactionHistoryEntity.SellerId,
                CustomerId  = transactionHistoryEntity.CustomerId,
                AmountShare = transactionHistoryEntity.AmountShare,
                Cost        = transactionHistoryEntity.Cost
            };

            this.transactionRepositories.Add(entityToAdd);

            this.transactionRepositories.SaveChanges();
            Console.WriteLine("The transaction was successful and added to the database.");
        }
Пример #17
0
        public void RegisterNewTransactionHistory(TransactionHistoryEntity transactionHistoryEntity)
        {
            var entityToAdd = new TransactionHistoryEntity()
            {
                DateTimeBay = transactionHistoryEntity.DateTimeBay,
                SellerId    = transactionHistoryEntity.SellerId,
                CustomerId  = transactionHistoryEntity.CustomerId,
                AmountShare = transactionHistoryEntity.AmountShare,
                Cost        = transactionHistoryEntity.Cost
            };
            TransactionRepositories transactionRepositories = new TransactionRepositories(dbContext);

            transactionRepositories.Add(entityToAdd);

            transactionRepositories.SaveChanges();
        }
Пример #18
0
        public int Add(TransactionHistoryInfo operationHistoryInfo)
        {
            var operationHistory = new TransactionHistoryEntity()
            {
                BuyerClientID  = operationHistoryInfo.BuyerClientID,
                SellerClientID = operationHistoryInfo.SellerClientID,
                Amount         = operationHistoryInfo.Amount,
                ShareID        = operationHistoryInfo.ShareID,
                SumOfOperation = operationHistoryInfo.SumOfOperation,
                DateTime       = operationHistoryInfo.DateTime
            };

            operationHistoryRepository.Add(operationHistory);
            operationHistoryRepository.SaveChanges();
            return(operationHistory.TransactionID);
        }
        public async Task AddTransferAsync(SmartVoucherTransferDto transfer)
        {
            using (var context = _contextFactory.CreateDataContext())
            {
                var entity = SmartVoucherTransferEntity.Create(transfer);
                var historyEntityForSender   = TransactionHistoryEntity.CreateForSmartVoucherTransferSender(transfer);
                var historyEntityForReceiver = TransactionHistoryEntity.CreateForSmartVoucherTransferReceiver(transfer);

                entity.Campaign = await GetAndUpdateCampaign(context, transfer.CampaignId, transfer.CampaignName);

                context.SmartVoucherTransfers.Add(entity);
                context.TransactionHistories.Add(historyEntityForSender);
                context.TransactionHistories.Add(historyEntityForReceiver);

                await context.SaveChangesAsync();
            }
        }
Пример #20
0
        public string Post([FromBody] TransactionInfo value)
        {
            string  StockName             = stockService.Get(value.StockID).Type;
            decimal transactionQuantity   = stockService.Get(value.StockID).Price *value.StockAmount;
            TransactionHistoryEntity deal = new TransactionHistoryEntity()
            {
                BuyerBalanceID      = value.BuyerBalanceID,
                SellerBalanceID     = value.SellerBalanceID,
                StockAmount         = value.StockAmount,
                StockName           = StockName,
                TimeOfTransaction   = DateTime.Now,
                TransactionQuantity = transactionQuantity
            };

            transactionsService.Add(deal);
            transactionsService.SaveChanges();
            int id = transactionsService.GetId(value);

            return(Newtonsoft.Json.JsonConvert.SerializeObject(transactionsService.Get(id)));
        }
Пример #21
0
        public void ShouldAddANewTransactionToTheHistory()
        {
            var transactionRepositories = Substitute.For <ITransactionRepositories>();
            TransactionService       transactionService       = new TransactionService(transactionRepositories);
            TransactionHistoryEntity transactionHistoryEntity = new TransactionHistoryEntity()
            {
                DateTimeBay = DateTime.Now,
                SellerId    = 1,
                CustomerId  = 2,
                AmountShare = 100,
                Cost        = 10
            };

            transactionService.RegisterNewTransactionHistory(transactionHistoryEntity);

            transactionRepositories.Received(1).Add(Arg.Is <TransactionHistoryEntity>(w =>
                                                                                      w.SellerId == transactionHistoryEntity.SellerId &&
                                                                                      w.CustomerId == transactionHistoryEntity.CustomerId &&
                                                                                      w.AmountShare == transactionHistoryEntity.AmountShare &&
                                                                                      w.Cost == transactionHistoryEntity.Cost
                                                                                      ));
            transactionRepositories.Received(1).SaveChanges();
        }
 public void Add(TransactionHistoryEntity transaction)
 {
     this.dbContext.TransactionHistories.Add(transaction);
 }
Пример #23
0
 public void Add(TransactionHistoryEntity operation)
 {
     dbContext.Transactions.Add(operation);
 }
Пример #24
0
 public int Add(TransactionHistoryEntity entity)
 {
     this.dbContext.Transactions.Add(entity);
     return(entity.TransactionID);
 }