public ActionResult PlaceOrder(string id) { var userName = User.Identity.GetUserName(); /* Find the details of the customer placing the order*/ var customer = db.Customers.Where(x => x.Email == userName).FirstOrDefault(); /* Place the order */ order_Service.AddOrder(customer); /* Get the last placed order by the cus.tomer */ var order = order_Service.GetOrders() .FindAll(x => x.Email == customer.Email) .OrderByDescending(x => x.date_created) .FirstOrDefault(); /* If the customer requests delivery, save order address */ if (id == "deliver") { address_Service.AddShippingAddress(new Shipping_Address() { Order_ID = order.Order_ID, street_number = Convert.ToInt16(Session["street_number"].ToString()), street_name = Session["street_name"].ToString(), City = Session["City"].ToString(), State = Session["State"].ToString(), ZipCode = Session["ZipCode"].ToString(), Country = Session["Country"].ToString(), Building_Name = "", Floor = "", Contact_Number = "", Comments = "", Address_Type = "" }); } /* Migrate cart items to map as order items */ order_Service.AddOrderItems(order, cart_Service.GetCartItems()); /* Empty the cart items */ cart_Service.EmptyCart(); /* Update Order Tracking Report */ order_Service.AddOrderTrackingReport(new Order_Tracking() { order_ID = order.Order_ID, date = DateTime.Now, status = "Awaiting Payment", Recipient = "" }); //Redirect to payment return(RedirectToAction("Payment", new { id = order.Order_ID })); }
public ActionResult COnfirmOrder() { var UserName = User.Identity.GetUserName(); ViewBag.Total = cart_Service.GetCartTotal(cart_Service.GetCartID()); ViewBag.TotalQTY = cart_Service.GetCartItems().FindAll(x => x.cart_id == cart_Service.GetCartID()).Sum(q => q.quantity); var confirm = db.FoodOrders.ToList(); var cart = db.Cart_Items.ToList(); MealOrder mealOrder = new MealOrder(); mealOrder.OrderNumber = mealOrder.GenVoucher(); mealOrder.Total = ViewBag.Total; mealOrder.UserOrder = UserName; mealOrder.Status = "Paid"; mealOrder.OrderDate = DateTime.Now.Date.ToLongDateString(); db.MealOrders.Add(mealOrder); db.SaveChanges(); FoodOrder foodOrder = new FoodOrder(); foreach (var item in confirm) { foreach (var i in cart) { if (UserName == item.UserEmail && item.cart_id == i.cart_id) { var statusUpdate = db.FoodOrders.Find(item.cart_item_id); statusUpdate.OrderStatus = "Checked Out"; statusUpdate.OrderId = mealOrder.OrderId; db.Entry(statusUpdate).State = EntityState.Modified; db.SaveChanges(); cart_Service.EmptyCart(); } } } return(RedirectToAction("OnceOff", new { tot = mealOrder.Total })); }