예제 #1
0
        public IActionResult Index()
        {
            string url;

            url = cfg.GetValue <string>("Hosts:ProductsAPI") + "/Home/getProducts";
            Result result = new Result();

            result               = dataFetcher.GetData(httpClient, url, result);
            products             = JsonConvert.DeserializeObject <List <Product> >(result.Value.ToString());
            ViewData["products"] = products;
            return(View());
        }
예제 #2
0
        public IActionResult Index() //this renders the entire cart view
        {
            //retrieve all product from productAPI
            string productAPIurl = cfg.GetValue <string>("Hosts:ProductsAPI") + "/Home/getProducts";
            Result p_result      = new Result();

            p_result = dataFetcher.GetData(httpClient, productAPIurl, p_result);
            products = JsonConvert.DeserializeObject <List <Product> >(p_result.Value.ToString());

            //retrieve productId from cookie
            List <string>  currentcartid = JsonConvert.DeserializeObject <List <string> >(Request.Cookies["CartState"]);
            List <Product> currentcart   = new List <Product>();

            foreach (string ItemId in currentcartid)
            {
                foreach (Product product in products)
                {
                    if (ItemId == product.Id)
                    {
                        currentcart.Add(product);
                    }
                }
            }

            ViewData["totalprice"] = currentcart.Sum(item => item.unitPrice).ToString("c");
            ViewData["CartView"]   = currentcart;
            return(View());
        }
예제 #3
0
        public string Example([FromBody] Operand operand)
        {
            string url;

            url     = cfg.GetValue <string>("Hosts:TokenAPI") + "/Home/Example";
            operand = dataFetcher.GetData(httpClient, url, operand);
            return(JsonSerializer.Serialize(operand));
        }
예제 #4
0
        public string Compute([FromBody] Operand operand)
        {
            string url;

            url     = cfg.GetValue <string>("Hosts:TokenAPI") + "/Home/Tokenize";
            operand = dataFetcher.GetData(httpClient, url, operand);

            url     = cfg.GetValue <string>("Hosts:TransformAPI") + "/Home/InfixToPostfix";
            operand = dataFetcher.GetData(httpClient, url, operand);

            url     = cfg.GetValue <string>("Hosts:ReducerAPI") + "/Home/ReducePostfix";
            operand = dataFetcher.GetData(httpClient, url, operand);

            return(JsonSerializer.Serialize(new
            {
                result = operand.Value
            }));
        }
예제 #5
0
        public IActionResult SuccessPayment(Result result)
        {
            string userid = JsonConvert.DeserializeObject <string>(Request.Cookies["UserId"]);
            //retrieve all product from productAPI
            string productAPIurl = cfg.GetValue <string>("Hosts:ProductsAPI") + "/Home/getProducts";
            Result p_result      = new Result();

            p_result = dataFetcher.GetData(httpClient, productAPIurl, p_result);
            products = JsonConvert.DeserializeObject <List <Product> >(p_result.Value.ToString());

            //retrieve productId from CartState in cookie
            List <string> checkoutcart    = JsonConvert.DeserializeObject <List <string> >(Request.Cookies["CartState"]);
            Product       temp            = new Product();
            List <Orders> finalorderskept = new List <Orders>();
            DateTime      x = DateTime.UtcNow;

            foreach (string ItemId in checkoutcart)
            {
                foreach (Product product in products)
                {
                    if (ItemId == product.Id)
                    {
                        temp = product;
                        break;
                    }
                }
                Orders finalorder = new Orders();
                finalorder.imageURL  = temp.imageURL;
                finalorder.productId = temp.Id;
                finalorder.unitPrice = temp.unitPrice;
                finalorder.userId    = userid;
                finalorder.timestamp = x;
                finalorderskept.Add(finalorder);
            }

            result.Value = JsonConvert.SerializeObject(finalorderskept);
            string url = cfg.GetValue <string>("Hosts:OrdersAPI") + "/Home/receiveorders";

            result = dataFetcher.GetData(httpClient, url, result);


            Response.Cookies.Delete("CartState");
            return(RedirectToAction("Index", "Product")); //Change if we want to show a different checkout page
        }
        public IActionResult Index()
        {
            string url;

            url = cfg.GetValue <string>("Hosts:AccountAPI") + "/Home/getAccounts";
            Result result = new Result();

            result   = dataFetcher.GetData(httpClient, url, result);
            accounts = JsonConvert.DeserializeObject <List <Account> >(result.Value.ToString());

            if (Request.Cookies["UserId"] != null) //this block of code pull unpaid cart item back to cookies
            {
                //pull all unpaid ItemId from CartAPI based on UserId
                Result result2 = new Result();
                result.Value = Request.Cookies["UserId"];
                string url2 = cfg.GetValue <string>("Hosts:CartAPI") + "/Home/getProducts";
                result2 = dataFetcher.GetData(httpClient, url2, result);
                List <Cart> carthistory = new List <Cart>();
                carthistory = JsonConvert.DeserializeObject <List <Cart> >(result2.Value.ToString());
                List <string> cartid = new List <string>();
                foreach (Cart x in carthistory)
                {
                    cartid.Add(x.productId);
                }
                if (Request.Cookies["CartState"] == null)
                {
                    Response.Cookies.Append("CartState", JsonConvert.SerializeObject(cartid));
                }
                else
                {
                    List <string> currentcart = JsonConvert.DeserializeObject <List <string> >(Request.Cookies["CartState"]);
                    currentcart.AddRange(cartid);
                    Response.Cookies.Append("CartState", JsonConvert.SerializeObject(currentcart));
                }
            }
            ViewData["accounts"] = accounts;
            return(View());
        }