public void Init(bool isEdit)
        {
            IsEdit = isEdit;

            if (!IsEdit)
            {
                SelectedAccount = new Account();
            }
        }
        private void GoToPaymentViewModelOverView(Account account)
        {
            if (account == null)
            {
                return;
            }

            accountRepository.Selected = account;
            navigationService.NavigateTo(NavigationConstants.PAYMENT_LIST_VIEW);
        }
        public void DeleteAssociatedPaymentsFromDatabase(Account account)
        {
            if (paymentRepository.Data == null)
            {
                return;
            }

            var paymentToDelete = paymentRepository.GetRelatedPayments(account);

            foreach (var payment in paymentToDelete)
            {
                paymentRepository.Delete(payment);
            }
        }
        /// <summary>
        ///     Save a new account or update an existing one.
        /// </summary>
        /// <param name="account">accountToDelete to save</param>
        public void Save(Account account)
        {
            if (string.IsNullOrWhiteSpace(account.Name))
            {
                account.Name = Strings.NoNamePlaceholderLabel;
            }

            if (account.Id == 0)
            {
                data.Add(account);
                dataAccess.Add(account);
            }
            else
            {
                dataAccess.Update(account);
            }
        }
 /// <summary>
 ///     returns a list with payments who are related to this account
 /// </summary>
 /// <param name="account">account to search the related</param>
 /// <returns>List of payments</returns>
 public IEnumerable<PaymentViewModel> GetRelatedPayments(Account account)
 {
     return Data.Where(x => x.ChargedAccount.Id == account.Id
                            || x.TargetAccount.Id == account.Id)
         .OrderByDescending(x => x.Date)
         .ToList();
 }
        private async void Delete(Account item)
        {
            if (item == null)
            {
                return;
            }

            if (await dialogService.ShowConfirmMessage(Strings.DeleteTitle, Strings.DeleteAccountConfirmationMessage))
            {
                accountRepository.Delete(item);
            }
        }
 private void EditAccount(Account account)
 {
     navigationService.NavigateTo(NavigationConstants.MODIFY_ACCOUNT_VIEW, account);
 }
        /// <summary>
        ///     Init the view. Is executed after the constructor call
        /// </summary>
        /// <param name="type">Type of the PaymentViewModel.</param>
        /// <param name="isEdit">Weather the PaymentViewModel is in edit mode or not.</param>
        public void Init(PaymentType type, bool isEdit = false)
        {
            IsEdit = isEdit;
            IsEndless = true;

            amount = 0;

            if (IsEdit)
            {
                PrepareEdit();
            }
            else
            {
                PrepareDefault(type);
            }

            AccountBeforeEdit = SelectedPayment.ChargedAccount;
        }
 public AccountViewModel(Account account)
 {
     this.account = account;
 }
 /// <summary>
 ///     Deletes the passed account and removes it from cache
 /// </summary>
 /// <param name="accountToDelete">accountToDelete to delete</param>
 public void Delete(Account accountToDelete)
 {
     data.Remove(accountToDelete);
     dataAccess.Delete(accountToDelete);
 }
 private Func<PaymentViewModel, Account> GetChargedAccountFunc(Account account)
 {
     Func<PaymentViewModel, Account> accountFunc =
         trans => Data.FirstOrDefault(x => x.Id == account.Id);
     return accountFunc;
 }
        /// <summary>
        ///     Removes the PaymentViewModel Amount from the selected account
        /// </summary>
        /// <param name="paymentVm">PaymentViewModel to remove.</param>
        /// <param name="account">Account to remove the amount from.</param>
        public void RemovePaymentAmount(PaymentViewModel paymentVm, Account account)
        {
            if (!paymentVm.IsCleared)
            {
                return;
            }

            PrehandleRemoveIfTransfer(paymentVm);

            Func<double, double> amountFunc = x =>
                paymentVm.Type == PaymentType.Income
                    ? -x
                    : x;

            HandlePaymentViewModelAmount(paymentVm, amountFunc, GetChargedAccountFunc(account));
        }
 /// <summary>
 ///     Initializes the ViewModel
 /// </summary>
 /// <param name="isEdit">Indicates if the view is in edit or create mode.</param>
 /// <param name="selectedAccountId">if in edit mode, this is the selected account.</param>
 public void Init(bool isEdit, int selectedAccountId)
 {
     IsEdit = isEdit;
     SelectedAccount = selectedAccountId != 0
         ? accountRepository.Data.First(x => x.Id == selectedAccountId)
         : new Account();
 }