예제 #1
0
 public ActionResult <string> Post([FromBody] TransactionsMakeData transaction)
 {
     if (this.transactionManager.Make(transaction))
     {
         return(Ok("Transaction completed"));
     }
     return(BadRequest("Transactions failed"));
 }
예제 #2
0
        public bool Make(TransactionsMakeData transactionsMakeData)
        {
            var transaction = new Transaction
            {
                dateTime = DateTime.Now,
                SellerID = transactionsMakeData.sellerID,
                BuyerID  = transactionsMakeData.buyerID,
                ShareID  = transactionsMakeData.shareID,
                Amount   = transactionsMakeData.shareAmount
            };

            if (this.Validate(transaction))
            {
                this.TransactionAgent(transaction);
                this.AddTransaction(transaction);
                return(true);
            }

            return(false);
        }
예제 #3
0
        public void Execute()
        {
            string url = "http://localhost/deal/make";

            this.outputDevice.Clear();
            this.commandParser.Parse(Command.clients.ToString());
            this.outputDevice.WriteLine("Select seller ID:");
            int sellerID = 0;

            while (true)
            {
                if (int.TryParse(this.inputDevice.ReadLine(), out sellerID))
                {
                    break;
                }
                else
                {
                    this.outputDevice.WriteLine("Please enter valid seller ID");
                }
            }

            this.outputDevice.Clear();
            this.commandParser.Parse(Command.clients.ToString());
            this.outputDevice.WriteLine("Select buyer ID:");
            int buyerID = 0;

            while (true)
            {
                if (int.TryParse(this.inputDevice.ReadLine(), out buyerID))
                {
                    break;
                }
                else
                {
                    this.outputDevice.WriteLine("Please enter valid buyer ID");
                }
            }

            this.outputDevice.Clear();
            this.commandParser.Parse(Command.shares.ToString());
            this.outputDevice.WriteLine("Select share ID:");
            int shareID = 0;

            while (true)
            {
                if (int.TryParse(this.inputDevice.ReadLine(), out shareID))
                {
                    break;
                }
                else
                {
                    this.outputDevice.WriteLine("Please enter valid share ID");
                }
            }

            this.outputDevice.WriteLine("Write share amount:");
            int stockAmount = 0;

            while (true)
            {
                if (int.TryParse(this.inputDevice.ReadLine(), out stockAmount))
                {
                    break;
                }
                else
                {
                    this.outputDevice.WriteLine("Please enter valid balance");
                }
            }

            TransactionsMakeData transactionToMake = new TransactionsMakeData {
                sellerID = sellerID, buyerID = buyerID, shareID = shareID, shareAmount = stockAmount
            };

            HttpContent contentString = new StringContent(JsonConvert.SerializeObject(transactionToMake), Encoding.UTF8, "application/json");
            var         result        = this.httpRequestManager.PostAsync(url, contentString);

            this.outputDevice.WriteLine(result.ToString());
        }