Пример #1
0
        /// <summary>
        /// Recall a submitted expense.
        /// </summary>
        /// <returns>True if recall succeeded, false otherwise.</returns>
        public virtual async Task <bool> Recall()
        {
            msdyn_expense expense = this.Expense;

            if (this.IsSubmitted())
            {
                Common.Model.Actions.ActionRequest recallAction = new Common.Model.Actions.ActionRequest("msdyn_ExpenseEntriesRecall");
                recallAction.Parameters = new ParameterCollection();
                recallAction.Parameters.Add(new KeyValuePair <string, object>("ExpenseEntryIds", String.Format("{0}", expense.Id)));
                recallAction.Parameters.Add(new KeyValuePair <string, object>("NoteText", ""));
                recallAction.Parameters.Add(new KeyValuePair <string, object>("CorrelationId", Guid.NewGuid().ToString()));
                OrganizationResponse response = await this.DataAccess.Execute(recallAction);

                if (response != null)
                {
                    expense.msdyn_ExpenseStatus = new OptionSetValue((int)msdyn_expense_msdyn_expensestatus.Draft);
                    return(true);
                }
                else
                {
                    await MessageCenter.ShowErrorMessage(AppResources.RecallError);
                }
            }
            else
            {
                await MessageCenter.ShowErrorMessage(AppResources.RecallError);
            }
            return(false);
        }
Пример #2
0
 public NoteViewModel(msdyn_expense expense)
     : base()
 {
     this.Title           = AppResources.Receipts;
     this.AttachedNotes   = new ObservableCollection <Annotation>();
     this.SelectedExpense = expense;
 }
Пример #3
0
        private void initializeListView()
        {
            listView = new ListView
            {
                ItemTemplate = new DataTemplate(LoadExpensePreviewTemplate),
                ItemsSource  = viewModel.ExpensesCollection,
                // iOS list scrolls top item out of view when HasUnevenRows=true.
                HasUnevenRows          = Device.OnPlatform(false, true, true),
                IsPullToRefreshEnabled = true,
                RowHeight           = ExpensePreview.HeightExpensePreview,
                SeparatorVisibility = SeparatorVisibility.None,
                VerticalOptions     = LayoutOptions.FillAndExpand,
                HorizontalOptions   = LayoutOptions.FillAndExpand
            };

            listView.ItemSelected += async(sender, args) =>
            {
                msdyn_expense selectedExpense = args.SelectedItem as msdyn_expense;
                if (selectedExpense != null)
                {
                    await this.NavigateToExpenseDetailsView(selectedExpense);

                    // Deselect the item
                    listView.SelectedItem = null;
                }
            };
        }
Пример #4
0
 /// <summary>
 /// Validates if an expense can be saved.
 /// </summary>
 /// <param name="expense">The expense for which to validate save.</param>
 /// <returns>True if it can be saved, false otherwise.</returns>
 public virtual bool CanExpenseBeSaved(msdyn_expense expense)
 {
     if (expense.msdyn_ExpenseCategory == null)
     {
         MessageCenter.ShowErrorMessage(AppResources.CategoryError).DoNotAwait();
         return(false);
     }
     return(true);
 }
        /// <summary>
        /// Decorate the base expense View based on the type and behaviors of the current expense.
        /// </summary>
        /// <param name="expense"></param>
        public static ExpenseMainView CreateExpenseView(msdyn_expense expense)
        {
            // base view for any kind of expense
            ExpenseMainView expenseView          = new ExpenseMainView(expense);
            IExpenseView    decoratedExpenseView = expenseView;

            // Decorate with Receipt behavior
            decoratedExpenseView = new ReceiptBehaviorView(expenseView);

            expenseView.ExtendedExpenseBehavior = decoratedExpenseView;
            decoratedExpenseView.CreateContent();
            return(expenseView);
        }
        /// <summary>
        /// Change at runtime the behaviors of the selected expense
        /// </summary>
        /// <param name="currentExpenseView"></param>
        /// <returns></returns>
        public static IExpenseView DecorateExpenseView(IExpenseView currentExpenseView)
        {
            if (currentExpenseView != null)
            {
                msdyn_expense expense = currentExpenseView.GetExpense();
                IExpenseView  decoratedExpenseView = currentExpenseView;

                // Check if Receipt Decorator still valid
                ReceiptBehaviorView receiptBehavior = decoratedExpenseView as ReceiptBehaviorView;

                return(decoratedExpenseView);
            }
            return(null);
        }
