From 969f7b61fcde082796d77fa3a5afd498c211a562 Mon Sep 17 00:00:00 2001 From: Ryan Alford Date: Tue, 1 Jul 2014 11:48:15 -0400 Subject: [PATCH] Implemented Adding New Transactions Implemented adding a new transaction to an account. An Add button will be at the top right of the account/transactions view, which will allow the user to add additional transactions. The transaction list and account balance are updated appropriately, --- .gitignore | 3 +- Framework.iOS/Framework.iOS.csproj | 2 - QBank.Api/QBank.Api.csproj | 3 - QBank.DataAccess/QBank.DataAccess.csproj | 2 - .../QBank.Infrastructure.Web.csproj | 2 - QBank.Model/QBank.Model.csproj | 2 - QBank.Service/QBank.Service.csproj | 2 - QBank.sln | 5 - iOS.Client/DataAccess/AccountsRepository.cs | 27 +++++ iOS.Client/Element/AccountRootElement.cs | 46 +++++++ iOS.Client/Screens/Accounts.cs | 9 +- iOS.Client/Screens/Transaction.cs | 112 ++++++++++++++++++ iOS.Client/iOS.Client.csproj | 13 +- 13 files changed, 202 insertions(+), 26 deletions(-) create mode 100644 iOS.Client/Screens/Transaction.cs diff --git a/.gitignore b/.gitignore index a3ec82f..83443ae 100644 --- a/.gitignore +++ b/.gitignore @@ -107,4 +107,5 @@ Generated_Code #added for RIA/Silverlight projects # Visual Studio version. Backup files are not needed, because we have git ;-) _UpgradeReport_Files/ Backup*/ -UpgradeLog*.XML \ No newline at end of file +UpgradeLog*.XML +*.userprefs diff --git a/Framework.iOS/Framework.iOS.csproj b/Framework.iOS/Framework.iOS.csproj index a928c7e..72457ad 100644 --- a/Framework.iOS/Framework.iOS.csproj +++ b/Framework.iOS/Framework.iOS.csproj @@ -3,8 +3,6 @@ Debug AnyCPU - 8.0.30703 - 2.0 {0166E991-1FED-4430-AF57-BC51E774B9A3} {6BC8ED88-2882-458C-8E55-DFD12B67127B};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} Library diff --git a/QBank.Api/QBank.Api.csproj b/QBank.Api/QBank.Api.csproj index 7b942f7..f1a993c 100644 --- a/QBank.Api/QBank.Api.csproj +++ b/QBank.Api/QBank.Api.csproj @@ -4,9 +4,6 @@ Debug AnyCPU - - - 2.0 {2E622B76-DE24-4398-BB9A-D6EB06723334} {E3E379DF-F4C6-4180-9B81-6769533ABE47};{349C5851-65DF-11DA-9384-00065B846F21};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} Library diff --git a/QBank.DataAccess/QBank.DataAccess.csproj b/QBank.DataAccess/QBank.DataAccess.csproj index 800e72a..60c9155 100644 --- a/QBank.DataAccess/QBank.DataAccess.csproj +++ b/QBank.DataAccess/QBank.DataAccess.csproj @@ -3,8 +3,6 @@ Debug AnyCPU - 8.0.30703 - 2.0 {1DA1F168-7E36-468A-AF9C-6167233200F5} Library Properties diff --git a/QBank.Infrastructure.Web/QBank.Infrastructure.Web.csproj b/QBank.Infrastructure.Web/QBank.Infrastructure.Web.csproj index eb898ff..32d0051 100644 --- a/QBank.Infrastructure.Web/QBank.Infrastructure.Web.csproj +++ b/QBank.Infrastructure.Web/QBank.Infrastructure.Web.csproj @@ -3,8 +3,6 @@ Debug AnyCPU - 8.0.30703 - 2.0 {24FBFD89-0069-408A-A6BF-ECF0CA5E019E} Library Properties diff --git a/QBank.Model/QBank.Model.csproj b/QBank.Model/QBank.Model.csproj index efbad23..2c5717a 100644 --- a/QBank.Model/QBank.Model.csproj +++ b/QBank.Model/QBank.Model.csproj @@ -3,8 +3,6 @@ Debug AnyCPU - 8.0.30703 - 2.0 {C8386F02-74E2-48D6-8D87-3F151203AC46} Library Properties diff --git a/QBank.Service/QBank.Service.csproj b/QBank.Service/QBank.Service.csproj index ac56dc9..4befc0b 100644 --- a/QBank.Service/QBank.Service.csproj +++ b/QBank.Service/QBank.Service.csproj @@ -3,8 +3,6 @@ Debug AnyCPU - 8.0.30703 - 2.0 {90CAC7EC-480B-43D6-824F-6C59DA02F6F9} Library Properties diff --git a/QBank.sln b/QBank.sln index 0b08818..16f1bd0 100644 --- a/QBank.sln +++ b/QBank.sln @@ -59,7 +59,6 @@ Global {1DA1F168-7E36-468A-AF9C-6167233200F5}.AppStore|iPhone.ActiveCfg = Debug|Any CPU {1DA1F168-7E36-468A-AF9C-6167233200F5}.AppStore|iPhone.Build.0 = Debug|Any CPU {1DA1F168-7E36-468A-AF9C-6167233200F5}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {1DA1F168-7E36-468A-AF9C-6167233200F5}.Debug|Any CPU.Build.0 = Debug|Any CPU {1DA1F168-7E36-468A-AF9C-6167233200F5}.Debug|iPhone.ActiveCfg = Debug|Any CPU {1DA1F168-7E36-468A-AF9C-6167233200F5}.Debug|iPhone.Build.0 = Debug|Any CPU {1DA1F168-7E36-468A-AF9C-6167233200F5}.Debug|iPhoneSimulator.ActiveCfg = Debug|Any CPU @@ -75,7 +74,6 @@ Global {24FBFD89-0069-408A-A6BF-ECF0CA5E019E}.AppStore|iPhone.ActiveCfg = Debug|Any CPU {24FBFD89-0069-408A-A6BF-ECF0CA5E019E}.AppStore|iPhone.Build.0 = Debug|Any CPU {24FBFD89-0069-408A-A6BF-ECF0CA5E019E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {24FBFD89-0069-408A-A6BF-ECF0CA5E019E}.Debug|Any CPU.Build.0 = Debug|Any CPU {24FBFD89-0069-408A-A6BF-ECF0CA5E019E}.Debug|iPhone.ActiveCfg = Debug|Any CPU {24FBFD89-0069-408A-A6BF-ECF0CA5E019E}.Debug|iPhone.Build.0 = Debug|Any CPU {24FBFD89-0069-408A-A6BF-ECF0CA5E019E}.Debug|iPhoneSimulator.ActiveCfg = Debug|Any CPU @@ -91,7 +89,6 @@ Global {2E622B76-DE24-4398-BB9A-D6EB06723334}.AppStore|iPhone.ActiveCfg = Debug|Any CPU {2E622B76-DE24-4398-BB9A-D6EB06723334}.AppStore|iPhone.Build.0 = Debug|Any CPU {2E622B76-DE24-4398-BB9A-D6EB06723334}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {2E622B76-DE24-4398-BB9A-D6EB06723334}.Debug|Any CPU.Build.0 = Debug|Any CPU {2E622B76-DE24-4398-BB9A-D6EB06723334}.Debug|iPhone.ActiveCfg = Debug|Any CPU {2E622B76-DE24-4398-BB9A-D6EB06723334}.Debug|iPhone.Build.0 = Debug|Any CPU {2E622B76-DE24-4398-BB9A-D6EB06723334}.Debug|iPhoneSimulator.ActiveCfg = Debug|Any CPU @@ -127,7 +124,6 @@ Global {90CAC7EC-480B-43D6-824F-6C59DA02F6F9}.AppStore|iPhone.ActiveCfg = Debug|Any CPU {90CAC7EC-480B-43D6-824F-6C59DA02F6F9}.AppStore|iPhone.Build.0 = Debug|Any CPU {90CAC7EC-480B-43D6-824F-6C59DA02F6F9}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {90CAC7EC-480B-43D6-824F-6C59DA02F6F9}.Debug|Any CPU.Build.0 = Debug|Any CPU {90CAC7EC-480B-43D6-824F-6C59DA02F6F9}.Debug|iPhone.ActiveCfg = Debug|Any CPU {90CAC7EC-480B-43D6-824F-6C59DA02F6F9}.Debug|iPhone.Build.0 = Debug|Any CPU {90CAC7EC-480B-43D6-824F-6C59DA02F6F9}.Debug|iPhoneSimulator.ActiveCfg = Debug|Any CPU @@ -143,7 +139,6 @@ Global {C8386F02-74E2-48D6-8D87-3F151203AC46}.AppStore|iPhone.ActiveCfg = Debug|Any CPU {C8386F02-74E2-48D6-8D87-3F151203AC46}.AppStore|iPhone.Build.0 = Debug|Any CPU {C8386F02-74E2-48D6-8D87-3F151203AC46}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {C8386F02-74E2-48D6-8D87-3F151203AC46}.Debug|Any CPU.Build.0 = Debug|Any CPU {C8386F02-74E2-48D6-8D87-3F151203AC46}.Debug|iPhone.ActiveCfg = Debug|Any CPU {C8386F02-74E2-48D6-8D87-3F151203AC46}.Debug|iPhone.Build.0 = Debug|Any CPU {C8386F02-74E2-48D6-8D87-3F151203AC46}.Debug|iPhoneSimulator.ActiveCfg = Debug|Any CPU diff --git a/iOS.Client/DataAccess/AccountsRepository.cs b/iOS.Client/DataAccess/AccountsRepository.cs index 8346ce7..6f462ea 100644 --- a/iOS.Client/DataAccess/AccountsRepository.cs +++ b/iOS.Client/DataAccess/AccountsRepository.cs @@ -1,6 +1,7 @@ using System; using iOS.Client.Model; using System.Collections.Generic; +using System.Linq; namespace iOS.Client { @@ -8,6 +9,8 @@ public interface IAccountsRepository { Account GetByAccountNumber(string accountNumber); IEnumerable GetAccountByCustomerId(int id); + Account ProcessDeposit (Account account, Transaction transaction); + Account ProcessCredit (Account account, Transaction transaction); } public class AccountsRepository: IAccountsRepository @@ -26,6 +29,30 @@ public IEnumerable GetAccountByCustomerId (int id) return seedAccounts; } + public Account ProcessDeposit(Account account, Transaction transaction) + { + return ProcessTransaction (account, transaction, true); + } + + public Account ProcessCredit(Account account, Transaction transaction) + { + return ProcessTransaction (account, transaction, false); + } + + private Account ProcessTransaction(Account account, Transaction transaction, bool isDeposit) + { + var now = DateTime.Now; + + account.Transactions.Add(transaction); + + if (isDeposit) + account.Balance += transaction.Amount; + else + account.Balance -= transaction.Amount; + + return account; + } + #endregion public AccountsRepository () diff --git a/iOS.Client/Element/AccountRootElement.cs b/iOS.Client/Element/AccountRootElement.cs index 020d710..8a2d568 100644 --- a/iOS.Client/Element/AccountRootElement.cs +++ b/iOS.Client/Element/AccountRootElement.cs @@ -18,6 +18,11 @@ public float GetHeight (UITableView tableView, NSIndexPath indexPath) NSString _cellKey = new NSString("AccountCell"); Account _account; bool _showIndicator; + bool _createAddButton; + private UIBarButtonItem _addButton; + IAccountsRepository _repository; + + public UINavigationController NavigationController { get; set; } protected override NSString CellKey {get {return _cellKey;}} @@ -36,9 +41,50 @@ public AccountRootElement (Account account, bool showIndicator, Func createOnSelected, bool createAddButton) : base(account.AccountNumber,createOnSelected ) + { + this._showIndicator = showIndicator; + _account = account; + _createAddButton = createAddButton; + _repository = accountRepo; + } + public AccountRootElement (Account account):base(account.AccountNumber) { _account = account; } + protected override void PrepareDialogViewController (UIViewController dvc) + { + base.PrepareDialogViewController (dvc); + + if (!_createAddButton) + return; + + accountRoot = (dvc as DialogViewController).Root; + + _addButton = new UIBarButtonItem (UIBarButtonSystemItem.Add, AddTransaction); + dvc.NavigationItem.RightBarButtonItem = _addButton; + } + + RootElement accountRoot; + + private void AddTransaction(object sender, EventArgs e) + { + var transactionView = new Transactions (_repository, _account); + transactionView.SaveCompleted += (transaction) => + { + // gets the section that contains the transactions and adds + // new transaction element to the section + var section = accountRoot[1]; + section.Add(new TransactionElement(transaction)); + + // updates the account section to updated the account balance. + var accountSection = new Section() { new AccountElement(_account, false) }; + accountRoot.RemoveAt(0); + accountRoot.Insert(0, accountSection); + }; + + NavigationController.PushViewController (transactionView, true); + } } diff --git a/iOS.Client/Screens/Accounts.cs b/iOS.Client/Screens/Accounts.cs index 93682c2..79fed62 100644 --- a/iOS.Client/Screens/Accounts.cs +++ b/iOS.Client/Screens/Accounts.cs @@ -54,7 +54,7 @@ RootElement CreateNewRoot(IEnumerable> accountsByGrou in accountsByGroup select new Section () { // i.e.: Deposits from account in _group select - new AccountRootElement(account,true, StyleTransactionsScreen) + new AccountRootElement(accountRepo: repository, account: account, showIndicator: true, createOnSelected: StyleTransactionsScreen, createAddButton: true) { new Section() // Section for Account Header { @@ -86,5 +86,12 @@ void CreateScreen () accountsByGroup = model.GroupBy (g => g.AccountType); Root = CreateNewRoot(accountsByGroup); + + for (int i = 0; i < Root.Count; i++) + { + var section = Root [i]; + var accountRootElement = (AccountRootElement)section.Elements [0]; + accountRootElement.NavigationController = this.NavigationController; + } } } diff --git a/iOS.Client/Screens/Transaction.cs b/iOS.Client/Screens/Transaction.cs new file mode 100644 index 0000000..6e1bd8b --- /dev/null +++ b/iOS.Client/Screens/Transaction.cs @@ -0,0 +1,112 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using MonoTouch.Foundation; +using MonoTouch.UIKit; +using MonoTouch.Dialog; +using iOS.Client.Model; + +namespace iOS.Client +{ + public partial class Transactions : DialogViewController + { + IAccountsRepository _repository; + Account _account; + + private bool IsDeposit + { + get { return _account.AccountType == "Deposit" || _account.AccountType == "Savings"; } + } + + public Action SaveCompleted; + + public Transactions (IAccountsRepository repository, Account account) : base (UITableViewStyle.Grouped, null) + { + _repository = repository; + _account = account; + } + + public override void LoadView () + { + base.LoadView (); + CreateScreen (); + ApplyStyle (); + } + + public void ApplyStyle() + { + Root.TableView.SeparatorColor = UIColor.FromPatternImage (Resources.CellSeparator); + Root.TableView.BackgroundView = new UIImageView (UIImage.FromBundle ("paper.png")); + } + + private void CreateNewRoot() + { + Root = new RootElement ("Add Transaction"); + + var section = new Section (string.Empty) + { + new DateElement ("Transaction Date", DateTime.Now), + new EntryElement ("Description", "", ""), + new EntryElement ("Amount", "", "") { KeyboardType = UIKeyboardType.DecimalPad }, + }; + + Root.Add (section); + + var saveSection = new Section (string.Empty); + var saveButton = new StyledStringElement ("Save", () => + { + float amount = 0f; + + if (!float.TryParse((section.Elements[2] as EntryElement).Value, out amount)) + { + new UIAlertView("Amount Error", "Amount must be a numeric value and is required", null, "Ok", null).Show(); + return; + } + + var transaction = new Transaction () + { + OccuredOn = (section.Elements[0] as DateElement).DateValue, + Amount = amount, + Description = (section.Elements[1] as EntryElement).Value, + RemainingBalance = CalculateBalance(amount) + }; + + if (IsDeposit) + _repository.ProcessDeposit(_account, transaction); + else + _repository.ProcessCredit(_account, transaction); + + if (SaveCompleted != null) + SaveCompleted(transaction); + + NavigationController.PopViewControllerAnimated(true); + + }); + saveSection.Add (saveButton); + Root.Add (saveSection); + } + + private double CalculateBalance(float amount) + { + if (IsDeposit) + return _account.Balance + amount; + else + { + if (_account.Balance > 0) + return _account.Balance - amount; + else + return _account.Balance + amount; + } + } + + private void CreateScreen () + { + NavigationItem.TitleView = new UIImageView (UIImage.FromBundle ("logo")); + NavigationItem.LeftBarButtonItem = new UIBarButtonItem ("Back", UIBarButtonItemStyle.Done, (s, e) => + { + NavigationController.PopViewControllerAnimated(true); + }); + CreateNewRoot(); + } + } +} diff --git a/iOS.Client/iOS.Client.csproj b/iOS.Client/iOS.Client.csproj index bc4d2ff..1f2ace8 100644 --- a/iOS.Client/iOS.Client.csproj +++ b/iOS.Client/iOS.Client.csproj @@ -3,8 +3,6 @@ Debug iPhoneSimulator - 8.0.30703 - 2.0 {842ADB2E-6B84-48C8-820B-AA72955D78F2} {6BC8ED88-2882-458C-8E55-DFD12B67127B};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} Exe @@ -40,7 +38,8 @@ None true iOS - + + ARMv7 @@ -65,8 +64,10 @@ true iPhone Developer QBank - - + + + + ARMv7 @@ -122,6 +123,7 @@ + @@ -185,7 +187,6 @@ - True 1.5 False