public void CompleteToggled(GroupItemViewModel givm)
        {
            Group = ListVM.ActiveGroup.Group;
            var purch = Group.PurchasesList.FirstOrDefault(p => p.Name == givm.VaiableName);

            Group.PurchasesList[Group.PurchasesList.IndexOf(purch)] = givm.Purchase;
            App.Database.SaveGroupItem(Group);
        }
        private void SaveGroupItem(object obj)
        {
            Group = ListVM.ActiveGroup.Group;
            GroupItemViewModel groupItem = obj as GroupItemViewModel;

            if (groupItem != null && groupItem.isValid)
            {
                if (string.IsNullOrEmpty(groupItem.VaiableName))
                {
                    if (Group.PurchasesList == null)
                    {
                        Group.PurchasesList = new List <Purchase>();
                        Purchases           = new List <GroupItemViewModel>();
                    }
                    if (Group.PurchasesList.Any(p => p.Name.ToLower() == groupItem.Name.ToLower()))
                    {
                        ListVM.Main.DisplayAlert("Внимание!", "Такой элемент уже имеется в списке.", "Ok");
                        return;
                    }
                    var purch = new Purchase
                    {
                        Id        = groupItem.Purchase.Id,
                        Name      = groupItem.Purchase.Name,
                        Count     = groupItem.Purchase.Count,
                        Units     = groupItem.Purchase.Units,
                        Completed = groupItem.Purchase.Completed
                    };
                    Group.PurchasesList.Add(purch);                        //добавляет покупку в группу
                    Purchases.Add(ListVM.PurchasesToGIVMConverter(purch)); //Добавляет IVM в текущий список GVM
                }
                else
                {
                    if (groupItem.Name.Length < 1)
                    {
                        ListVM.Main.DisplayAlert("Внимание!", "Название не может быть пустым", "Ok");
                        return;
                    }
                    var purch = Group.PurchasesList.FirstOrDefault(p => p.Name == groupItem.VaiableName);
                    Group.PurchasesList[Group.PurchasesList.IndexOf(purch)] = groupItem.Purchase;
                }

                App.Database.SaveGroupItem(Group);//сохраняет эту группу в БД
                if (needToSave)
                {
                    ListVM.Back();
                    ListVM.ActiveGroup           = ListVM.GroupsList[ListVM.GroupsList.Count - 1];
                    ListVM.ActiveGroup.Purchases = new List <GroupItemViewModel>();
                    foreach (var groupIVM in ListVM.ActiveGroup.Group.PurchasesList)
                    {
                        ListVM.ActiveGroup.Purchases.Add(ListVM.PurchasesToGIVMConverter(groupIVM));
                    }
                }
            }
            ListVM.BackToList();
        }
        void DeleteItem(GroupItemViewModel item)
        {
            var purch = ListVM.ActiveGroup.Group.PurchasesList != null?ListVM.ActiveGroup.Group.PurchasesList.FirstOrDefault(p => p.Name == item.Name) : null;

            var givm = ListVM.ActiveGroup.Purchases != null?ListVM.ActiveGroup.Purchases.FirstOrDefault(p => p.Name == item.Name) : null;

            if (purch != null && givm != null)
            {
                ListVM.ActiveGroup.Group.PurchasesList.Remove(purch);
                ListVM.ActiveGroup.Purchases.Remove(givm);
                App.Database.SaveGroupItem(ListVM.ActiveGroup.Group);
            }
            ListVM.BackToList();
        }