public bool Insert(OderDetail detail) { using (ThucLop db = new ThucLop()) { db.OderDetails.Add(detail); db.SaveChanges(); return true; } }
public ActionResult Payment(string shipName, string Address, string Phone, string email) { var order = new Order(); order.CreatedDate = DateTime.Now; order.ShipName = shipName; order.ShipAddress = Address; order.ShipMobile = Phone; order.ShipEmail = email; try { var id = new OrderDAO().Insert(order); var cart = (List<CartItem>)Session[CartSession]; var detailDao = new OrderDetailDAO(); foreach (var item in cart) { var orderDetail = new OderDetail(); orderDetail.ProductID = item.Product.ID; orderDetail.OrderID = id; orderDetail.Price = item.Product.Price; orderDetail.Quantity = item.Quantity; detailDao.Insert(orderDetail); } } catch (Exception ex) { throw ex; } return RedirectToAction("Finish"); }