Ejemplo n.º 1
0
        public IActionResult CalcTotal([FromBody] TotalRequest request)
        {
            (var subtotal, var total) = Calculate(request);

            return(Json(new {
                subtotal,
                total
            }));
        }
Ejemplo n.º 2
0
        private (decimal subtotal, decimal total) Calculate(TotalRequest request)
        {
            var subtotal = 0.0m;

            if (!string.IsNullOrEmpty(request.camps))
            {
                subtotal += request.member ? 75 : 100;
            }

            var total = subtotal;

            if (request.coupon.Trim().ToLower() == "price is mia")
            {
                total = 0;
            }

            if (request.coupon.Trim().ToLower() == "drop and give me 50")
            {
                total = subtotal / 2;
            }

            return(subtotal, total);
        }
Ejemplo n.º 3
0
        public async Task AddRequestToMainServer()
        {
            Console.WriteLine("ADDTOMAINSERVER");
            int req = 0;

            TotalRequest = 0;
            Random  randomNumber = new Random();
            decimal percentageMain;
            Task    addRequest = Task.Factory.StartNew(async() =>
            {
                while (true)
                {
                    if (MainServer.RequestCount >= 9900)
                    {
                        continue;
                    }
                    req = randomNumber.Next(1, 100);
                    MainServer.CancellationToken.Token.ThrowIfCancellationRequested();
                    MainServer.RequestCount += req;
                    TotalRequest            += req;
                    percentageMain           = ((Convert.ToDecimal(MainServer.RequestCount) / MainServer.Capacity) * 100);
                    MainServer.ServerProgressBar.ChangeValues(MainServer.RequestCount, percentageMain);
                    lblTotalRequest.Invoke(new Action(() => lblTotalRequest.Text = "Total Request: " + TotalRequest.ToString()));
                    myConsole.Invoke(new Action(() => myConsole.AppendText("Main Server Request: " + req.ToString() + "\n")));
                    await Task.Delay(100);
                }
            }
                                                       , MainServer.CancellationToken.Token);

            Task responseRequest = Task.Factory.StartNew(async() =>
            {
                while (true)
                {
                    await Task.Delay(500);
                    if (MainServer.RequestCount <= 0)
                    {
                        MainServer.RequestCount = 0;
                        MainServer.ServerProgressBar.ChangeValues(0, 0);
                        myConsole.Invoke(new Action(() => myConsole.AppendText("Main Server Request: " + MainServer.RequestCount.ToString() + "\n")));
                        MainServer.CancellationToken.Cancel();
                    }
                    req = randomNumber.Next(1, 50);
                    MainServer.CancellationToken.Token.ThrowIfCancellationRequested();
                    MainServer.RequestCount -= req;
                    TotalRequest            -= req;
                    myConsole.Invoke(new Action(() => myConsole.AppendText("Main Server Response: " + req.ToString() + "\n")));
                }
            }
                                                         , MainServer.CancellationToken.Token);

            MainServer.CancellationToken.Token.Register(() =>
            {
                Console.WriteLine("Requests Stoped");
            });
        }