Exemplo n.º 1
0
        /// <summary>
        /// Loads the context.
        /// </summary>
        private void LoadContext()
        {
            //if (OrderGroupId > 0)
            {
                OrderGroup order      = null;
                bool       cartLoaded = false;
                Cart       cart       = null;
                if (!this.IsPostBack && (!this.Request.QueryString.ToString().Contains("Callback=yes"))) // load fresh on initial load
                {
                    order = LoadFresh();

                    if (order == null)
                    {
                        cart = CreateFreshCart();

                        cartLoaded = true;

                        // persist in session
                        Session[_OrderGroupDtoSessionKey] = cart;
                    }
                }
                else // load from session
                {
                    order = (OrderGroup)Session[_OrderGroupDtoSessionKey];

                    if (order == null)
                    {
                        order = LoadFresh();
                    }
                }

                // Put a dictionary key that can be used by other tabs
                IDictionary dic = new ListDictionary();
                if (cartLoaded)
                {
                    dic.Add(_OrderContextObjectString, cart);
                }
                else
                {
                    dic.Add(_OrderContextObjectString, order);
                }

                // Call tabs load context
                ViewControl.LoadContext(dic);

                // Load order group context
                OrderGroupEdit.LoadContext(dic);
            }

            EditSaveControl.SavedClientScript  = String.Format("CSManagementClient.ChangeView('Order', 'Orders-List', 'filter={0}&class={1}');", FilterType, ClassType);
            EditSaveControl.CancelClientScript = String.Format("CSManagementClient.ChangeView('Order', 'Orders-List', 'filter={0}&class={1}');", FilterType, ClassType);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Handles the SaveChanges event of the EditSaveControl control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
        void EditSaveControl_SaveChanges(object sender, EventArgs e)
        {
            OrderGroup order      = (OrderGroup)Session[_OrderGroupDtoSessionKey];
            bool       cartLoaded = false;
            Cart       cart       = null;

            if (order == null && OrderGroupId > 0)
            {
                if (this.ViewId.StartsWith(_PaymentPlanViewId, StringComparison.OrdinalIgnoreCase))
                {
                    order = OrderContext.Current.GetPaymentPlan(CustomerId, OrderGroupId);
                }
                else if (this.ViewId.StartsWith(_PurchaseOrderViewId, StringComparison.OrdinalIgnoreCase))
                {
                    order = OrderContext.Current.GetPurchaseOrder(CustomerId, OrderGroupId);
                }
                else if (this.ViewId.StartsWith(_ShoppingCartViewId, StringComparison.OrdinalIgnoreCase))
                {
                    order = OrderContext.Current.GetCart(CustomerId, OrderGroupId);
                }
            }

            // if order is still null, create an empty cart
            if (order == null)
            {
                cart       = CreateFreshCart();
                cartLoaded = true;
                Session[_OrderGroupDtoSessionKey] = cart;
            }

            // Put a dictionary key that can be used by other tabs
            IDictionary dic = new ListDictionary();

            if (cartLoaded)
            {
                dic.Add(_OrderContextObjectString, cart);
            }
            else
            {
                dic.Add(_OrderContextObjectString, order);
            }

            // Call tabs save
            OrderGroupEdit.SaveChanges(dic);
            ViewControl.SaveChanges(dic);

            Cart cartFromSession = order as Cart;

            if (cartFromSession != null)             // if we're in create mode, save cart as order (payment plan, cart)
            {
                if (this.ViewId.StartsWith(_PaymentPlanViewId, StringComparison.OrdinalIgnoreCase))
                {
                    cartFromSession.SaveAsPaymentPlan();
                }
                else if (this.ViewId.StartsWith(_PurchaseOrderViewId, StringComparison.OrdinalIgnoreCase))
                {
                    cartFromSession.SaveAsPurchaseOrder();
                }
                else if (this.ViewId.StartsWith(_ShoppingCartViewId, StringComparison.OrdinalIgnoreCase))
                {
                    cartFromSession.AcceptChanges();
                }
            }
            else
            {
                // Persist changes to the database
                order.AcceptChanges();
            }

            Session.Remove(_OrderGroupDtoSessionKey);
        }