Пример #1
0
        public async Task <bool> AddAsync([FromBody] AddWordDto dto)
        {
            var result = await _wordService.UpdateAsNewWordAsync(dto);

            if (result)
            {
                _cachedService.Clear();
            }
            return(result);
        }
Пример #2
0
        private bool DatabaseVerification()
        {
            var dbHelper = new DatabaseBackupHelper();
            int applicationDatabaseVersion = 2;
            int currentDatabaseVersion     = ConfigurationManager.GetValueOrDefault <int>(ConfigurationKeys.DatabaseVersion);

            if (currentDatabaseVersion == applicationDatabaseVersion)
            {
                dbHelper.CreateBackup();
                return(true);
            }
            try
            {
                dbHelper.CreateBackup();
                DatabaseUpdateHelper.UpdateIfNeeded(Database, currentDatabaseVersion);
                ConfigurationManager.Clear();
                CachedService.Clear();
                return(true);
            }
            catch (Exception ex)
            {
                var message = new StringBuilder();
                message.AppendLine(string.Format("Błąd aktualizacji bazy danych do wersji {0}.", applicationDatabaseVersion));
                message.AppendLine();
                message.AppendLine(ex.Message);
                ShowMessage(message.ToString(), () => { TryClose(); }, null, MessageBoxButton.OK, MessageBoxImage.Error);
                return(false);
            }
        }
Пример #3
0
        public void AddNewCashFlowGroup()
        {
            using (var tx = Database.GetTransaction())
            {
                int maxPosition = 1;
                if (Database.Count <CashFlowGroup>() > 0)
                {
                    maxPosition = Database.ExecuteScalar <int>("SELECT MAX(Position) FROM CashFlowGroup");
                }
                var cashFlowGroup = new CashFlowGroup
                {
                    Name        = NewGroupName,
                    Description = NewGroupDescription,
                    Position    = maxPosition + 1,
                };

                Database.Save(cashFlowGroup);
                tx.Complete();
                _cashFlowGroups.Add(cashFlowGroup);
            }
            CachedService.Clear();
            NewGroupName        = string.Empty;
            NewGroupDescription = string.Empty;
            //LoadData();
            IsNewGroupNameFocused = false;
            IsNewGroupNameFocused = true;
            NotifyOfPropertyChange(() => CashFlowGroups);
        }
Пример #4
0
        public void DeleteCashFlowType(CashFlow cashFlow, bool omitConfirmation)
        {
            if (!omitConfirmation)
            {
                var hasBudgetPlansDefined = Database.ExecuteScalar <int>(PetaPoco.Sql.Builder
                                                                         .Select("COUNT(*)")
                                                                         .From("BudgetPlan")
                                                                         .Where("CashFlowId = @0", cashFlow.Id)) > 0;

                var hasExpensesDefined = Database.ExecuteScalar <int>(PetaPoco.Sql.Builder
                                                                      .Select("COUNT(*)")
                                                                      .From("Expense")
                                                                      .Where("CashFlowId = @0", cashFlow.Id)) > 0;

                if (hasBudgetPlansDefined || hasExpensesDefined)
                {
                    Shell.ShowDialog <CashFlowDeleteConfirmationViewModel>(new { CashFlow = cashFlow }, () => DeleteCashFlowType(cashFlow, true), null);
                    return;
                }
            }

            using (var tx = Database.GetTransaction())
            {
                Database.Delete <BudgetPlan>("WHERE CashFlowId = @0", cashFlow.Id);
                Database.Delete <SavingValue>("WHERE ExpenseId IN (SELECT [Expense].Id FROM [Expense] WHERE CashFlowId = @0)", cashFlow.Id);
                Database.Delete <Expense>("WHERE CashFlowId = @0", cashFlow.Id);
                Database.Delete <CashFlow>(cashFlow);
                tx.Complete();
                _cashFlows.Remove(cashFlow);
            }
            CachedService.Clear();

            NotifyOfPropertyChange(() => CashFlows);
            //LoadData();
        }
Пример #5
0
        private void ReorderCashFlowGroup(CashFlowGroup itemToReorder, int placeAtIndex)
        {
            var itemsCopy          = CashFlowGroups.ToList();
            var itemToReorderIndex = itemsCopy.IndexOf(itemToReorder);

            if (itemToReorderIndex < 0 || itemToReorderIndex == placeAtIndex)
            {
                return;
            }
            SuppressEvent = true;

            itemsCopy.Insert(placeAtIndex, itemToReorder);
            if (placeAtIndex > itemToReorderIndex)
            {
                itemsCopy.RemoveAt(itemToReorderIndex);
            }
            else
            {
                itemsCopy.RemoveAt(itemToReorderIndex + 1);
            }

            int position = 1;

            itemsCopy.ForEach(x => x.Position = position++);
            using (var tx = Database.GetTransaction())
            {
                Database.SaveAll(itemsCopy);
                tx.Complete();
            }
            NotifyOfPropertyChange(() => CashFlowGroups);
            CachedService.Clear(CachedServiceKeys.AllCashFlowGroups);
            SuppressEvent = false;
        }
