Beispiel #1
0
        /// <summary>
        /// save current expense
        /// </summary>
        void SaveExpense()
        {
            CurrentExpense.Description  = expenseDescription.Text;
            CurrentExpense.Cost         = expenseAmount.Text.ToDecimal(CultureInfo.InvariantCulture);
            CurrentExpense.AssignmentId = Assignment.Id;

            var task = expenseViewModel.SaveExpenseAsync(Assignment, CurrentExpense);

            if (expenseViewModel.Photo != null)
            {
                task = task.ContinueWith(_ => {
                    expenseViewModel.Photo.ExpenseId = CurrentExpense.Id;
                    expenseViewModel.Photo.Image     = imageBitmap.ToByteArray();
                    System.Console.WriteLine(expenseViewModel.Photo.Image.Length);
                }).ContinueWith(_ => expenseViewModel.SavePhotoAsync());
            }

            task.ContinueWith(_ => {
                activity.RunOnUiThread(() => {
                    var fragment = activity.FragmentManager.FindFragmentById <ExpenseFragment> (Resource.Id.contentFrame);
                    fragment.ReloadExpenseData();
                    Dismiss();
                });
            });
        }
        public void SaveExpense()
        {
            var assignment = new Assignment();
            var loadTask   = viewModel.LoadExpensesAsync(assignment);

            loadTask.Wait();

            var task = viewModel.SaveExpenseAsync(assignment, new Expense {
                Cost = 2
            });

            task.Wait();

            Assert.That(assignment.TotalExpenses, Is.EqualTo(2m));
        }