コード例 #1
0
        public ActionResult Product(int productID)
        {
            var product = Products.GetByID(productID).Clone(UserID);

            product.CreatedDate = DateTime.Now;

            Products.Insert(product);

            foreach (var item in ProductGroups.GetByProductID(productID))
            {
                ProductGroups.Insert(new ProductGroup()
                {
                    ProductID = product.ID,
                    GroupID   = item.GroupID
                });
            }

            foreach (var item in AttributeValues.GetByProductID(productID))
            {
                AttributeValues.Insert(new AttributeValue()
                {
                    ProductID         = product.ID,
                    AttributeID       = item.AttributeID,
                    AttributeOptionID = item.AttributeOptionID,
                    Value             = item.Value
                });
            }

            return(Redirect("/Admin/Products/Edit/" + product.ID));
        }
コード例 #2
0
        private void SaveAttributes(HttpRequestBase req, int productID)
        {
            var exists = false;

            foreach (string key in req.Form)
            {
                if (key.StartsWith("attr_"))
                {
                    exists = true;
                    break;
                }
            }

            if (!exists)
            {
                return;
            }

            AttributeValues.DeleteBy(productID);

            var attrValues = new List <AttributeValue>();

            foreach (string key in req.Form)
            {
                if (key.StartsWith("attr_"))
                {
                    var id    = int.Parse(key.Replace("attr_", String.Empty));
                    var value = req.Form[key];

                    var attr      = Attributes.GetByID(id);
                    var attrValue = new AttributeValue();

                    attrValue.ProductID   = productID;
                    attrValue.AttributeID = attr.ID;

                    attrValues.Add(attrValue);

                    switch (attr.AttributeType)
                    {
                    case AttributeType.Text:
                        attrValue.Value = value;
                        break;

                    case AttributeType.Number:
                        attrValue.Value = value;
                        break;

                    case AttributeType.SingleItem:
                        if (!String.IsNullOrWhiteSpace(value))
                        {
                            attrValue.AttributeOptionID = int.Parse(value);
                        }
                        break;

                    case AttributeType.MultipleItem:
                        attrValues.Remove(attrValues.Last());

                        var selecteds = value.Split(',');
                        foreach (var item in selecteds)
                        {
                            var atv = (AttributeValue)attrValue.Clone();
                            atv.AttributeOptionID = int.Parse(item);

                            attrValues.Add(atv);
                        }

                        break;

                    case AttributeType.Check:
                        //attrValue.Value = bool.Parse(value).ToString();
                        break;

                    case AttributeType.MultilineText:
                        attrValue.Value = value;
                        break;

                    default:
                        break;
                    }
                }
            }

            foreach (var item in attrValues)
            {
                AttributeValues.Insert(item);
            }
        }