From 7a2ef63b79e804b96c0885e3efa43310fd973f44 Mon Sep 17 00:00:00 2001 From: Vijayakumar Mariappan Date: Mon, 7 May 2018 21:07:27 +0530 Subject: [PATCH] Committed Expense description changes. --- .../Model/TransactionDetail.cs | 3 +- .../View/AddTransactionsPage.xaml.cs | 32 +++++++++++-------- 2 files changed, 21 insertions(+), 14 deletions(-) diff --git a/ExpenseAnalysis/ExpenseAnalysis/Model/TransactionDetail.cs b/ExpenseAnalysis/ExpenseAnalysis/Model/TransactionDetail.cs index e5dc147..bd5a103 100644 --- a/ExpenseAnalysis/ExpenseAnalysis/Model/TransactionDetail.cs +++ b/ExpenseAnalysis/ExpenseAnalysis/Model/TransactionDetail.cs @@ -20,11 +20,12 @@ namespace ExpenseAnalysis public class AddTransactionDetail { - public double Spent { get; set; } public CategoryPicker Category { get; set; } + [Display(Name = "Expense Description")] + [Required(AllowEmptyStrings = false, ErrorMessage = "Description should not be empty")] public string ExpenseDescription { get; set; } public DateTime Date { get; set; } diff --git a/ExpenseAnalysis/ExpenseAnalysis/View/AddTransactionsPage.xaml.cs b/ExpenseAnalysis/ExpenseAnalysis/View/AddTransactionsPage.xaml.cs index c6a1e43..e4eaff3 100644 --- a/ExpenseAnalysis/ExpenseAnalysis/View/AddTransactionsPage.xaml.cs +++ b/ExpenseAnalysis/ExpenseAnalysis/View/AddTransactionsPage.xaml.cs @@ -8,6 +8,8 @@ namespace ExpenseAnalysis { public TransactionPage TransactionPage; + bool isDescriptionValid; + public AddTransactionsPage() { InitializeComponent(); @@ -15,20 +17,24 @@ namespace ExpenseAnalysis private void DoneButton_Clicked(object sender, EventArgs e) { - var newTransaction = ((ExpenseViewModel)BindingContext).SingleTransaction; - if (newTransaction.Spent != 0) - { - var transaction = new TransactionDetail - { - Category = newTransaction.Category.ToString(), - Date = newTransaction.Date, - Spent = newTransaction.Spent, - Name = newTransaction.ExpenseDescription - }; - ((ExpenseViewModel)BindingContext).AddTransaction(transaction); - TransactionPage.CanNotify = true; + isDescriptionValid = dataForm.Validate("ExpenseDescription"); + if (isDescriptionValid) + { + var newTransaction = ((ExpenseViewModel)BindingContext).SingleTransaction; + if (newTransaction.Spent != 0) + { + var transaction = new TransactionDetail + { + Category = newTransaction.Category.ToString(), + Date = newTransaction.Date, + Spent = newTransaction.Spent, + Name = newTransaction.ExpenseDescription + }; + ((ExpenseViewModel)BindingContext).AddTransaction(transaction); + TransactionPage.CanNotify = true; + } + Navigation.PopToRootAsync(); } - Navigation.PopToRootAsync(); } private void DataForm_AutoGeneratingDataFormItem(object sender, AutoGeneratingDataFormItemEventArgs e)