public async Task <ActionResult> Order() { var account = (Account)Session[Constant.UserCustomerSession]; var productOrders = await cardDAO.GetAllProductOrder(account.Id); if (productOrders == null) { return(Json(0)); } long totalPrice = productOrders.Sum(x => x.Price * x.QuantityPurchased); var bill = new Bill { Address = account.User.Address, CreationTime = DateTime.Now, BillStatus = BillStatus.AwaitingApproval, TotalPrice = totalPrice, VAT = (long)(totalPrice * 0.1), AccountId = account.Id }; bill.Id = await billDAO.CreateBill(bill); var billInfos = productOrders.Select(x => new BillInfo { BillId = bill.Id, Price = x.Price, ProductId = x.ProductId, QuantityPurchased = x.QuantityPurchased }).ToList(); int res = await billDAO.CreateBillInfo(billInfos); if (res > 0) { TempData["Order"] = "Đơn hàng đã được thành công!"; } return(Json(res)); }