public async Task WhenIGetTodayBalances() { DateTime today = DateTime.UtcNow.Date; BalancesViewModel balances = await _context.BalanceService.GetUserEffectiveBalancesAsync(_userContext.UserId, today); _balances = balances.Items.ToList(); }
public async Task ThenBalanceForTodayExists() { DateTime today = DateTime.UtcNow.Date; BalancesViewModel balances = await _context.BalanceService.GetUserEffectiveBalancesAsync(_userContext.UserId, today); bool exists = balances.Count > 0; exists.Should().Be(true); }
public async Task ThenBalanceDeleted() { BalancesViewModel balances = await _balanceFeatureContext.BalanceService .GetUserEffectiveBalancesAsync(_userContext.UserId, _effectiveDate); bool exists = balances.Items.Any(b => b.Id == _balanceToDeleteId); exists.Should().Be(false); }
public async Task GivenISpecifiedBalanceToDelete(string assetName) { AssetViewModel asset = await _assetFeatureContext.AssetService .GetAssetByNameAsync(_userContext.UserId, assetName); BalancesViewModel balances = await _balanceFeatureContext.BalanceService .GetUserEffectiveBalancesAsync(_userContext.UserId, _effectiveDate); BalanceViewModel balance = balances.Items.Single(b => b.Asset.Name == asset.Name && b.EffectiveDate == _effectiveDate); _balanceToDeleteId = balance.Id.Value; }
public async Task WhenIUpdateBalanceOfAsset(string assetName) { DateTime today = DateTime.UtcNow.Date; AssetViewModel asset = await _assetFeatureContext.AssetService.GetAssetByNameAsync(_userContext.UserId, assetName); BalancesViewModel balances = await _balanceFeatureContext.BalanceService .GetUserEffectiveBalancesAsync(_userContext.UserId, today); BalanceViewModel balance = balances.Items.Single(b => b.Asset.Name.Equals(assetName, StringComparison.OrdinalIgnoreCase)); _updatedBalance = await _balanceFeatureContext.BalanceService .UpdateBalanceAsync(_userContext.UserId, balance.Id.Value, _balanceUpdateModel); }
public async Task <ActionResult <BalancesViewModel> > GetCurrentUserEffectiveBalances(DateTime effectiveDate) { UserViewModel user = await GetCurrentUserAsync(); if (user == null) { return(HandleUserNotFoundResult()); } BalancesViewModel result = await _balanceService.GetUserEffectiveBalancesAsync(user.Id, effectiveDate); return(HandleResult(result)); }
public ActionResult Balances(long userId) { if (!CurrentUser.IsAdmin) { throw new Exception("Unauthorized user access"); } ViewBag.userId = userId; var user = new EmployeeService().RetrieveEmployeeById(userId); var viewModel = new BalancesViewModel { UserDisplayName = user.DisplayName, UserId = user.EmployeeId }; return(View("Balances", viewModel)); }
public async Task <BalancesViewModel> GetUserEffectiveBalancesAsync(Guid userId, DateTime effectiveDate) { IEnumerable <Balance> balances = await _balanceRepository.GetByEffectiveDateAsync(userId, effectiveDate); List <BalanceViewModel> items = balances .Select(b => new BalanceViewModel(b)) .OrderBy(i => i.Asset.Currency) .ThenBy(i => i.Asset.Name) .ToList(); if (effectiveDate.Date == DateTime.UtcNow.Date) { await PopulateIsBankAccountFieldAsync(userId, items); } IEnumerable <BalanceTotalModel> totals = await _balancesTotalService.CalculateTotalsAsync(userId, balances, effectiveDate); BalancesViewModel result = new BalancesViewModel(items, items.Count, totals); return(result); }