Пример #6
0
        protected void OnSavingPropertyChanged(object sender, PropertyChangedEventArgs e)
        {
            if (sender is Entity)
            {
                switch (e.PropertyName)
                {
                case "Name":
                case "Description":
                case "Value":
                case "StartingBalance":
                    var saving      = sender as Saving;
                    var savingValue = sender as SavingValue;
                    if (saving != null)
                    {
                        UpdateSaving(saving, true);
                    }

                    if (savingValue != null)
                    {
                        Save(savingValue);
                        savingValue.Saving.Refresh();
                        CachedService.Clear(CachedServiceKeys.AllSavings);
                        CachedService.Clear(CachedServiceKeys.AllIncomes);
                    }
                    break;
                }
            }
        }
Пример #7
0
        public CashFlowTypesViewModel(IShellViewModel shell, IDatabase database, IConfigurationManager configuration, ICachedService cashedService, IEventAggregator eventAggregator)
            : base(shell, database, configuration, cashedService, eventAggregator)
        {
            SuppressEvent = false;
            _cashFlows    = new BindableCollectionExt <CashFlow>();
            _cashFlows.PropertyChanged += (s, e) =>
            {
                OnPropertyChanged(s, e);
                CachedService.Clear(CachedServiceKeys.AllCashFlows);
            };

            _cashFlowGroups = new BindableCollectionExt <CashFlowGroup>();
            _cashFlowGroups.PropertyChanged += (s, e) =>
            {
                if (SuppressEvent == true)
                {
                    return;
                }
                OnPropertyChanged(s, e);

                CachedService.Clear(CachedServiceKeys.AllCashFlowGroups);
                CachedService.Clear(CachedServiceKeys.AllCashFlows);
                var cashFlowGroup = s as CashFlowGroup;
                _cashFlows.Where(x => x.CashFlowGroupId == cashFlowGroup.Id)
                .ForEach(x => x.Group = cashFlowGroup);
                NewCashFlowGroup      = null;
                NewCashFlowGroup      = CashFlowGroups.First();
            };
        }
Пример #8
0
 public void RemoveSavingValue(SavingValue savingValue)
 {
     using (var tx = Database.GetTransaction())
     {
         Database.Delete(savingValue);
         tx.Complete();
         CachedService.Clear(CachedServiceKeys.AllSavings);
     }
     LoadSavingsData();
 }
Пример #9
0
 private void DeleteSaving(Saving saving)
 {
     using (var tx = Database.GetTransaction())
     {
         Database.Delete(saving.CashFlow);
         Database.Delete(saving);
         tx.Complete();
         CachedService.Clear(CachedServiceKeys.AllSavings);
         CachedService.Clear(CachedServiceKeys.AllCashFlows);
     }
 }
Пример #10
0
        public void AddIncome()
        {
            string incomeDefaultName = CreateUniqueName("Dochody", Incomes.Select(x => x.Name).ToList());
            var    income            = new Income
            {
                Name = incomeDefaultName,
            };

            Save(income);
            CachedService.Clear(CachedServiceKeys.AllIncomes);
            LoadIncomesData();
        }
Пример #11
0
 private void DeleteRevenue(Entity entity)
 {
     Delete(entity);
     if (entity is IncomeValue)
     {
         CachedService.Clear(CachedServiceKeys.AllIncomes);
     }
     if (entity is SavingValue)
     {
         CachedService.Clear(CachedServiceKeys.AllSavings);
     }
     RefreshSummaryValues();
 }
Пример #12
0
 private void SaveEquation(BudgetCalculatorEquation budgetCalculatorEquation)
 {
     using (var tx = Database.GetTransaction())
     {
         Database.Save(budgetCalculatorEquation);
         var itemsToDelete = EquationToEdit.Items.Where(x => !budgetCalculatorEquation.Items.Any(y => x.Id == y.Id));
         itemsToDelete.ForEach(x => Database.Delete(x));
         Database.SaveAll(budgetCalculatorEquation.Items);
         tx.Complete();
         CachedService.Clear(CachedServiceKeys.AllEquations);
         PublishRefreshRequest(budgetCalculatorEquation);
     }
 }
