/// <summary>
        /// The add.
        /// </summary>
        /// <param name="item">
        /// The item.
        /// </param>
        internal new void Add(ILineItem item)
        {
            using (new WriteLock(this._addLocker))
            {
                var key = this.GetKeyForItem(item);
                if (key != null)
                {
                    var exists = this.Contains(key);
                    if (exists)
                    {
                        this[key].Quantity += item.Quantity;
                        return;
                    }
                }

                if (this.ValidateAdd != null)
                {
                    if (!this.ValidateAdd(item))
                    {
                        return;
                    }
                }

                if (AddingItem != null)
                {
                    AddingItem.Invoke(this, new AddItemEventArgs(item));
                }

                base.Add(item);

                this.OnAdd.IfNotNull(x => x.Invoke());

                this.OnCollectionChanged(new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Add, item));
            }
        }
Beispiel #2
0
        private void ExecuteClearAddingItemCommand()
        {
            var publicProperties = AddingItem.GetType().GetProperties();

            foreach (var publicProperty in publicProperties)
            {
                if (publicProperty.CanWrite && publicProperty.GetSetMethod(false) != null)
                {
                    if (publicProperty.PropertyType != typeof(string) && typeof(IList).IsAssignableFrom(publicProperty.PropertyType))
                    {
                        var list = (publicProperty.GetValue(AddingItem, null) as IList);
                        list.Clear();
                    }
                    else
                    {
                        publicProperty.SetValue(
                            AddingItem,
                            publicProperty.DeclaringType.IsValueType
                                ? Activator.CreateInstance(publicProperty.DeclaringType)
                                : null,
                            null);
                    }
                }
            }
        }
Beispiel #3
0
        public override ListViewItem Add(ListViewItem value)
        {
            if (!noEvents)
            {
                AddingItem?.Invoke(this, value);
            }
            var o = base.Add(value);

            if (!noEvents)
            {
                AddedItem?.Invoke(this, value);
            }
            return(o);
        }
Beispiel #4
0
        private void ExecuteAddAddingItemCommand()
        {
            var collection = (ItemsSource as IList);

            if (collection == null && ItemsSource is ICollectionView)
            {
                collection = (ItemsSource as ICollectionView).SourceCollection as IList;
            }
            if (collection != null && IsAddingDirty)
            {
                collection.Add(AddingItem);
                AddingItem = Activator.CreateInstance(AddingItem.GetType());
            }
        }
        /// <inheritdoc />
        /// <summary>
        ///     Adds an item to the <see cref="T:System.Collections.Generic.ICollection`1"></see>.
        /// </summary>
        /// <param name="item">The object to add to the <see cref="T:System.Collections.Generic.ICollection`1"></see>.</param>
        public void Add(T item)
        {
            AddingItemEventArgs <T> addingItemEventArgs = new AddingItemEventArgs <T>(item);

            AddingItem?.Invoke(this, addingItemEventArgs);
            if (addingItemEventArgs.Cancel)
            {
                return;
            }

            _items.Add(item);

            AddedItemEventArgs <T> addedItemEventArgs = new AddedItemEventArgs <T>(addingItemEventArgs.Item);

            AddedItem?.Invoke(this, addedItemEventArgs);
        }
