Exemplo n.º 1
0
        public ActionResult TransactionComplete(int?id)
        {
            if (id != null)
            {
                var billingAccount = BalanceProvider.GetCurentUserBillingAccount();
                using (var dataBase = new ApplicationDbContext())
                {
                    var curentUserTransactions = dataBase.Transactions.Where(transaction => transaction.TransferFromId == billingAccount.Id).ToList();
                    var currentTransaction     = curentUserTransactions.SingleOrDefault(transaction => transaction.Id == id);
                    if (currentTransaction != null)
                    {
                        var item = new TransactionListItem
                        {
                            TransactionId     = currentTransaction.Id,
                            Date              = currentTransaction.Date,
                            TransactionAmount = currentTransaction.TransactionAmount.ToString()
                        };

                        var billingAccounts = dataBase.BillingAccounts.ToList();
                        var correspondent   = billingAccounts.SingleOrDefault(account => account.Id.Equals(currentTransaction.TransferToId));
                        if (correspondent != null)
                        {
                            item.CorrespondentName = correspondent.FullUserName;
                            return(View(item));
                        }
                    }
                }
            }
            return(RedirectToAction("Index", "Home"));
        }
Exemplo n.º 2
0
        public ActionResult List()
        {
            var currentUser = BalanceProvider.GetCurentUserBillingAccount();

            using (var dataBase = new ApplicationDbContext())
            {
                var currentUserTransactionsList = dataBase.Transactions.Where(transaction =>
                                                                              transaction.TransferFromId == currentUser.Id)
                                                  .OrderByDescending(transaction => transaction.Id)
                                                  .ToList();

                var billingAccounts = dataBase.BillingAccounts.ToList();

                var transactionListItems = currentUserTransactionsList.Select(transaction =>
                {
                    var item = new TransactionListItem
                    {
                        Date              = transaction.Date,
                        TransactionId     = transaction.Id,
                        TransactionAmount = transaction.TransactionAmount.ToString()
                    };
                    var recipientAccount   = billingAccounts.Single(account => account.Id == transaction.TransferToId);
                    item.CorrespondentName = recipientAccount.FullUserName;
                    return(item);
                });

                return(View(transactionListItems));
            }
        }
Exemplo n.º 3
0
        public ActionResult BillingInfo()
        {
            var billingAccount = BalanceProvider.GetCurentUserBillingAccount();

            return(View(billingAccount));

            /*
             * using (var dataBase = new ApplicationDbContext())
             * {
             *  var billingAccoun = dataBase.BillingAccounts.SingleOrDefault(account => account.Id == billingAccountId);
             *  if (billingAccoun != null)
             *  {
             *      return View();
             *  }
             * }
             * return View(new BillingAccount());
             */
            /*
             * using (var dataBase = new ApplicationDbContext())
             * {
             * dataBase.
             * var galleryItem = dataBase.Images.SingleOrDefault(item => item.Id == id);
             * var fileName = $"{Path.GetFileNameWithoutExtension(Path.GetRandomFileName())}.jpg";
             * return File(galleryItem.Image, "image/jpg", fileName);
             * }
             *
             * return View();
             */
        }
Exemplo n.º 4
0
        public BalanceExtendedResponse BalanceExtended(BalanceExtendedRequest balanceExtendedRequest)
        {
            Log(Logger.LogMessageType.Info, "->   -------------------- Comienza la ejecución del método Sales.BalanceExtended", Logger.LoggingLevelType.Medium);
            LoginRequestInternal loginRequest = new LoginRequestInternal()
            {
                DeviceType = balanceExtendedRequest.Request.DeviceType,
                Password   = balanceExtendedRequest.Request.Password,
                User       = balanceExtendedRequest.Request.Username
            };
            LoginResponseInternal loginResponse = AuthenticationProvider.LoginInternal(loginRequest);

            BalanceRequestInternal internalObject = new BalanceRequestInternal()
            {
                SessionID  = loginResponse.SessionID,
                DeviceType = balanceExtendedRequest.Request.DeviceType
            };
            BalanceResponseInternal     internalResponse = BalanceProvider.BalanceInternal(internalObject);
            BalanceExtendedResponse     response         = new BalanceExtendedResponse();
            BalanceExtendedResponseBody responseBody     = new BalanceExtendedResponseBody()
            {
                ResponseCode    = internalResponse.ResponseCode,
                ResponseMessage = internalResponse.ResponseMessage,
                TransactionID   = internalResponse.TransactionID,
                Balance         = internalResponse.StockBalance
            };

            response.Response = responseBody;
            Log(Logger.LogMessageType.Info, "->   -------------------- Termina la ejecución del método Sales.BalanceExtended", Logger.LoggingLevelType.Medium);
            return(response);
        }
    public static BalanceProvider Instance()
    {
        if (instance == null)
        {
            instance = new BalanceProvider();
        }

        return instance;
    }
