private async Task AddExpenseVoiceAsync(string text)
        {
            IsBusy = true;

            try
            {
                Expense exp = CreateExpenseFromText(text);

                if (exp != null)
                {
                    if (await _expenseTrackerService.SaveExpenseAsync(exp))
                    {
                        await ExecuteLoadExpensesAsync();
                    }
                    else
                    {
                        await base.ShowErrorMessageAsync("Error creating Expense on server.");
                    }
                }
                else
                {
                    await base.ShowErrorMessageAsync("Error creating Expense from text spoken.");
                }
            }
            catch (Exception ex)
            {
                _telemetry.LogError("ExecuteLoadExpensesAsync error", ex);
                await base.ShowErrorMessageAsync("Error creating Expense on server.");
            }
            finally
            {
                IsBusy = false;
            }
        }
Beispiel #2
0
        public async Task ExecuteSaveAsync()
        {
            // Prevent multiple tap on save button
            _tapCount += 1;
            if (_tapCount > 1)
            {
                _tapCount = 0;
                return;
            }


            IsBusy = true;

            try
            {
                Expense exp = new Expense();
                exp.Date = this.Date;

                if (this.CategorySelectedItem == null)
                {
                    await base.ShowErrorMessageAsync("Select a category.");

                    return;
                }
                exp.Category = this.CategorySelectedItem;

                if (this.Value == 0)
                {
                    await base.ShowErrorMessageAsync("Inform a value.");

                    return;
                }
                exp.Value = this.Value;

                if (this.PaymentTypeSelectedItem == null)
                {
                    await base.ShowErrorMessageAsync("Select a payment type.");

                    return;
                }
                exp.PaymentType = this.PaymentTypeSelectedItem;


                if (string.IsNullOrEmpty(this.Description))
                {
                    exp.Description = exp.Category;
                }
                else
                {
                    exp.Description = this.Description;
                }


                exp.UserName = _userSettings.GetEmail();


                if (await _expenseTrackerService.SaveExpenseAsync(exp))
                {
                    await NavigateToExpenseList(exp);
                }
                else
                {
                    await base.ShowErrorMessageAsync("Error creating Expense on server.");
                }
            }
            catch (Exception ex)
            {
                _telemetry.LogError("ExecuteLoadExpensesAsync error", ex);
                await base.ShowErrorMessageAsync("Error creating Expense on server.");
            }
            finally
            {
                IsBusy = false;
            }
        }