Пример #13
0
 private void DeleteEquation(BudgetCalculatorEquation equation)
 {
     using (var tx = Database.GetTransaction())
     {
         // delete all related equations
         var equationsDeletedCounter = Database.Execute("DELETE FROM BudgetCalculatorEquation WHERE Id IN (SELECT BudgetCalculatorEquationId FROM BudgetCalculatorItem WHERE ForeignId = @0 AND ValueTypeName = 'CalculatorEquationValue')", equation.Id);
         Database.Execute("DELETE FROM BudgetCalculatorItem WHERE ForeignId = @0 AND ValueTypeName = 'CalculatorEquationValue'", equation.Id);
         Database.Execute("DELETE FROM BudgetCalculatorItem WHERE BudgetCalculatorEquationId = @0", equation.Id);
         Database.Delete(equation);
         tx.Complete();
         CachedService.Clear(CachedServiceKeys.AllEquations);
         PublishRefreshRequest(equation);
     }
 }
Пример #14
0
        private void LoadIncomesData()
        {
            Incomes.Clear();
            var incomesList = CachedService.GetAllIncomes();

            incomesList.ForEach(x =>
            {
                Incomes.Add(x);
                x.PropertyChanged += (s, e) =>
                {
                    Save(x);
                    CachedService.Clear(CachedServiceKeys.AllIncomes);
                };
            });
        }
Пример #15
0
 private void UpdateSaving(Saving saving, bool updateCashFlow = false)
 {
     using (var tx = Database.GetTransaction())
     {
         Database.Update(saving);
         if (updateCashFlow)
         {
             saving.CashFlow.Name = saving.Name;
             Database.Update(saving.CashFlow);
         }
         tx.Complete();
         CachedService.Clear(CachedServiceKeys.AllSavings);
         CachedService.Clear(CachedServiceKeys.AllCashFlows);
     }
 }
Пример #16
0
        private void SwapPositions(CashFlowGroup first, CashFlowGroup secound)
        {
            first.IsNotifying   = false;
            secound.IsNotifying = false;
            var firstPosition = first.Position;

            first.Position      = secound.Position;
            secound.Position    = firstPosition;
            first.IsNotifying   = true;
            secound.IsNotifying = true;

            base.Save(first);
            base.Save(secound);
            CachedService.Clear();
            NotifyOfPropertyChange(() => CashFlowGroups);
        }
Пример #17
0
        public void DeleteCashFlowGroup(CashFlowGroup cashFlowGroup, bool omitConfirmation)
        {
            if (!omitConfirmation)
            {
                var hasCashFlowsDefined = Database.ExecuteScalar <int>(PetaPoco.Sql.Builder
                                                                       .Select("COUNT(*)")
                                                                       .From("CashFlow")
                                                                       .Where("CashFlowGroupId = @0", cashFlowGroup.Id)) > 0;

                var hasBudgetPlansDefined = Database.ExecuteScalar <int>(PetaPoco.Sql.Builder
                                                                         .Select("COUNT(*)")
                                                                         .From("BudgetPlan")
                                                                         .Where("CashFlowId IN (SELECT [CashFlow].Id FROM [CashFlow] WHERE CashFlowGroupId = @0)", cashFlowGroup.Id)) > 0;

                var hasExpensesDefined = Database.ExecuteScalar <int>(PetaPoco.Sql.Builder
                                                                      .Select("COUNT(*)")
                                                                      .From("Expense")
                                                                      .Where("CashFlowId IN (SELECT [CashFlow].Id FROM [CashFlow] WHERE CashFlowGroupId = @0)", cashFlowGroup.Id)) > 0;

                if (hasCashFlowsDefined || hasBudgetPlansDefined || hasExpensesDefined)
                {
                    Shell.ShowDialog <CashFlowGroupDeleteConfirmationViewModel>(new { CashFlowGroup = cashFlowGroup }, () => DeleteCashFlowGroup(cashFlowGroup, true), null);
                    return;
                }
            }

            using (var tx = Database.GetTransaction())
            {
                Database.Delete(cashFlowGroup);
                tx.Complete();
                _cashFlowGroups.IsNotifying = false;
                _cashFlowGroups.Remove(cashFlowGroup);
                _cashFlowGroups.IsNotifying = true;
            }

            NewCashFlowGroup = _cashFlowGroups.First();
            CachedService.Clear();
            _cashFlows.IsNotifying = false;
            NotifyOfPropertyChange(() => CashFlowGroups);
            LoadCashFlows();
        }
