//public String CheckOut(IEnumerable<ShoppingCartProduct> Model) //{ // CustomerRepository customerRepo = new CustomerRepository(ConstantUtil.MyConnectionString); // Customer customer = customerRepo.GetById(1); // CustomerOrder co = new CustomerOrder(1, 25); // CustomerOrderRepository cor = new CustomerOrderRepository(ConstantUtil.MyConnectionString); // int orderId = cor.Insert(co); // List<CustomerOrderProduct> cops = new List<CustomerOrderProduct>(); // foreach (int scp in myModel.products) // { // CustomerOrderProduct temp = new CustomerOrderProduct(orderId, scp); // ProductRepository pr = new ProductRepository(ConstantUtil.MyConnectionString); // Product prod = pr.GetById(scp); // temp.Quantity = 100; // temp.UnitOfMeasure = prod.UnitOfMeasure; // temp.UnitPrice = prod.UnitPrice; // temp.CreatedBy = prod.CreatedBy; // temp.CreatedDate = prod.CreatedDate; // temp.LastModifiedBy = prod.LastModifiedBy; // temp.LastModifiedDate = prod.LastModifiedDate; // temp.Subtotal = 0; // cops.Add(temp); // } // return "Successfully"; //} public String CheckOut() { CustomerRepository customerRepo = new CustomerRepository(ConstantUtil.MyConnectionString); Customer customer = customerRepo.GetById(1); CustomerOrder co = new CustomerOrder(1, 25); CustomerOrderRepository cor = new CustomerOrderRepository(ConstantUtil.MyConnectionString); int orderId = cor.Insert(co); List <CustomerOrderProduct> cops = new List <CustomerOrderProduct>(); ShoppingCartProductRepository scpr = new ShoppingCartProductRepository(ConstantUtil.MyConnectionString); IEnumerable <ShoppingCartProduct> myModel = scpr.GetAll(); foreach (ShoppingCartProduct scp in myModel) { CustomerOrderProduct temp = new CustomerOrderProduct(orderId, scp.ProductId); //ProductRepository pr = new ProductRepository(ConstantUtil.MyConnectionString); //Product prod = pr.GetById(scp); temp.Quantity = scp.Quantity; temp.UnitOfMeasure = scp.UnitOfMeasure; temp.UnitPrice = scp.UnitPrice; temp.CreatedBy = scp.CreatedBy; temp.CreatedDate = scp.CreatedDate; temp.LastModifiedBy = scp.LastModifiedBy; temp.LastModifiedDate = scp.LastModifiedDate; temp.Subtotal = scp.SubTotal; //cops.Add(temp); CustomerOrderProductRepository copr = new CustomerOrderProductRepository(ConstantUtil.MyConnectionString); copr.Insert(temp); } return("Successfully"); }
public ActionResult COnfirmOrder() { var UserName = User.Identity.GetUserName(); ViewBag.Total = cart_Service.GetCartTotal(cart_Service.GetCartID()); ViewBag.TotalQTY = cart_Service.GetCartItems().FindAll(x => x.cartId == cart_Service.GetCartID()).Sum(q => q.quantity); var confirm = _productOrdersRepository.GetAll(); //db.productrders.ToList(); var cart = _productOrdersRepository.GetAll(); //db.Cart_Items.ToList(); CustomerOrder mealOrder = new CustomerOrder(); mealOrder.OrderNumber = mealOrder.GenVoucher(); mealOrder.Total = ViewBag.Total; mealOrder.UserOrder = UserName; mealOrder.Status = "Paid"; mealOrder.OrderDate = DateTime.Now.Date.ToLongDateString(); _CustomerOrderRepository.Insert(mealOrder); //db.MealOrders.Add(mealOrder); //db.SaveChanges(); ProductOrder foodOrder = new ProductOrder(); foreach (var item in confirm) { foreach (var i in cart) { if (UserName == item.UserEmail && item.cart_id == i.cart_id) { var statusUpdate = _productOrdersRepository.GetById(item.cart_item_id); //db.productrders.Find(item.cart_item_id); statusUpdate.OrderStatus = "Checked Out"; statusUpdate.OrderId = mealOrder.OrderId; _productOrdersRepository.Update(statusUpdate); //db.Entry(statusUpdate).State = EntityState.Modified; //db.SaveChanges(); cart_Service.EmptyCart(); } } } return(RedirectToAction("OnceOff", new { tot = mealOrder.Total })); }