async Task Save()
        {
            if (String.IsNullOrWhiteSpace(Credit.creditID))
            {
                await _pageService.DisplayAlert("Error", "Please enter CreditID", "OK");

                return;
            }
            if (Credit.id == 0)
            {
                await _creditStore.AddCredit(Credit);

                CreditAdded?.Invoke(this, Credit);
            }
            else
            {
                await _creditStore.UpdateCredit(Credit);

                CreditUpdated?.Invoke(this, Credit);
            }
            await _pageService.PopModalAsync();
        }
Exemplo n.º 2
0
        /// <summary>
        /// Add a credit.
        /// </summary>
        /// <param name="accountGuid">GUID of the account.</param>
        /// <param name="amount">Amount of the credit (zero or greater).</param>
        /// <param name="isCommitted">Indicates if the transaction has already been commited to the current committed balance.</param>
        /// <param name="summarizedBy">GUID of the entry that summarized this entry.</param>
        /// <param name="notes">Notes for the transaction.</param>
        /// <returns>String containing the GUID of the newly-created entry.</returns>
        public string AddCredit(string accountGuid, decimal amount, string notes = null, string summarizedBy = null, bool isCommitted = false)
        {
            if (String.IsNullOrEmpty(accountGuid))
            {
                throw new ArgumentNullException(nameof(accountGuid));
            }
            if (amount < 0)
            {
                throw new ArgumentException("Amount must be zero or greater.");
            }

            Account a = GetAccountByGuid(accountGuid);

            if (a == null)
            {
                throw new KeyNotFoundException("Unable to find account with GUID " + accountGuid + ".");
            }

            Entry entry = null;

            try
            {
                LockAccount(accountGuid);
                entry = new Entry(accountGuid, EntryType.Credit, amount, notes, summarizedBy, isCommitted);
                entry = _ORM.Insert <Entry>(entry);
                return(entry.GUID);
            }
            finally
            {
                UnlockAccount(accountGuid);
                if (entry != null)
                {
                    Task.Run(() => CreditAdded?.Invoke(this, new EntryEventArgs(a, entry)));
                }
            }
        }
Exemplo n.º 3
0
 private void When(CreditAdded creditAdded)
 {
     _credit = _credit.Add(creditAdded.Credit);
 }