public IList <OrderedItemModel> NormalizeOrderedItems(List <OrderedItemModel> items)
        {
            List <OrderedItemModel> normalizedItems = new List <OrderedItemModel>();

            while (items.Count > 0)
            {
                OrderedItemModel   currentItem = items[0];
                OrderedItemModel[] equalItems  = items.Where(i => i.Equals(currentItem)).ToArray();
                int totalQuantity = 0;
                foreach (OrderedItemModel equalItem in equalItems)
                {
                    if (equalItem.Price != currentItem.Price)
                    {
                        return(null);
                    }

                    totalQuantity += equalItem.Quantity.Value;
                }

                items.RemoveAll(i => i.Equals(currentItem));
                currentItem.Quantity = totalQuantity;

                normalizedItems.Add(currentItem);
            }

            return(normalizedItems);
        }
        public override bool Equals(object obj)
        {
            if (obj == null)
            {
                return(false);
            }

            OrderedItemModel other = obj as OrderedItemModel;

            if (other == null)
            {
                return(false);
            }

            if (this.ArticleId != other.ArticleId)
            {
                return(false);
            }

            if (this.SizeId != other.SizeId)
            {
                return(false);
            }

            if (this.ColorId != other.ColorId)
            {
                return(false);
            }

            return(true);
        }
Exemplo n.º 3
0
        public async Task<bool> ValidateOrderedItem(OrderedItemModel orderedItem)
        {
            ArticlesProvider articlesProvider = new ArticlesProvider();
            Task<bool> articleExistsTask = articlesProvider.HasArticleWithPrice(orderedItem.ArticleId.Value, orderedItem.Price.Value);

            StocksProvider stocksProvider = new StocksProvider();
            Task<bool> hasStocksTask = stocksProvider.HasEnoughStocksOfArticle(orderedItem.ArticleId.Value, orderedItem.SizeId.Value, orderedItem.ColorId, orderedItem.Quantity.Value);

            bool articleExists = await articleExistsTask;
            bool hasEnoughStocks = await hasStocksTask;

            bool isOrderValid = articleExists && hasEnoughStocks;

            return isOrderValid;
        }