Ejemplo n.º 1
0
        public void UpdateProductAttribute(PRODUCT_ATTRIBUTE Attribute)
        {
            _productDAO.UpdateProductAttribute(Attribute);
            Context.SaveChanges();

            // EF maintains objects in context, so if during the same request the same object is read, it will not be loaded from db
            // but instead the context version will be used. Here the quantity property isn't updated, so context will have a 0 value for it
            // a refresh is needed to get the last version
            Context.Refresh(RefreshMode.StoreWins, Attribute);
        }
Ejemplo n.º 2
0
        private void FixupPRODUCT_ATTRIBUTE(PRODUCT_ATTRIBUTE previousValue)
        {
            if (previousValue != null && previousValue.ORDER_DETAIL.Contains(this))
            {
                previousValue.ORDER_DETAIL.Remove(this);
            }

            if (PRODUCT_ATTRIBUTE != null)
            {
                if (!PRODUCT_ATTRIBUTE.ORDER_DETAIL.Contains(this))
                {
                    PRODUCT_ATTRIBUTE.ORDER_DETAIL.Add(this);
                }
                if (ProdAttrID != PRODUCT_ATTRIBUTE.ID)
                {
                    ProdAttrID = PRODUCT_ATTRIBUTE.ID;
                }
            }
        }
Ejemplo n.º 3
0
        private void FixupPRODUCT_ATTRIBUTE(PRODUCT_ATTRIBUTE previousValue)
        {
            if (previousValue != null && previousValue.SHOPPING_CART.Contains(this))
            {
                previousValue.SHOPPING_CART.Remove(this);
            }

            if (PRODUCT_ATTRIBUTE != null)
            {
                if (!PRODUCT_ATTRIBUTE.SHOPPING_CART.Contains(this))
                {
                    PRODUCT_ATTRIBUTE.SHOPPING_CART.Add(this);
                }
                if (ProdAttrID != PRODUCT_ATTRIBUTE.ID)
                {
                    ProdAttrID = PRODUCT_ATTRIBUTE.ID;
                }
            }
        }
Ejemplo n.º 4
0
 public void AddProductAttribute(PRODUCT_ATTRIBUTE Attribute)
 {
     _productDAO.AddProductAttribute(Attribute);
     Context.SaveChanges();
 }
Ejemplo n.º 5
0
        private void setAttributes(List<CATEGORY> categoriesList, PRODUCT product, FZExcelProduct exProd)
        {
            // TODO when different attributes used, this should be changed to be dynamic!
            int? sizeAttribute = categoriesList.FirstOrDefault().AttributeID;

            List<D_ATTRIBUTE_VALUE> attrValueList = _attributeDAO.GetAttributeValues(sizeAttribute.Value);
            PRODUCT_ATTRIBUTE prodAttr;
            int availability = 0;
            int attrValId = 0;

            // TODO this should be generalized for other attributes

            // XS size
            if (int.TryParse(exProd.SizeXS, out availability) && availability != 0)
            {
                attrValId = attrValueList.Where(a => a.Value.Equals("XS")).FirstOrDefault().ID;
                prodAttr = new PRODUCT_ATTRIBUTE()
                {
                    AttributeValueID = attrValId,
                    ProductID = product.ID,
                    Availability = availability,
                    Quantity = availability,
                };
                AddProductAttribute(prodAttr);
            }

            // S size
            if (int.TryParse(exProd.SizeS, out availability) && availability != 0)
            {
                attrValId = attrValueList.Where(a => a.Value.Equals("S")).FirstOrDefault().ID;
                prodAttr = new PRODUCT_ATTRIBUTE()
                {
                    AttributeValueID = attrValId,
                    ProductID = product.ID,
                    Availability = availability,
                    Quantity = availability,
                };
                AddProductAttribute(prodAttr);
            }

            // M size
            if (int.TryParse(exProd.SizeM, out availability) && availability != 0)
            {
                attrValId = attrValueList.Where(a => a.Value.Equals("M")).FirstOrDefault().ID;
                prodAttr = new PRODUCT_ATTRIBUTE()
                {
                    AttributeValueID = attrValId,
                    ProductID = product.ID,
                    Availability = availability,
                    Quantity = availability,
                };
                AddProductAttribute(prodAttr);
            }

            // L size
            if (int.TryParse(exProd.SizeL, out availability) && availability != 0)
            {
                attrValId = attrValueList.Where(a => a.Value.Equals("L")).FirstOrDefault().ID;
                prodAttr = new PRODUCT_ATTRIBUTE()
                {
                    AttributeValueID = attrValId,
                    ProductID = product.ID,
                    Availability = availability,
                    Quantity = availability,
                };
                AddProductAttribute(prodAttr);
            }

            // XL size
            if (int.TryParse(exProd.SizeXL, out availability) && availability != 0)
            {
                attrValId = attrValueList.Where(a => a.Value.Equals("XL")).FirstOrDefault().ID;
                prodAttr = new PRODUCT_ATTRIBUTE()
                {
                    AttributeValueID = attrValId,
                    ProductID = product.ID,
                    Availability = availability,
                    Quantity = availability,
                };
                AddProductAttribute(prodAttr);
            }

            // XXL size
            if (int.TryParse(exProd.SizeXXL, out availability) && availability != 0)
            {
                attrValId = attrValueList.Where(a => a.Value.Equals("XXL")).FirstOrDefault().ID;
                prodAttr = new PRODUCT_ATTRIBUTE()
                {
                    AttributeValueID = attrValId,
                    ProductID = product.ID,
                    Availability = availability,
                    Quantity = availability,
                };
                AddProductAttribute(prodAttr);
            }
        }