Пример #18
0
        private void Save(Expense expense)
        {
            Diagnostics.Start();
            Diagnostics.Start("Database operations");
            using (var tx = Database.GetTransaction())
            {
                int savingsDeletedCounter = 0;
                Database.Save(expense);
                if (expense.Flow.Saving == null)
                {
                    savingsDeletedCounter = Database.Delete <SavingValue>("WHERE ExpenseId = @0", expense.Id);
                }

                if (expense.SavingValue != null)
                {
                    expense.SavingValue.UpdateDescription();
                    Database.Save(expense.SavingValue);
                    int savingValuesCount = Database.ExecuteScalar <int>(PetaPoco.Sql.Builder
                                                                         .Select("COUNT(*)")
                                                                         .From("SavingValue")
                                                                         .Where("ExpenseId = @0", expense.Id));
                    if (savingValuesCount > 1)
                    {
                        savingsDeletedCounter =
                            Database.Delete <SavingValue>("WHERE ExpenseId = @0 AND SavingId <> @1", expense.Id, expense.SavingValue.SavingId);
                    }
                }

                tx.Complete();
                CachedService.Clear(CachedServiceKeys.AllSavings);
            }
            Diagnostics.Stop();

            NotifyOfPropertyChange(() => TotalExpensesValue);
            PublishRefreshRequest(expense);
            Diagnostics.Stop();
        }
Пример #19
0
        private void ReorderCashFlowGroup(BudgetCalculatorEquation itemToReorder, int placeAtIndex)
        {
            //var itemsCopy = Equations.ToList();
            var itemToReorderIndex = Equations.IndexOf(itemToReorder);

            if (itemToReorderIndex < 0 || itemToReorderIndex == placeAtIndex)
            {
                return;
            }
            Equations.IsNotifying = false;
            SuppressEvent         = true;

            Equations.Insert(placeAtIndex, itemToReorder);
            if (placeAtIndex > itemToReorderIndex)
            {
                Equations.RemoveAt(itemToReorderIndex);
            }
            else
            {
                Equations.RemoveAt(itemToReorderIndex + 1);
            }
            int position = 1;

            Equations.ForEach(x => x.Position = position++);
            using (var tx = Database.GetTransaction())
            {
                Database.SaveAll(Equations);
                tx.Complete();
            }
            Equations.IsNotifying = true;

            Equations.Refresh();
            NotifyOfPropertyChange(() => AvaiableEquations);
            CachedService.Clear(CachedServiceKeys.AllEquations);
            SuppressEvent = false;
        }
Пример #20
0
 public void RemoveIncome(Income income, bool omitConfirmation)
 {
     if (!omitConfirmation)
     {
         var hasIncomeValuesDefined = Database.ExecuteScalar <int>(PetaPoco.Sql.Builder
                                                                   .Select("COUNT(*)")
                                                                   .From("IncomeValue")
                                                                   .Where("IncomeId = @0", income.Id)) > 0;
         if (hasIncomeValuesDefined)
         {
             var message = string.Format("Dochód \"{0}\" jest już używany w budżecie. Usunięcie go spowoduje usunięcie jego wystąpień we wszystkich budżetach.\r\n\r\nCzy chcesz kontynuować?", income.Name);
             Shell.ShowMessage(message, () => RemoveIncome(income, true), null);
             return;
         }
     }
     using (var tx = Database.GetTransaction())
     {
         Database.Delete <IncomeValue>("WHERE IncomeId = @0", income.Id);
         Database.Delete(income);
         tx.Complete();
     }
     CachedService.Clear(CachedServiceKeys.AllIncomes);
     LoadIncomesData();
 }
Пример #21
0
        public void AddNewCashFlowType()
        {
            using (var tx = Database.GetTransaction())
            {
                var cashFlow = new CashFlow
                {
                    Name        = NewName,
                    Description = NewDescription,
                    Group       = NewCashFlowGroup,
                };

                Database.Save(cashFlow);
                tx.Complete();
                _cashFlows.Add(cashFlow);
            }
            CachedService.Clear();
            NewName          = string.Empty;
            NewDescription   = string.Empty;
            NewCashFlowGroup = CashFlowGroups.First();
            //LoadData();
            IsNewNameFocused = false;
            IsNewNameFocused = true;
            NotifyOfPropertyChange(() => CashFlows);
        }
Пример #22
0
 protected override void Save(Entity entity)
 {
     base.Save(entity);
     CachedService.Clear();
 }
Пример #23
0
 public IActionResult Add([FromForm] WordAndExampleDto data)
 {
     _wordService.AddWordAndExampleAsync(data);
     _cachedService.Clear();
     return(Redirect("Index"));
 }
Пример #24
0
 public bool Add(WordAndExampleDto data)
 {
     _wordService.AddWordAndExampleAsync(data);
     _cachedService.Clear();
     return(true);
 }