/// <summary>
        /// Add the order, pass cart, customer # and order amount to ViewModel
        /// </summary>
        /// <returns></returns>
        public ActionResult genOrder()
        {
            OrderViewModel myOrder = new OrderViewModel();
            try
            {
                myOrder.AddOrder((CartItem[])Session["Cart"],
                                  Convert.ToInt32(Session["CustomerID"]),
                                  (double)Session["OrderAmt"]);

                if (myOrder.OrderID > 0) // Order Added
                {
                    ViewBag.Message = "Order " + myOrder.OrderID + " Created!";
                    if (myOrder.BackOrderFlag > 0)
                        ViewBag.Message += " Some goods were backordered!";
                }
                else  // problem
                    ViewBag.Message = myOrder.Message + ", try again later!";
            }

            catch (Exception ex)
            {
                ViewBag.Message = "Order was not created, try again later! - " + ex.Message;
            }
            return PartialView("PopupMessage");
        }
 //
 // GET: /Orders/getOrdersJson
 public JsonResult getJsonOrders()
 {
     JsonResult jr;
     try
     {
         OrderViewModel myOrder = new OrderViewModel();
         myOrder.CustomerID = Convert.ToInt32(Session["CustomerID"]);
         List<OrderDetailViewModel> orders = myOrder.GetAllDetailsForAllOrders();
         jr = this.Json(orders, JsonRequestBehavior.AllowGet);
     }
     catch (Exception ex)
     {
         ViewBag.Message = ex.Message;
         jr = Json(ViewBag.Message);
     }
     return jr;
 }
        public static HtmlString OrderList(this HtmlHelper helper, string id)
        {
            OrderViewModel myOrder = new OrderViewModel();
            myOrder.CustomerID = Convert.ToInt32(HttpContext.Current.Session["CustomerID"]);
            List<OrderViewModel> orders = myOrder.GetAllForCust();

            bool colorSwitch = false;
            string bgClass;

            // Create tag builder
            var builder = new TagBuilder("table");
            StringBuilder innerHtml = new StringBuilder();

            // Create valid id
            builder.GenerateId(id);
            builder.MergeAttribute("style", "width:100%;");

            // Render tag
            innerHtml.Append("<thead><tr><th class='tblItemHead2'>ID</th><th class='tblItemHead2'>Date</th></tr></thead>");
            foreach (OrderViewModel order in orders)
            {
                if (colorSwitch == false)
                {
                    colorSwitch = true;
                    bgClass = " class='trWhite' ";
                }
                else
                {
                    bgClass = " class='trGray' ";
                    colorSwitch = false;
                }
                // details from cart
                innerHtml.Append("<tr " + bgClass + "><td id='OrderNo'>" + String.Format("{0:00}", Convert.ToString(order.OrderID)) + "&nbsp;&nbsp;" + "</td>");
                innerHtml.Append("<td>" + String.Format("{0:yyyy/MM/dd}", order.OrderDate) + "</td></tr>");
            }

            builder.InnerHtml = innerHtml.ToString();

            return new HtmlString(builder.ToString());
        }
示例#4
0
        /// <summary>
        /// Get order information for a single customer
        /// </summary>
        /// <returns>List of OrderWeb instances to Presentation layer</returns>
        public List<OrderViewModel> GetAllForCust()
        {
            List<OrderViewModel> webOrders = new List<OrderViewModel>();
            try
            {
                OrderModel data = new OrderModel();
                List<Order> dataOrders = data.GetAllForCust(CustomerID);

                // We return OrderViewModel instances as the Asp layer has no knowledge of EF
                foreach (Order o in dataOrders)
                {
                    OrderViewModel ordWeb = new OrderViewModel();
                    ordWeb.OrderID = o.OrderID;
                    ordWeb.OrderDate = o.OrderDate;
                    ordWeb.OrderAmount = o.OrderAmount;
                    webOrders.Add(ordWeb);
                }
            }
            catch (Exception e)
            {
                ErrorRoutine(e, "OrderViewModel", "GetAllForCust");
            }
            return webOrders;
        }