Exemple #1
0
 /// <summary>
 /// Create a new ProductAttributeStaticValues object.
 /// </summary>
 /// <param name="id">Initial value of the Id property.</param>
 /// <param name="value">Initial value of the Value property.</param>
 /// <param name="productAttributeId">Initial value of the ProductAttributeId property.</param>
 /// <param name="productId">Initial value of the ProductId property.</param>
 public static ProductAttributeStaticValues CreateProductAttributeStaticValues(global::System.Int32 id, global::System.String value, global::System.Int32 productAttributeId, global::System.Int32 productId)
 {
     ProductAttributeStaticValues productAttributeStaticValues = new ProductAttributeStaticValues();
     productAttributeStaticValues.Id = id;
     productAttributeStaticValues.Value = value;
     productAttributeStaticValues.ProductAttributeId = productAttributeId;
     productAttributeStaticValues.ProductId = productId;
     return productAttributeStaticValues;
 }
Exemple #2
0
 /// <summary>
 /// Deprecated Method for adding a new object to the ProductAttributeStaticValues EntitySet. Consider using the .Add method of the associated ObjectSet&lt;T&gt; property instead.
 /// </summary>
 public void AddToProductAttributeStaticValues(ProductAttributeStaticValues productAttributeStaticValues)
 {
     base.AddObject("ProductAttributeStaticValues", productAttributeStaticValues);
 }
Exemple #3
0
        public ActionResult Attributes(int productId, FormCollection form)
        {
            using (var context = new ShopContainer())
            {
                var product = context.Product.Include("ProductAttributeValues").First(p => p.Id == productId);

                PostCheckboxesData cbData = form.ProcessPostCheckboxesData("attr", "productId");
                PostData staticAttrData = form.ProcessPostData("tb", "productId");

                product.ProductAttributeValues.Clear();

                foreach (var kvp in cbData)
                {
                    var attributeValueId = kvp.Key;
                    bool attributeValue = kvp.Value;

                    if (attributeValue)
                    {
                        var productAttributeValue = context.ProductAttributeValues.First(pv => pv.Id == attributeValueId);
                        product.ProductAttributeValues.Add(productAttributeValue);
                    }
                }


                foreach (var kvp in staticAttrData)
                {
                    int attributeId = Convert.ToInt32(kvp.Key);
                    foreach (var value in kvp.Value)
                    {
                        string attributeValue = value.Value;

                        var productAttribute = context.ProductAttribute.Include("ProductAttributeStaticValues").First(pa => pa.Id == attributeId);

                        //productAttribute.ProductAttributeStaticValues.Clear();

                        ProductAttributeStaticValues productAttributeValue = null;
                        productAttributeValue = context.ProductAttributeStaticValues.FirstOrDefault(
                                pav => pav.ProductAttribute.Id == productAttribute.Id && pav.Product.Id == product.Id);


                        if (string.IsNullOrEmpty(attributeValue))
                        {
                            if (productAttributeValue != null)
                                context.DeleteObject(productAttributeValue);
                        }
                        else
                        {
                            if (productAttributeValue == null)
                            {



                                productAttributeValue = new ProductAttributeStaticValues
                                                            {
                                                                Value = attributeValue,
                                                                ProductAttribute = productAttribute
                                                            };
                                product.ProductAttributeStaticValues.Add(productAttributeValue);

                            }
                            else
                            {
                                productAttributeValue.Value = attributeValue;
                            }
                        }
                        //productAttribute.ProductAttributeValues.Add(productAttributeValue);


                    }
                }

                context.SaveChanges();




                return RedirectToAction("Index");
            }
        }