예제 #1
0
        public void AddProperty(Guid productID, string propertyName, string propertyValue, bool isImportant)
        {
            using (ShopDataContext db = new ShopDataContext())
            {
                var prod = db.Products.FirstOrDefault(p => p.ProductID == productID);
                BL.ProductProperty pr = new ProductProperty()
                                            {
                                                PropertyName = propertyName,
                                                PropertyValue = propertyValue,
                                                IsImportant = isImportant,
                                                PropertyID = Guid.NewGuid()
                                            };

                BL.ProductsRefProperty propRef = new ProductsRefProperty()
                                                     {
                                                         ID = Guid.NewGuid(),
                                                         ProductID = prod.ProductID,
                                                         ProductPropertiesID = pr.PropertyID
                                                     };

                switch (propertyName)
                {
                    case BL.ProductPropertyConstants.ProductPhotoOriginal:
                        propRef.Sort = prod.ProductProperties.Count(p => p.PropertyName == BL.ProductPropertyConstants.ProductPhotoOriginal);
                        break;
                    case BL.ProductPropertyConstants.ProductPhotoPreview:
                        propRef.Sort = 0;
                        break;
                    case BL.ProductPropertyConstants.ProductDescription:
                        propRef.Sort = 0;
                        break;
                    default:
                        propRef.Sort = prod.ProductProperties.Count(p =>
                                             p.PropertyName != BL.ProductPropertyConstants.ProductDescription
                                             && p.PropertyName != BL.ProductPropertyConstants.ProductPhotoOriginal
                                             && p.PropertyName != BL.ProductPropertyConstants.ProductPhotoPreview);
                        break;
                }

                prod.ProductProperties.Add(pr);
                prod.ProductsRefProperies.Add(propRef);
                db.SubmitChanges();
            }
        }
예제 #2
0
        public void AddProductProperty(string propertyName, string propertyValue, Guid productID)
        {
            using (ShopDataContext db = new ShopDataContext())
            {
                BL.Product prod = db.Products.FirstOrDefault(p => p.ProductID == productID);
                if (prod == null)
                    return;

                BL.ProductsRefProperty refProp = new ProductsRefProperty()
                {
                    ID = Guid.NewGuid(),
                    Sort = prod.ProductsRefProperies.Count,
                    ProductID = productID
                };

                BL.ProductProperty prop = new ProductProperty()
                {
                    IsImportant = true,
                    PropertyID = Guid.NewGuid(),
                    PropertyName = BL.ProductPropertyConstants.ProductDescription,
                    PropertyValue = propertyValue,
                    Sort = prod.ProductProperties.Count,
                };
                prop.ProductsRefProperies.Add(refProp);
                prod.ProductProperties.Add(prop);
                db.SubmitChanges();
            }
        }
예제 #3
0
        public bool AddProperties(Guid productID, List<BL.ProductProperty> props)
        {
            bool allRight = false;
            using (ShopDataContext db = new ShopDataContext())
            {
                BL.Product prod = db.Products.FirstOrDefault(p => p.ProductID == productID);
                if (prod != null)
                {
                    int index = 0;
                    foreach (var item in props)
                    {
                        BL.ProductProperty pr = new ProductProperty()
                                                    {
                                                        Sort = item.Sort,
                                                        PropertyName = item.PropertyName,
                                                        PropertyValue = item.PropertyValue,
                                                        IsImportant = item.IsImportant,
                                                        PropertyID = Guid.NewGuid()
                                                    };
                        prod.ProductProperties.Add(pr);
                        BL.ProductsRefProperty pref = new ProductsRefProperty()
                        {
                            ProductPropertiesID = pr.PropertyID,
                            Sort = index,
                            ID = Guid.NewGuid()
                        };
                        prod.ProductsRefProperies.Add(pref);

                        index++;
                    }
                    db.SubmitChanges();
                    allRight = true;
                }
            }
            return allRight;
        }