Exemplo n.º 6
0
 public ZCashService(IConfiguration config, WalletsRepository walletsRepository,
                     EventsRepository eventsRepository, TransactionsRepository transactionsRepository,
                     BalanceProvider balanceProvider, OutcomeTransactionRepository outcomeTransactionRepository)
 {
     _client                       = new(config);
     _walletsRepository            = walletsRepository;
     _eventsRepository             = eventsRepository;
     _transactionsRepository       = transactionsRepository;
     _balanceProvider              = balanceProvider;
     _outcomeTransactionRepository = outcomeTransactionRepository;
 }
Exemplo n.º 7
0
 public EtheriumService(WalletsRepository walletsRepository,
                        EventsRepository eventsRepository,
                        OutcomeTransactionRepository outcomeTransactionRepository,
                        ETHRequestClient ethRequestClient,
                        BalanceProvider balanceProvider)
 {
     _walletsRepository            = walletsRepository;
     _eventsRepository             = eventsRepository;
     _outcomeTransactionRepository = outcomeTransactionRepository;
     _ethRequestClient             = ethRequestClient;
     _balanceProvider = balanceProvider;
 }
Exemplo n.º 8
0
 public SendController(WalletsRepository walletsRepository,
                       ILitecoinService litecoinService,
                       EventsRepository eventsRepository,
                       UserManager <IdentityUser> userManager,
                       UserRepository userRepository,
                       WalletService walletService,
                       BalanceProvider balanceProvider)
 {
     _walletsRepository = walletsRepository;
     _litecoinService   = litecoinService;
     _eventsRepository  = eventsRepository;
     _userManager       = userManager;
     _userRepository    = userRepository;
     _walletService     = walletService;
     _balanceProvider   = balanceProvider;
 }
        private IEnumerable <TransactionHistoryItem> GetTransactionItems()
        {
            var currentUser = BalanceProvider.GetCurentUserBillingAccount();

            using (var dataBase = new ApplicationDbContext())
            {
                var currentUserTransactionsList = dataBase.Transactions.Where(transaction =>
                                                                              transaction.TransferFromId == currentUser.Id || transaction.TransferToId == currentUser.Id)
                                                  .OrderByDescending(transaction => transaction.Id)
                                                  .ToList();

                var billingAccounts    = dataBase.BillingAccounts.ToList();
                var operationBalance   = currentUser.Balance;
                var transactionHistory = currentUserTransactionsList.Select(transaction =>
                {
                    var historyItem = new TransactionHistoryItem();

                    historyItem.Date = transaction.Date;
                    if (transaction.TransferFromId == currentUser.Id)
                    {
                        var recipientAccount = billingAccounts.Single(account => account.Id == transaction.TransferToId);

                        historyItem.CorrespondentName = recipientAccount.FullUserName;
                        historyItem.Credit            = transaction.TransactionAmount;
                        historyItem.Debit             = new Money(0);
                        historyItem.Balance           = operationBalance;
                        operationBalance += transaction.TransactionAmount;
                    }
                    else if (transaction.TransferToId == currentUser.Id)
                    {
                        var debitorAccount = billingAccounts.Single(account => account.Id == transaction.TransferFromId);

                        historyItem.CorrespondentName = debitorAccount.FullUserName;
                        historyItem.Debit             = transaction.TransactionAmount;
                        historyItem.Credit            = new Money(0);
                        historyItem.Balance           = operationBalance;
                        operationBalance -= transaction.TransactionAmount;
                    }
                    return(historyItem);
                }
                                                                            ).ToList();

                return(transactionHistory);
            }
        }
