private static AccountActivityOverViewVeiwModel CreateViewModel(IOrderedEnumerable <AccountActivitiesViewModel> allActivities, int year, int month)
        {
            var runningTotal = 0d;

            foreach (var activity in allActivities)
            {
                if (!activity.IsTransfer)
                {
                    runningTotal += activity.Amount;
                }
                activity.RunningTotal = runningTotal;
            }

            var allActivitiesDateDesending = allActivities.Reverse().ToList();

            var accountActivityOverViewVeiwModel = new AccountActivityOverViewVeiwModel(allActivitiesDateDesending)
            {
                MoneyIn       = allActivities.Where(x => !x.IsTransfer).Sum(x => x.Amount > 0 ? x.Amount : 0),
                MoneyOut      = allActivities.Where(x => !x.IsTransfer).Sum(x => x.Amount < 0 ? x.Amount : 0),
                PreviousMonth = DateService.PreviousMonth(year, month),
                PreviousYear  = DateService.PreviousYear(year, month),
                NextMonth     = DateService.NextMonth(year, month),
                NextYear      = DateService.NextYear(year, month),
                StatementDate = DateService.GetMonthYearDate(year, month)
            };

            return(accountActivityOverViewVeiwModel);
        }
Example #2
0
        public ActionResult Statements(int accountId)
        {
            var statementViewModels = new List <StatementOverviewViewModel>();

            var transactions = GetTransactions(accountId);
            var transfers    = GetTransfers(accountId);

            var allStatements = transactions.Concat(transfers)
                                .OrderByDescending(x => x.Date)
                                .GroupBy(x => x.Year & x.Month);

            foreach (var statementCollection in allStatements)
            {
                var @in   = statementCollection.Where(x => x.Amount > 0).Sum(x => x.Amount);
                var @out  = statementCollection.Where(x => x.Amount < 0).Sum(x => x.Amount);
                var sum   = @in + @out;
                var year  = statementCollection.First().Year;
                var month = statementCollection.First().Month;
                var date  = statementCollection.First().Date;

                var statementOverviewViewModel = new StatementOverviewViewModel()
                {
                    In            = @in,
                    Out           = @out,
                    Amount        = sum,
                    StatementDate = DateService.GetMonthYearDate(year, month),
                    Date          = date,
                    AccountId     = accountId
                };

                statementViewModels.Add(statementOverviewViewModel);
            }

            var account   = accountRepository.Find(accountId);
            var viewModel = new StatementsViewModel
            {
                AccountName = account.Name,
                Statements  = statementViewModels,
                MoneyIn     = transactions.Concat(transfers).Sum(x => x.Amount > 0 ? x.Amount : 0),
                MoneyOut    = transactions.Concat(transfers).Sum(x => x.Amount < 0 ? x.Amount : 0)
            };

            return(View(viewModel));
        }
Example #3
0
        public ActionResult Statement(int accountId, int year, int month)
        {
            var account = accountRepository.Find(accountId);
            var date    = DateService.GetMonthYearDate(year, month);

            var transactions = transactionRepository.All.Where(x => x.AccountId == accountId && x.Date.Year == year && x.Date.Month == month).ToList();
            var transfersOut = transferRepository.All.Where(x => x.AccountId == accountId && x.Date.Year == year && x.Date.Month == month).ToList();
            var transfersIn  = transferRepository.All.Where(x => x.ToAccountId == accountId && x.Date.Year == year && x.Date.Month == month).ToList();

            foreach (var transfer in transfersOut)
            {
                transfer.Amount = -transfer.Amount;
            }

            var activities = new List <IAccountActivity>();

            activities.AddRange(transactions);
            activities.AddRange(transfersOut);
            activities.AddRange(transfersIn);
            var accountActivitiesVM = activities.OrderByDescending(x => x.Date).Select(x => new AccountActivitiesViewModel(x)).ToList();

            var viewModel = new StatementViewModel
            {
                AccountId     = accountId,
                AccountName   = account.Name,
                StatementDate = date,
                PreviousMonth = DateService.PreviousMonth(year, month),
                PreviousYear  = DateService.PreviousYear(year, month),
                NextMonth     = DateService.NextMonth(year, month),
                NextYear      = DateService.NextYear(year, month),
                Activities    = accountActivitiesVM,
                MoneyIn       = activities.Sum(x => x.Amount > 0 ? x.Amount : 0),
                MoneyOut      = activities.Sum(x => x.Amount < 0 ? x.Amount : 0)
            };

            return(View(viewModel));
        }