Ejemplo n.º 6
0
        private void saveAttributes(PRODUCT product)
        {
            string prodAttrID, attrValID, availability;
            PRODUCT_ATTRIBUTE prodAttr;
            int id;
            foreach (ListViewDataItem item in lvAttributeValues.Items)
            {
                prodAttrID = attrValID = availability = String.Empty;

                prodAttrID = ((HiddenField)item.FindControl("prodAttrID")).Value;
                attrValID = ((HiddenField)item.FindControl("attrValID")).Value;
                availability = ((TextBox)item.FindControl("txtAvailability")).Text;

                id = 0;

                prodAttr = new PRODUCT_ATTRIBUTE();
                if (!String.IsNullOrEmpty(prodAttrID) && !String.IsNullOrEmpty(attrValID) && Int32.TryParse(prodAttrID, out id))
                {
                    // if availability is 0 and the attribute is never associated to this product, value is not considered
                    if (availability == "0" && id == 0)
                        continue;

                    ddlAttributes.Visible = false;
                    prodAttr.Availability = Int32.Parse(availability);
                    prodAttr.AttributeValueID = Int32.Parse(attrValID);
                    prodAttr.ProductID = product.ID;
                    // old version from previous retrieval
                    prodAttr.Version = (byte[])lvAttributeValues.DataKeys[item.DataItemIndex].Value;
                    if (id != 0)
                    {
                        // not new
                        prodAttr.ID = id;
                        ApplicationContext.Current.Products.UpdateProductAttribute(prodAttr);
                    }
                    else
                    {
                        // new, quantity is set only this time
                        prodAttr.Quantity = prodAttr.Availability;
                        ApplicationContext.Current.Products.AddProductAttribute(prodAttr);
                        ((HiddenField)item.FindControl("prodAttrID")).Value = prodAttr.ID.ToString();
                        ((Label)item.FindControl("lblQuantity")).Text = prodAttr.Quantity.ToString();
                    }
                }
            }

            // the list view is updated to reflect new versions after update
            List<PRODUCT_ATTRIBUTE> attributes = ApplicationContext.Current.Products.GetProductAttributes(ProductID);
            if (attributes.Count > 0)
            {
                populateAttributeValues(attributes.First().D_ATTRIBUTE_VALUE.AttributeID, attributes);
                updPanelAttributes.Update();
            }
        }
Ejemplo n.º 7
0
     private void FixupPRODUCT_ATTRIBUTE(PRODUCT_ATTRIBUTE previousValue)
     {
         if (previousValue != null && previousValue.ORDER_DETAIL.Contains(this))
         {
             previousValue.ORDER_DETAIL.Remove(this);
         }
 
         if (PRODUCT_ATTRIBUTE != null)
         {
             if (!PRODUCT_ATTRIBUTE.ORDER_DETAIL.Contains(this))
             {
                 PRODUCT_ATTRIBUTE.ORDER_DETAIL.Add(this);
             }
             if (ProdAttrID != PRODUCT_ATTRIBUTE.ID)
             {
                 ProdAttrID = PRODUCT_ATTRIBUTE.ID;
             }
         }
     }
Ejemplo n.º 8
0
 public void UpdateProductAttribute(PRODUCT_ATTRIBUTE Attribute, bool Attach = true)
 {
     if (Attach)
     {
         Context.PRODUCT_ATTRIBUTE.Attach(Attribute);
     }
     var entry = Context.ObjectStateManager.GetObjectStateEntry(Attribute);
     entry.SetModifiedProperty("Availability");
 }
Ejemplo n.º 9
0
 public void AddProductAttribute(PRODUCT_ATTRIBUTE Attribute)
 {
     Context.PRODUCT_ATTRIBUTE.AddObject(Attribute);
 }
Ejemplo n.º 10
0
        private void FixupPRODUCT_ATTRIBUTE(PRODUCT_ATTRIBUTE previousValue)
        {
            if (previousValue != null && previousValue.SHOPPING_CART.Contains(this))
            {
                previousValue.SHOPPING_CART.Remove(this);
            }

            if (PRODUCT_ATTRIBUTE != null)
            {
                if (!PRODUCT_ATTRIBUTE.SHOPPING_CART.Contains(this))
                {
                    PRODUCT_ATTRIBUTE.SHOPPING_CART.Add(this);
                }
                if (ProdAttrID != PRODUCT_ATTRIBUTE.ID)
                {
                    ProdAttrID = PRODUCT_ATTRIBUTE.ID;
                }
            }
        }