コード例 #1
0
        /// <summary>
        /// Updates the attributes.
        /// </summary>
        /// <param name="mc">The mc.</param>
        private void UpdateAttributes(MetaClass mc)
        {
            for (int i = 0; i < ItemsGrid.Items.Count; i++)
            {
                // Obtain references to row's controls
                HtmlInputCheckBox active     = (System.Web.UI.HtmlControls.HtmlInputCheckBox)ItemsGrid.Items[i].Cells[0].Controls[0];
                TextBox           weightText = (System.Web.UI.WebControls.TextBox)ItemsGrid.Items[i].FindControl("Weight");

                int weight = 0;
                // Wrap in try/catch block to catch errors in the event that someone types in
                // an invalid value for quantity
                try
                {
                    weight = Int32.Parse(weightText.Text);
                }
                catch (System.FormatException)
                {
                }
                catch (System.OverflowException)
                {
                }

                try
                {
                    // delete is unchecked
                    int       fieldId = (int)ItemsGrid.DataKeys[i];
                    MetaField field   = MetaField.Load(MDContext, fieldId);

                    if (active.Checked)
                    {
                        if (mc.UserMetaFields[field.Name] != null)
                        {
                            ((MetaField)mc.UserMetaFields[field.Name]).Weight = weight;
                        }
                        else
                        {
                            mc.AddField(fieldId, weight);
                        }
                    }
                    else
                    {
                        if (mc.UserMetaFields[field.Name] != null)
                        {
                            mc.DeleteField((int)ItemsGrid.DataKeys[i]);
                        }
                    }
                }
                catch (System.FormatException)
                {
                }
                catch (System.OverflowException)
                {
                }
            }
        }
コード例 #2
0
        private void dgSelectedFields_DeleteCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
        {
            int       fieldId    = int.Parse(e.Item.Cells[0].Text);
            MetaClass mc         = GetSelectedMetaClass();
            int       currentPos = mc.GetFieldWeight(fieldId);

            foreach (MetaField mf in mc.UserMetaFields)
            {
                if (mf.Weight > currentPos)
                {
                    mf.Weight = mf.Weight - 1;
                }
            }
            mc.DeleteField(fieldId);

            Response.Redirect("~/Admin/Customization.aspx", true);
        }
コード例 #3
0
        public void OrderSystem_LineItemMetaDataSave()
        {
            bool      metaFieldExists  = false;
            MetaField brandField       = null;
            string    fieldName        = "Brand";
            bool      metaFieldAdded   = false;
            string    testForValue     = "Test";
            string    returnedValue    = "";
            Cart      cart             = null;
            Cart      newCart          = null;
            Cart      retrieveTestCart = null;
            Guid      customerId       = Guid.NewGuid();

            //Create cart. This cart is just used to get the lineitem meta class information
            try
            {
                cart = OrderHelper.CreateCartSimple(customerId);
            }
            catch (Exception exc)
            {
                if (exc.Message == "'maxValue' must be greater than zero.\r\nParameter name: maxValue")
                {
                    Assert.Fail("Check your ApplicationId");
                }
                else
                {
                    throw exc;
                }
            }

            //first make sure the meta field exists in the collection for the LineItem  collection
            MetaDataContext context = OrderContext.MetaDataContext;
            MetaClass       mc      = cart.OrderForms[0].LineItems[0].MetaClass;

            for (int i = 0; i < mc.MetaFields.Count; i++)
            {
                if (mc.MetaFields[i].Name.Equals(fieldName, StringComparison.OrdinalIgnoreCase))
                {
                    brandField      = mc.MetaFields[i];
                    metaFieldExists = true;
                    break;
                }
            }

            if (!metaFieldExists)
            {
                brandField = MetaField.Load(context, fieldName);

                if (brandField == null)
                {
                    brandField     = MetaField.Create(context, "Mediachase.Commerce.Orders.System", fieldName, fieldName, "", MetaDataType.ShortString, 100, true, false, false, false, false);
                    metaFieldAdded = true;
                }
                mc.AddField(brandField);
            }

            //use a new customer id for the new cart
            customerId = Guid.NewGuid();

            //Create a new cart that will be used to add meta data to and save
            newCart = OrderHelper.CreateRetrieveOneLineItemCart(customerId);

            //now add a value for this new metafield in the first lineitem in the cart
            newCart.OrderForms[0].LineItems[0][fieldName] = testForValue;
            newCart.AcceptChanges();

            //now retrieve the cart anew and test
            retrieveTestCart = Cart.LoadByCustomerAndName(newCart.CustomerId, newCart.Name);

            //check for the value
            if (retrieveTestCart.OrderForms[0].LineItems[0][fieldName] != null)
            {
                returnedValue = retrieveTestCart.OrderForms[0].LineItems[0][fieldName].ToString();
            }

            if (!metaFieldExists)
            {
                mc.DeleteField(brandField);
            }

            //delete the field if added
            if (metaFieldAdded)
            {
                MetaField.Delete(context, brandField.Id);
            }

            if (testForValue != returnedValue)
            {
                Assert.Fail("Value was not saved");
            }
        }