Esempio n. 1
0
        /// <summary>
        /// Get source collection of items for serializing
        /// </summary>
        /// <returns>Collection of items</returns>
        protected override ObservableCollection <T> GetFinalCollection()
        {
            foreach (var item in ItemsSource.Where(x => !ItemsSourceAll.Contains(x)))
            {
                if (ItemsSourceAll.FirstOrDefault(x => x.ID == item.ID) != null)
                {
                    ItemsSourceAll[ItemsSourceAll.IndexOf(ItemsSourceAll.FirstOrDefault(x => x.ID == item.ID))] = item;
                }
                else
                {
                    ItemsSourceAll.Add(item);
                }
            }

            bool ClearSecured = CustomSettings.IsUserLogged;

            var ToRemove = ItemsSourceAll.Where(x => (x.Secured == ClearSecured || (x.Secured != ClearSecured && ClearSecured == true))).Where(x => !ItemsSource.Select(y => y.ID).ToList().Contains(x.ID)).Select(x => x.ID).ToList();

            foreach (var item in ToRemove)
            {
                ItemsSourceAll.Remove(ItemsSourceAll.FirstOrDefault(x => x.ID == item));
            }

            return(ItemsSourceAll);
        }
Esempio n. 2
0
        /// <summary>
        /// Add range of items into collection and save it
        /// </summary>
        /// <param name="itemList">List of imported items</param>
        /// <param name="reloadSource">Reload source if null</param>
        /// <returns>True, if action was succesfull</returns>
        public virtual async Task <bool> AddItemRange(List <T> itemList, bool reloadSource = true, bool CheckItems = true)
        {
            bool res = true;

            if (!reloadSource && ItemsSource == null)
            {
                ItemsSource    = new ObservableCollection <T>();
                ItemsSourceAll = new ObservableCollection <T>();
            }

            foreach (var item in itemList)
            {
                if (CheckItems)
                {
                    res &= await AddItem(item, false);
                }
                else
                {
                    ItemsSourceAll.Add(item);
                    ItemsSource.Add(item);
                }
            }

            await SaveDataAsync();

            return(res);
        }
Esempio n. 3
0
        /// <summary>
        /// Add item into collection and save it, when required
        /// </summary>
        /// <param name="item">New item</param>
        /// <param name="saveData">Save data after adding item into collection</param>
        /// <returns>True, if action was succesfull</returns>
        public virtual async Task <bool> AddItem(T item, bool saveData = true)
        {
            T NewItem = item;

            NewItem.Encrypted = false;
            NewItem.ManagerID = ID;

            if (ItemsSource == null)
            {
                await GetItemsAsync();
            }

            if (NewItem.ID == -1)
            {
                if (ItemsSource != null)
                {
                    NewItem.ID = GetID();
                }
                else
                {
                    NewItem.ID = 0;
                }

                ItemsSource.Add(NewItem);
            }
            else
            {
                int Index = ItemsSource.IndexOf(ItemsSource.FirstOrDefault(x => x.ID == NewItem.ID));
                if (Index == -1)
                {
                    Index = IndexOfItem(NewItem);
                }

                if (Index == -1)
                {
                    return(false);
                }

                ItemsSource.RemoveAt(Index);

                ItemsSource.Insert(Index, NewItem);
            }

            if (!AddItemAdditionCheck(item))
            {
                return(false);
            }

            if (saveData)
            {
                await SaveDataAsync();
            }
            else
            {
                ItemsSourceAll.Add(NewItem);
            }

            return(true);
        }
Esempio n. 4
0
        /// <summary>
        /// Return list of names of items
        /// </summary>
        /// <returns>List of names of items</returns>
        public virtual async Task <List <string> > GetItemsNameList()
        {
            if ((CustomSettings.IsUserLogged && ItemsSource.Count != ItemsSourceAll.Count) || (!CustomSettings.IsUserLogged && ItemsSource.Count == ItemsSourceAll.Count && ItemsSourceAll.Count(x => x.Secured) > 0))
            {
                await GetItemsAsync(true);
            }

            return(ItemsSource?.Select(x => x.Name).ToList() ?? new List <string>());
        }