Exemplo n.º 10
0
        public ActionResult Create(int?id)
        {
            var billingAccount = BalanceProvider.GetCurentUserBillingAccount();

            using (var dataBase = new ApplicationDbContext())
            {
                var dbBillingAccounts   = dataBase.BillingAccounts.ToList();
                var billingAccountsList = dbBillingAccounts.OrderBy(account => account.FirstName)
                                          .Select(account => new BillingUser {
                    id = account.Id, name = account.FullUserName
                })
                                          .ToList();
                ViewBag.BillingAccountsList = billingAccountsList;
                decimal defaultValue = 0.01m;
                ViewBag.TransactionAmount = new Money(defaultValue).Amount;

                if (billingAccount.Balance <= new Money(0))
                {
                    return(RedirectToAction("NotEnoughFunds"));
                }

                ViewBag.MaxTransaction = billingAccount.Balance.Amount;

                if (id != null)
                {
                    var repeatTransaction = dataBase.Transactions.SingleOrDefault(transaction => transaction.Id == id);
                    if (repeatTransaction != null)
                    {
                        var selectAcountInList = billingAccountsList.SingleOrDefault(account => account.id == repeatTransaction.TransferToId);
                        ViewBag.SelectedRecipientId = selectAcountInList.id;
                        ViewBag.InitialRecipient    = selectAcountInList.name;
                        ViewBag.TransactionAmount   = (billingAccount.Balance < repeatTransaction.TransactionAmount) ? billingAccount.Balance.Amount : repeatTransaction.TransactionAmount.Amount;
                    }
                }
            }

            return(View());
        }
Exemplo n.º 11
0
        public BalanceResponse Balance(BalanceRequest externalRequest)
        {
            Log(Logger.LogMessageType.Info, "->   -------------------- Comienza la ejecución del método Sales.Balance", Logger.LoggingLevelType.Medium);
            BalanceRequestInternal internalRequest = new BalanceRequestInternal()

            {
                SessionID  = externalRequest.Request.SessionID,
                DeviceType = externalRequest.Request.DeviceType
            };
            BalanceResponseInternal internalResponse     = BalanceProvider.BalanceInternal(internalRequest);
            BalanceResponse         externalResponse     = new BalanceResponse();
            BalanceResponseBody     externalResponseBody = new BalanceResponseBody()
            {
                ResponseCode    = internalResponse.ResponseCode,
                ResponseMessage = internalResponse.ResponseMessage,
                TransactionID   = internalResponse.TransactionID,
                Balance         = internalResponse.StockBalance
            };

            externalResponse.Response = externalResponseBody;
            Log(Logger.LogMessageType.Info, "->   -------------------- Termina la ejecución del método Sales.Balance", Logger.LoggingLevelType.Medium);
            return(externalResponse);
        }
Exemplo n.º 12
0
        public JsonResult CommitTransaction(string amount, int selectedRecipient)
        {
            if (string.IsNullOrEmpty(amount))
            {
                return(Json(new
                {
                    success = false,
                    responseText = $"Not valid amount [{amount}]. Please check form fields."
                }, JsonRequestBehavior.AllowGet));
            }
            var transaction = new Transaction();

            amount = amount.Replace(',', '.');
            var amountValue = new Money(Decimal.Parse(amount, CultureInfo.InvariantCulture));

            using (var dataBase = new ApplicationDbContext())
            {
                var billingAccounts = dataBase.BillingAccounts.ToList();
                var sendToRecipient = billingAccounts.SingleOrDefault(account => account.Id.Equals(selectedRecipient));
                if (sendToRecipient != null)
                {
                    var billingAccount = BalanceProvider.GetCurentUserBillingAccount();
                    if (billingAccount.Balance < amountValue)
                    {
                        return(Json(new
                        {
                            success = false,
                            responseText = $"Not valid amount: [{amountValue}]. Balance is: [{billingAccount.Balance}]. Please check form fields."
                        }));
                    }

                    var id = BalanceProvider.GetCurentUserBillingAccount().Id;
                    if (id == selectedRecipient)
                    {
                        return(Json(new
                        {
                            success = false,
                            responseText = $"You can not transfer money to yourself!. Please check form fields."
                        }));
                    }

                    var currntAccount    = dataBase.BillingAccounts.Single(account => account.Id == id);
                    var recipientAccount = dataBase.BillingAccounts.Single(account => account.Id == sendToRecipient.Id);

                    transaction.TransferFromId    = currntAccount.Id;
                    transaction.TransferFrom      = currntAccount;
                    transaction.TransferToId      = sendToRecipient.Id;
                    transaction.TransferTo        = sendToRecipient;
                    transaction.TransactionAmount = amountValue;
                    transaction.Date = DateTime.Now;
                    dataBase.Transactions.Add(transaction);

                    currntAccount.Balance    -= amountValue;
                    recipientAccount.Balance += amountValue;
                    dataBase.SaveChanges();


                    return(Json(new { success = true, responseText = transaction.Id }));
                }
                else
                {
                    return(Json(new
                    {
                        success = false,
                        responseText = "Can't find user. Please check form fields."
                    }));
                }
            }
        }