public async Task <IActionResult> CheckOutAsync(int userID) { var baseUri = new Uri(urlString); var serverClient = new ServerClient(urlString); double totalCost = 0.0; //To check balance foreach (CartInfo ci in cartlist) { totalCost += ci.price * ci.itemInCartAmount; } if (totalCost > login_user.balance) { ViewBag.User = login_user; ViewBag.Message = "Sorry, please add some balance first!"; Log log_checkout = new Log(login_user.userID, "Check out failed. No enough balance."); await serverClient.RecordLog(log_checkout); return(View("Cart", cartlist)); } else { double balance = await serverClient.CheckOutAsync(userID); List <Item> list = await serverClient.GetItemsAsync(); login_user.balance = balance; ViewBag.User = login_user; Log log_checkout = new Log(login_user.userID, "Check out succeeded."); await serverClient.RecordLog(log_checkout); ViewBag.Message = "Congratulations, your order has been placed!"; return(View("Homepage", list)); } }