public ActionResult AddressAndPayment() { ProductOrder objprdorder = new ProductOrder(); if (Request.IsAuthenticated) { var query = from c in storeDB.User_Info where c.E_mail_id == User.Identity.Name select c; foreach (var d in query) { objprdorder.Customer_name = d.First_name + d.Last_name; objprdorder.mobileNo = d.Mobile_number; objprdorder.Emailid = d.E_mail_id; objprdorder.Customer_Address = d.Address_Communication; } } else { TempData["PrevURL"] = "/Checkout/AddressAndPayment"; return RedirectToAction("UserLogin", "UserInfo"); } return View(objprdorder); }
public ActionResult AddressAndPayment(FormCollection values) { var order = new ProductOrder(); TryUpdateModel(order); try { //if ((PromoCode.ToUpper().Split(',').Contains(values["PromoCode"].ToUpper()) == false) && (string.IsNullOrEmpty(values["PromoCode"]) == false)) //{ // ViewBag.Message = "Invalid Promo Code."; // return View(order); //} //else //{ // order.Username = User.Identity.Name; order.OrderDate = DateTime.Now; //order.Currency = System.Configuration.ConfigurationManager.AppSettings["currency_code"]; order.Currency = System.Configuration.ConfigurationManager.AppSettings["currency_code"]; //order.Name = values["PromoCode"]; //Save Order storeDB.ProductOrders.Add(order); storeDB.SaveChanges(); //Process the order var cart = ShoppingCart.GetCart(this.HttpContext); cart.CreateOrder(order); if (!string.IsNullOrEmpty(order.Customer_name)) { SendEmail(order.Customer_name, order.Customer_Address, order.Emailid, order.OrderId.ToString(), order.mobileNo); } return RedirectToAction("Complete", new { id = order.OrderId }); //} } catch { //Invalid - redisplay with errors return View(order); } }
public int CreateOrder(ProductOrder order) { decimal orderTotal = 0; var cartItems = GetCartItems(); // Iterate over the items in the cart, // adding the order details for each foreach (var item in cartItems) { var orderDetail = new ProductOrderDetail { PDT_Id = item.PDT_Id, OrderId = order.OrderId, UnitPrice = Convert.ToDecimal(item.PRODUCT.PDT_Discount_price), Quantity = item.Count }; // Set the order total of the shopping cart orderTotal += (item.Count * Convert.ToDecimal(item.PRODUCT.PDT_Discount_price)); storeDB.ProductOrderDetails.Add(orderDetail); } // Set the order's total to the orderTotal count // order.Total = orderTotal; var orderprice = storeDB.ProductOrders.Single(oinfo => oinfo.OrderId == order.OrderId); orderprice.Total = orderTotal; // Save the order storeDB.SaveChanges(); // Empty the shopping cart EmptyCart(); // Return the OrderId as the confirmation number return order.OrderId; }