Beispiel #6
0
 private void ExecuteRemoveItemCommand(object item)
 {
     if (item == AddingItem)
     {
         AddingItem = Activator.CreateInstance(AddingItem.GetType());
     }
     else
     {
         var collection = (ItemsSource as IList);
         if (collection == null && ItemsSource is ICollectionView)
         {
             collection = (ItemsSource as ICollectionView).SourceCollection as IList;
         }
         if (collection != null)
         {
             collection.Remove(item);
         }
     }
 }
        /// <summary>
        /// Adds a line item to the customer item cache.
        /// </summary>
        /// <param name="lineItem">
        /// The <see cref="IItemCacheLineItem"/>.
        /// </param>
        public void AddItem(IItemCacheLineItem lineItem)
        {
            if (lineItem.Quantity <= 0)
            {
                lineItem.Quantity = 1;
            }
            if (lineItem.Price < 0)
            {
                lineItem.Price = 0;
            }

            if (AddingItem.IsRaisedEventCancelled(new Core.Events.NewEventArgs <ILineItem>(lineItem), this))
            {
                return;
            }

            _itemCache.AddItem(lineItem);

            AddedItem.RaiseEvent(new Core.Events.NewEventArgs <ILineItem>(lineItem), this);
        }
        /// <summary>
        /// Constructs a <see cref="IBidirectionalList{T}"/> given <paramref name="values"/>.
        /// </summary>
        /// <param name="values"></param>
        /// <param name="onAdded"></param>
        /// <param name="onRemoved"></param>
        /// <param name="onAdding"></param>
        /// <param name="onRemoving"></param>
        public BidirectionalList(IList <T> values
                                 , BidirectionalListItemCallback <T> onAdded
                                 , BidirectionalListItemCallback <T> onRemoved
                                 , BidirectionalListItemCallback <T> onAdding   = null
                                 , BidirectionalListItemCallback <T> onRemoving = null)
        {
            var defaultItemCallback = DefaultItemCallback;

            // Connect the Bidirectional Item callback conditionally when there is a Callback.
            void ConnectBidiCallback(BidirectionalListItemCallback <T> callback
                                     , Action <BidirectionalList <T>, BidirectionalListItemCallback <T> > onConnect)
            {
                if (callback != null)
                {
                    onConnect.Invoke(this, callback);
                }
            }

            ConnectBidiCallback(onAdded, (x, callback) => x.AddedItem       += callback);
            ConnectBidiCallback(onAdding, (x, callback) => x.AddingItem     += callback);
            ConnectBidiCallback(onRemoved, (x, callback) => x.RemovedItem   += callback);
            ConnectBidiCallback(onRemoving, (x, callback) => x.RemovingItem += callback);

            // Effectively we are also Adding the items to the initial Collection instance.
            foreach (var x in values)
            {
                AddingItem?.Invoke(x);
            }

            Collection = values;

            foreach (var x in values)
            {
                AddedItem?.Invoke(x);
            }
        }
        /// <summary>
        /// Constructs a <see cref="IBidirectionalList{T}"/> given <paramref name="values"/>.
        /// </summary>
        /// <param name="values"></param>
        /// <param name="onAdded"></param>
        /// <param name="onRemoved"></param>
        /// <param name="onAdding"></param>
        /// <param name="onRemoving"></param>
        public BidirectionalList(IList <T> values
                                 , BidirectionalListItemCallback <T> onAdded    = null
                                 , BidirectionalListItemCallback <T> onRemoved  = null
                                 , BidirectionalListItemCallback <T> onAdding   = null
                                 , BidirectionalListItemCallback <T> onRemoving = null)
        {
            AddedItem    += onAdded ?? DefaultCallback();
            AddingItem   += onAdding ?? DefaultCallback();
            RemovedItem  += onRemoved ?? DefaultCallback();
            RemovingItem += onRemoving ?? DefaultCallback();

            // Effectively we are also Adding the items to the initial Collection instance.
            foreach (var x in values)
            {
                AddingItem?.Invoke(x);
            }

            _collection = values;

            foreach (var x in values)
            {
                AddedItem?.Invoke(x);
            }
        }
 void OnAddingItem(GenItemEventArgs args) => AddingItem?.Invoke(this, args);
Beispiel #11
0
        public async static Task <bool> GetAllAdders(ITurnContext turnContext, CancellationToken cancellationToken, IConfiguration config)
        {
            try
            {
                IEnumerable <string> ingridients = turnContext.Activity.Text.Split('+').ToList();


                IEnumerable <Dish> dish = new List <Dish>();
                var client = new HttpClient();
                client.BaseAddress = new Uri(config.GetValue <string>("ConnectionStrings"));
                client.DefaultRequestHeaders.Accept.Clear();
                client.DefaultRequestHeaders.Accept.Add(
                    new MediaTypeWithQualityHeaderValue("application/json"));

                var dania = client.GetAsync($"Ing").Result.Content.ReadAsStringAsync();

                dish = System.Text.Json.JsonSerializer.Deserialize <List <Dish> >(dania.Result).ToList();

                List <AddingItem> firstList = new List <AddingItem>();



                foreach (var item in dish)
                {
                    foreach (var item2 in item.ingridients)
                    {
                        foreach (var x in ingridients)
                        {
                            if (x != "")
                            {
                                if (item2.name.StartsWith(x))
                                {
                                    AddingItem iA = new AddingItem();
                                    iA.DishName = item.name;
                                    iA.index++;
                                    if (firstList.IndexOf(iA) == -1)
                                    {
                                        firstList.Add(iA);
                                    }
                                }
                            }
                        }
                    }
                }
                IEnumerable <AddingItem> topFiveItems = firstList.OrderByDescending(x => x.index).Take(5);

                var reply = MessageFactory.Text("");
                List <CardAction> actions = new List <CardAction>();
                int skippedInt            = 0;

                foreach (var item in topFiveItems)
                {
                    actions.Add(new CardAction()
                    {
                        Title = item.DishName, Type = ActionTypes.PostBack, Value = "1qq1_" + item.DishName + "_" + turnContext.Activity.Text
                    });
                }
                actions.Add((new CardAction()
                {
                    Title = "Następne", Type = ActionTypes.PostBack, Value = +(skippedInt + 1)
                }));
                actions.Add((new CardAction()
                {
                    Title = "Wróć", Type = ActionTypes.PostBack, Value = +(skippedInt + 1)
                }));
                reply.SuggestedActions = new SuggestedActions()
                {
                    Actions = actions
                };
                if (topFiveItems.Count() > 0)
                {
                    await turnContext.SendActivityAsync(reply, cancellationToken);

                    return(true);
                }
                else
                {
                    return(false);
                }
            }
            catch (Exception ex)
            {
                return(true);
            }
        }
 /// <inheritdoc />
 public void Insert(int index, T item)
 {
     AddingItem?.Invoke(item);
     ListAction(x => x.Insert(index, item));
     AddedItem?.Invoke(item);
 }
 /// <inheritdoc />
 public void Add(T item)
 {
     AddingItem?.Invoke(item);
     ListAction(x => x.Add(item));
     AddedItem?.Invoke(item);
 }
 /// <summary>
 ///
 /// </summary>
 /// <param name="e"></param>
 private void OnAddingItemEvent(TaskDescriptionEventArgs e)
 {
     AddingItem?.Invoke(this, e);
 }