Exemple #1
0
 public ExpenseViewBehavior(IExpenseView expenseView)
 {
     if (expenseView == null)
     {
         throw new ArgumentNullException("Class decorator can't have a null IExpenseView");
     }
     this.ExpenseView = expenseView;
 }
        /// <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);
        }
Exemple #4
0
        /// <summary>
        /// Check the behaviors of the new category, if there is data that needs to be deleted,
        /// show a warning message to the user before change category.
        /// </summary>
        /// <param name="newExpenseCategory">expense category selected by the user</param>
        /// <param name="warningMessage">If there is data to delete, message with details of the data to be deleted</param>
        /// <returns>true if the change of category was successful</returns>
        public async Task <bool> SetCategory(msdyn_expensecategory newExpenseCategory, string warningMessage = null)
        {
            bool allowSetCategory = true;

            if (!string.IsNullOrEmpty(warningMessage))
            {
                // Confirm with user the change of category
                string message = string.Format(AppResources.ChangeExpenseTypeWarning, warningMessage);
                allowSetCategory = await MessageCenter.ShowDialog(message, null, null);
            }

            if (allowSetCategory)
            {
                this.ViewModel.Expense.ExpenseCategory = newExpenseCategory;
                // Change category and update new view
                this.ExtendedExpenseBehavior = ExpenseViewFactory.DecorateExpenseView(this.ExtendedExpenseBehavior);
                await this.ExtendedExpenseBehavior.CreateContent();
            }

            return(allowSetCategory);
        }
Exemple #5
0
 public ReceiptBehaviorView(IExpenseView baseExpenseView) : base(baseExpenseView)
 {
     this.ViewModel = new ReceiptViewModel(this.GetExpense());
 }