public static Detail_Transaction InsertDetailTransaction(Detail_Transaction DetailTrans) { db.Detail_Transactions.Add(DetailTrans); db.SaveChanges(); return(DetailTrans); }
public static Detail_Transaction InsertDetailTransaction(int TransactionID, int ProductID, int Quantity) { Detail_Transaction DetailTrans = new Detail_Transaction() { TransactionID = TransactionID, ProductID = ProductID, Quantity = Quantity }; return(DetailTrans); }
public static Response doCheckout(List <Cart> carts, int UserID, int PaymentTypeID, DateTime date) { Header_Transaction headerTran = TransactionsFactories.InsertHeaderTransaction(UserID, PaymentTypeID, date); TransactionRepositories.InsertHeaderTransaction(headerTran); Detail_Transaction detailTran = new Detail_Transaction(); for (int i = 0; i < carts.Count; i++) { detailTran = TransactionsFactories.InsertDetailTransaction(headerTran.ID, carts[i].ProductID, carts[i].Quantity); TransactionRepositories.InsertDetailTransaction(detailTran); CartRepositories.DeleteCart(carts[i].ProductID, UserID); } return(new Response(true)); }
public static Response DeleteProduct(int ProductID) { Cart cart = CartRepositories.GetCartByProduct(ProductID); Detail_Transaction detailTran = TransactionRepositories.GetDetailTransactionByProductID(ProductID); if (cart != null || detailTran != null) { return(new Response(false, "Cant delete this product because its referenced in another table in database")); } Product pro = ProductRepositories.GetProduct(ProductID); if (pro != null) { ProductRepositories.DeleteProduct(ProductID); return(new Response(true)); } return(new Response(false, "cant find the product")); }