Esempio n. 1
0
        public static void CreateAccount()
        {
            Console.Write("What is the name of this account: ");
            string accountName = Console.ReadLine();
            Console.Write("When should the account be opened: ");
            string openDateString = Console.ReadLine();

            using(IHomeAccountantDataService dataService = DependencyContainer.Instance.Resolve<IHomeAccountantDataService>())
            {
                HomeAccountant.Core.Models.AccountType type = dataService.GetAccountType(selectedAccount);
                Account account = dataService.OpenAccount(accountName, type, DateTime.Parse(openDateString), selectedAccount);
                dataService.Save();

                selectedAccount = account;
            }
        }
        public AccountStatu CloseAccount(Account account, DateTime closeDate)
        {
            if (account == null)
                throw new ArgumentException("You must provide an account to close");
            if (account.IsPermanent)
                throw new ArgumentException("You cannot close a permenant account");

            Models.AccountStatusType openType = this.repository.GetAccountStatusTypes()
                    .FirstOrDefault(t => t.Name.ToUpper() == AccountStatus.Open.ToString().ToUpper());
            Models.AccountStatusType closeType = this.repository.GetAccountStatusTypes()
                .FirstOrDefault(t => t.Name.ToUpper() == AccountStatus.Close.ToString().ToUpper());

            Models.AccountStatu accountOpen = this.repository.GetAccountStatuses()
                .Where(s => s.AccountStatusTypeId == openType.Id
                    && s.AccountId == account.Id && s.StatusDateTime <= closeDate)
                .OrderByDescending(s => s.StatusDateTime)
                .FirstOrDefault();
            DateTime? openDate = accountOpen == null ? (DateTime?)null : accountOpen.StatusDateTime;

            Models.AccountStatu accountRecentClosing = this.repository.GetAccountStatuses()
                .Where(s => s.AccountStatusTypeId == closeType.Id
                    && s.AccountId == account.Id
                    && (openDate == null || openDate < s.StatusDateTime))
                .OrderByDescending(s => s.StatusDateTime)
                .FirstOrDefault();

            if (accountOpen == null || (accountRecentClosing != null && accountRecentClosing.StatusDateTime < closeDate))
                throw new ArgumentException("The account is already closed or hasn't been opened");

            AccountStatu accountClosing = this.repository.CreateAccountStatus();
            accountClosing.StatusDateTime = closeDate;

            accountClosing.AccountStatusTypeId = closeType.Id;
            accountClosing.AccountId = account.Id;

            return accountClosing;
        }
 public Models.AccountType GetAccountType(Account account)
 {
     return this.repository.GetAccountTypes().FirstOrDefault(t => t.Id == account.AccountTypeId);
 }
Esempio n. 4
0
        public static void DisplayAccounts(int parentAccountId)
        {
            using (IHomeAccountantDataService dataService = DependencyContainer.Instance.Resolve<IHomeAccountantDataService>())
            {
                List<Account> mainAccounts = dataService.GetAccounts(parentAccount: parentAccountId, searchDate: DateTime.Now).ToList();
                if (mainAccounts.Count > 0)
                {
                    for (int i = 0; i < mainAccounts.Count(); i++)
                    {
                        Console.WriteLine("{0}: {1}", i + 1, mainAccounts[i].Name);
                    }

                    Console.WriteLine();
                    Console.Write("Select an account to manage: ");
                    string input = Console.ReadLine();

                    int accountOption;
                    if (int.TryParse(input, out accountOption) && accountOption >= 1 && accountOption <= mainAccounts.Count())
                    {
                        selectedAccount = mainAccounts[accountOption - 1];
                        DisplayAccountMenu();
                    }
                }
                else
                    DisplayAccountMenu();
            }
        }