private void SaveCommandExecute(object obj)
        {
            purchase.Name = purchase.Name.Trim();

            Task.Factory.StartNew(async () => 
            {
                var pName = purchase.Name;
                var result = await StoreService.AddPurchase(purchase);
                if (result != null)
                {
                    int tId = Thread.CurrentThread.ManagedThreadId;
                    logger.Info("Purchase saved: {0}", pName);
                    Status.Post("Покупка \"{0}\" збережена", pName);

                    purchase = new Purchase 
                    {
                        Type = purchase.Type,
                        SubType = purchase.SubType,
                        Date = purchase.Date
                    };

                    CleanInputFields();
                }
                else
                {
                    logger.Warn("Purchase not saved: {0}", pName);
                    Status.Post("Помилка: покупка \"{0}\" не збережена", pName);
                }
            });
            
        }
        void SearchResultList_ListChanged(object sender, ListChangedEventArgs e)
        {
            Purchase purchase;

            switch (e.ListChangedType)
            {
            case ListChangedType.ItemChanged:
                purchase = searchResultList.ElementAt(e.NewIndex);
                var referencePurchase = SearchResultListBackup.ElementAt(e.NewIndex);
                if (!RecalculatePurchase(purchase, referencePurchase))
                {
                    Task.Factory.StartNew(async() =>
                    {
                        if ((await StoreService.AddPurchase(purchase)) != null)
                        {
                            Status.Post("Зміни до покупки \"{0}\" збережені", purchase.Name);
                        }
                    });
                }
                break;

            case ListChangedType.ItemDeleted:
                purchase = SearchResultListBackup.ElementAt(e.NewIndex);
                var result = MessageBox.Show(
                    string.Format("Видалити запис \"{0}\"?", purchase.Name),
                    "Видалення запису",
                    MessageBoxButtons.OKCancel,
                    MessageBoxIcon.Question);
                Task.Factory.StartNew(async() =>
                {
                    if (result == DialogResult.OK)
                    {
                        if (await StoreService.RemoveProduct(purchase.Id))
                        {
                            BackupSearchList(SearchResultList);
                            Status.Post("Покупка \"{0}\" видалена", purchase.Name);
                        }
                        else
                        {
                            Status.Post("Помилка: покупка \"{0}\" не видалена", purchase.Name);
                        }
                    }
                });

                break;

            default:
                break;
            }
        }
 private void CalculateCommandExecuted(object obj)
 {
     if (DataService.PerformCalculation(editingPurchase, actualCalculationTarget))
     {
         OnPropertyChanged(() => SearchResultList);
         BackupSearchList(SearchResultList);
         //SearchResultList = new BindingList<Purchase>(SearchResultListBackup);
         Task.Factory.StartNew(async() =>
         {
             if ((await StoreService.AddPurchase(editingPurchase)) != null)
             {
                 Status.Post("Зміни до покупки \"{0}\" збережені", editingPurchase.Name);
             }
         });
     }
     else
     {
         SearchResultList = new BindingList <Purchase>(SearchResultListBackup);
     }
     ShowDataCalcPopup = false;
 }