Beispiel #1
0
        public override async Task OnConnectedAsync()
        {
            var lastOrder = repo.GetAllOrders().OrderByDescending(o => o.OrderNumber).First();
            var userName  = lastOrder.User.UserName;

            await Groups.AddToGroupAsync(Context.ConnectionId, userName);

            await base.OnConnectedAsync();
        }
        public async Task GetAsync(string id) //id is blockId
        {
            logger.LogInformation("New block has been mined");

            RPCCredentialString cred = new RPCCredentialString();

            cred.UserPassword = new NetworkCredential(config["NodeCredentials:RPCUser"], config["NodeCredentials:RPCPassword"]);
            RPCClient client = new RPCClient(cred, Network.TestNet);


            var unspent = client.ListUnspent();

            foreach (var order in repo.GetAllOrders())
            {
                if (order.DisregardOrder || order.OrderTransactionsConfirmed)
                {
                    continue;
                }

                if (order.OrderDate.AddMinutes(15) < DateTime.Now && order.ReceivedValue < order.OrderTotalInBitcoin) //15 minutes or more has passed since order has been placed and payment did not met the requirements
                {
                    order.DisregardOrder = true;
                }


                if (!order.OrderTransactionsConfirmed && order.ReceivedValue > 0) // if there are unconfirmed txes
                {
                    bool confirmed = true;

                    foreach (var unspentOutput in unspent.Where(tx => tx.Address.ToString() == order.BitcoinAddress))
                    {
                        if (unspentOutput.Confirmations < 6) // one of transactions of order has less than 6 confirmations
                        {
                            confirmed = false;               //  transactions for this order have not been confirmed
                            break;
                        }
                    }

                    if (confirmed == true) // all transactions are confirmed and there has been at least some payment
                    {
                        order.OrderTransactionsConfirmed = true;
                        await mailService.SendEmailAsync(
                            order.User.Email,
                            "Your Transactions have been confirmed!",
                            $"Accordion Fair is pleased to inform you that your transactions for order {order.OrderNumber} have been confirmed."
                            );

                        repo.SaveAll();
                    }
                }
            }
        }
Beispiel #3
0
        public IActionResult Get()
        {
            try
            {
                var results = repo.GetAllOrders();

                return(Ok(results));
            }
            catch (Exception ex)
            {
                logger.LogError($"Failed to get orders: {ex}");
                return(BadRequest("Failed to get orders"));
            }
        }
        public async Task <IActionResult> Get()
        {
            var user = await userManager.FindByNameAsync(User.Identity.Name);

            var roles = await userManager.GetRolesAsync(user);

            if (roles.Contains("Admin")) // if user is admin, return all orders
            {
                var orders = repo.GetAllOrders();

                if (orders.Any())
                {
                    logger.LogInformation("Returned all orders for admin account");
                    return(Ok(orders));
                }
                else
                {
                    logger.LogError("All orders could not be retrieved");
                    return(BadRequest());
                }
            }
            else  // if user is not admin, return specific orders
            {
                var orders = repo.GetAllOrdersByUser(username: user.UserName, includeItems: true);

                if (orders.Any())
                {
                    logger.LogInformation($"Returned all orders for {user.UserName} user");
                    return(Ok(orders));
                }
                else
                {
                    logger.LogError($"Orders for {user.UserName} could not be retrieved");
                    return(BadRequest());
                }
            }
        }