Esempio n. 1
0
        public bool IsProductEquals(CartLine line)
        {
            if (SellerId != line.SellerId)
            {
                return(false);
            }

            if (ProductTypeId != line.ProductTypeId)
            {
                return(false);
            }

            //check Attributes length
            if ((Attributes?.Count() ?? 0) != (Attributes?.Count() ?? 0))
            {
                return(false);
            }

            //check Attribute key and value
            if (Attributes != null || Attributes.Count != 0)
            {
                foreach (var attribute in Attributes)
                {
                    if (line.Attributes.TryGetValue(attribute.Key, out string value))
                    {
                        if (attribute.Value != value)
                        {
                            return(false);
                        }
                    }
                    else
                    {
                        return(false);
                    }
                }
            }

            return(true);
        }
Esempio n. 2
0
        public virtual void AddItem(int sellerId, int productTypeId, short quantity, IDictionary <string, string> attributes)
        {
            CartLine newLine = new CartLine
            {
                SellerId      = sellerId,
                ProductTypeId = productTypeId,
                Quantity      = quantity,
                Attributes    = attributes
            };

            CartLine line = Lines
                            .FirstOrDefault(l => l.IsProductEquals(newLine));

            if (line == null)
            {
                Lines.Add(newLine);
            }
            else
            {
                line.Quantity += quantity;
            }
        }