Пример #7
0
        /// <summary>
        /// Save selected expense, if Id is null it will create a new one,
        /// otherwise it will update the selected expense.
        /// </summary>
        /// <returns>True if the expense saved, false otherwise.</returns>
        public override async Task <bool> ForcedSave()
        {
            bool          result  = false;
            msdyn_expense expense = this.Expense;

            if (expense != null)
            {
                expense.msdyn_Amount = expense.msdyn_Amount ?? new Money(0);

                // If Expense can't be saved, don't allow the client to save,
                // return false so user can make the corresponding corrections.
                if (this.CanExpenseBeSaved(expense))
                {
                    // If expense doesn't have an Id, it need to be created
                    if (expense.Id == null || expense.Id == Guid.Empty)
                    {
                        // Always clear the expense id when creating a new entry
                        // because CRM validation treats Guid.Empty as an invalid id for a new record.
                        Guid?expenseId = await this.DataAccess.Create(expense);

                        if (expenseId != null && expenseId != Guid.Empty)
                        {
                            expense.Id = (Guid)expenseId;
                            result     = true;
                        }
                        else
                        {
                            result = false;
                        }
                    }
                    else
                    {
                        result = await this.DataAccess.Update(expense);
                    }

                    // Update status of expense.
                    if (this.HasPendingDataToSave)
                    {
                        this.HasPendingDataToSave = !result;
                    }

                    // If save failed due to something unforseen, show a message.
                    if (!result)
                    {
                        await MessageCenter.ShowErrorMessage(AppResources.SaveError);
                    }
                }
            }
            return(result);
        }
Пример #8
0
        /// <summary>
        /// If the expense is not yet created, just delete from memory. Otherwise delete from server
        /// </summary>
        /// <param name="omitWarningMessage">True if deletion would happen without a confirmation from the user</param>
        /// <returns>True if the expense was deleted</returns>
        public async Task <bool> Delete(bool omitWarningMessage = false)
        {
            msdyn_expense expense = this.Expense;

            if (expense != null)
            {
                if (expense.Id != null && expense.Id != Guid.Empty)
                {
                    if (omitWarningMessage || await MessageCenter.ShowDialog(AppResources.DeleteWarningExpense, null, null))
                    {
                        return(await this.DataAccess.Delete(expense.LogicalName, expense.Id));
                    }
                    return(false);
                }
                return(true);
            }
            return(false);
        }
Пример #9
0
        /// <summary>
        /// Validates if the expense can be submitted.
        /// </summary>
        /// <returns>True if it can be submitted, false otherwise.</returns>
        internal bool CanSubmit()
        {
            bool          result         = false;
            msdyn_expense currentExpense = this.Expense;

            if (currentExpense != null && currentExpense.ExpenseCategory != null)
            {
                if (currentExpense.ExpenseCategory.IsReceiptMandatory())
                {
                    return(currentExpense.HasReceipts);
                }
                else
                {
                    return(true);
                }
            }

            return(result);
        }
 public ReceiptsCollectionView(msdyn_expense expense) : base()
 {
     this.Title = AppResources.Receipts;
 }
Пример #11
0
 public ReceiptViewModel(msdyn_expense expense) : base(expense)
 {
     this.Title = AppResources.Receipts;
 }
Пример #12
0
 public ExpenseMainView(msdyn_expense expense) : base()
 {
     this.BackgroundColor = BaseApp.PAGE_BACKGROUND_COLOR;
     this.ViewModel       = new ExpenseViewModel(expense);
     this.IsBusy          = false;
 }
Пример #13
0
 public ExpenseViewModel(msdyn_expense expense)
     : base()
 {
     this.Expense = expense;
     this.Expense.PropertyChanged += Entity_PropertyChanged;
 }
Пример #14
0
        protected async System.Threading.Tasks.Task NavigateToExpenseDetailsView(msdyn_expense expense)
        {
            ExpenseMainView expenseDetails = ExpenseViewFactory.CreateExpenseView(expense);

            await this.Navigation.PushAsync(expenseDetails);
        }