public ActionResult ProcessCheckout(ShippingAddress shippingaddress,ShippingMethod shippingMethod,CustomerBilling customerBilling, Order order, OrderDetail orderDetail, OrderStatu orderstatus) { int customerID = Convert.ToInt32(Session["customerID"]); var customerEmail = Session["customerEmail"].ToString(); try { using (ShippingAddressEntities shippingEntities = new ShippingAddressEntities()) { CustomerAddressEntities cAddentity = new CustomerAddressEntities(); List<CustomerAddress> customeraddress = cAddentity.CustomerAddresses.Where(x => x.customerAddress_ID == customerID).ToList(); shippingaddress.customer_ID = customerID; shippingaddress.CustomerAddress_ID = customeraddress[0].customerAddress_ID; shippingEntities.ShippingAddresses.Add(shippingaddress); shippingEntities.SaveChanges(); } using(CustomerBillingEntities customerBillingentity = new CustomerBillingEntities()) { customerBilling.customer_ID = customerID; customerBillingentity.CustomerBillings.Add(customerBilling); customerBillingentity.SaveChanges(); } //loop through products in the cart session //the information is used to populate database foreach (Item item in (List<Item>)Session["cart"]) { using (OrderDetailsEntities orderDetailsEntities = new OrderDetailsEntities()) { orderDetail.product_ID = item.Pr.product_ID; orderDetail.quantity = item.Pr.quantity; orderDetail.total = item.Pr.quantity * item.Pr.price; orderDetailsEntities.OrderDetails.Add(orderDetail); orderDetailsEntities.SaveChanges(); } using (OrdersEntities ordersEntity = new OrdersEntities()) { decimal total = item.Pr.quantity * item.Pr.price; order.orderDetails_ID = orderDetail.orderDetails_ID; order.customer_ID = customerID; order.orderStatus_ID = 1; //pending order look at table OrderStatus order.customerBilling_ID = customerBilling.customerBilling_ID; order.shippingAddress_ID = shippingaddress.shippingAddress_ID; order.shippingMethod_ID = shippingMethod.shippingMethod_ID; order.customerBilling_ID = customerBilling.customerBilling_ID; order.orderDate = DateTime.Now; order.tax = total * Convert.ToDecimal(.07); order.grandTotal = order.tax + total; ordersEntity.Orders.Add(order); ordersEntity.SaveChanges(); } } return RedirectToAction("Sent"); } catch(SmtpException ex) { return View("Checkout"); } catch (Exception ex) { return View("Checkout"); } //possibly write an if statement if they are not logged in make them login //else go to the dashboard return RedirectToAction("Index","Home"); }
public ActionResult Billing() { if (ModelState.IsValid) { int customerID = Convert.ToInt32(Session["customerID"]); using(CustomerBillingEntities cbentities = new CustomerBillingEntities()) { ViewBag.customerBillinginfo = cbentities.CustomerBillings.Where(x => x.customer_ID == customerID).ToList().FirstOrDefault(); } } return View(); }