예제 #1
0
        public bool AddItems(int userId, ItemDataBase[] items)
        {
            if (!_carts.TryGetValue(userId, out var dbItems))
            {
                _carts[userId] = new List <ItemDataBase>(items);
                return(true);
            }

            foreach (var item in items)
            {
                var search = new ItemSearch(item.Id);
                var ind    = dbItems.FindIndex(search.HasId);
                if (ind < 0)
                {
                    dbItems.Add(item);
                }
                else
                {
                    dbItems[ind].Quentity += item.Quentity;
                }
            }

            return(true);
        }