public async Task <DashboardState> Handle(DateTimeOffset date, UserId user, DashboardId dashboard) { var state = _readStateUseCase.Handle(date, user); var virtualState = _readVirtualStateUseCase.Handle(date, user); return(await _manager.GetState(date, user, dashboard, state, virtualState)); }
public IActionResult Get([Required] DateTimeOffset date, string period, string broker) { var userId = new UserId(User.Identity?.Name ?? string.Empty); _logger.LogInformation( $"Retrieve virtual state for user '{userId}' at {date} with period '{period}' and broker '{broker}'"); var periodValue = !string.IsNullOrEmpty(period) ? Enum.Parse <VirtualPeriod>(period) : VirtualPeriod.AllTime; var brokerId = !string.IsNullOrEmpty(broker) ? new BrokerId(broker) : null; var state = _useCase.Handle(date, userId, periodValue, brokerId); var summary = state.Summary .ToDictionary(s => s.Key.ToString(), s => new CurrencyBalanceDto(s.Value.RealSum, s.Value.VirtualSum)); var balancesDto = state.Balances .Select(b => { var inventoryDto = b.Inventory .Select(a => { var dividend = new DividendStateDto( a.Dividend.PreviousDividend, a.Dividend.LastDividend, a.Dividend.YearDividend, a.Dividend.DividendSum); return(new VirtualAssetDto( a.Id, a.Broker, a.Isin, a.Name ?? string.Empty, a.Type ?? string.Empty, a.Count, a.RealPrice, a.VirtualPrice, a.RealSum, a.VirtualSum, dividend, a.Currency)); }) .ToArray(); return(new VirtualBalanceDto(b.RealSum, b.VirtualSum, inventoryDto, b.Currency)); }) .ToArray(); var dto = new VirtualStateDto(summary, balancesDto); return(new JsonResult(dto)); }