protected DataSet GetData() { List <TransactionHeader> headers = TransactionHeaderRepository.GetAllTransactions(); DataSet ds = new DataSet(); var ds_header = ds.TransactionHeader; var ds_detail = ds.TransactionDetail; foreach (var header in headers) { var newRow = ds_header.NewRow(); newRow["Id"] = header.Id; newRow["UserId"] = header.UserId; newRow["Date"] = header.TransactionDate; ds_header.Rows.Add(newRow); List <TransactionDetail> details = TransactionDetailRepository.GetTransactionDetails(header.Id); foreach (var detail in details) { var newRowDetail = ds_detail.NewRow(); newRowDetail["TransactionId"] = detail.TransactionId; newRowDetail["ProductId"] = detail.ProductId; newRowDetail["ProductName"] = ProductRepository.GetProductById(detail.ProductId).Name; newRowDetail["Price"] = ProductRepository.GetProductById(detail.ProductId).Price; newRowDetail["Quantity"] = ProductRepository.GetProductById(detail.ProductId).Quantity; ds_detail.Rows.Add(newRowDetail); } } return(ds); }
public static bool Checkout(int userId) { List <Cart> carts = GetThisUserCart(userId); if (carts.Count == 0) { return(false); } else { TransactionHeader transactionHeader = TransactionHeaderFactory.Create(userId); if (TransactionHeaderRepository.InsertTransactionHeader(transactionHeader)) { int headerId = transactionHeader.Id; for (int i = 0; i < carts.Count(); i++) { TransactionDetail transactionDetail = TransactionDetailFactory.Create(headerId, carts[i].ProductId, carts[i].Quantity); TransactionDetailRepository.InsertTransactionDetail(transactionDetail); } for (int i = 0; i < carts.Count(); i++) { CartRepository.RemoveCart(carts[i]); } return(true); } return(false); } }