Exemplo n.º 1
0
        public SpySettingsViewModel GetSpySettings(long spyAccountId)
        {
            var statistics = _statisticsManager.GetSpyStatistics(spyAccountId);

            var detailedStatistic = new DetailedSpyStatisticsModel
            {
                AllTimeStatistic  = _statisticsManager.GetAllTimeSpyStatistics(statistics),
                LastHourStatistic = _statisticsManager.GetLastHourSpyStatistics(statistics),
            };

            var functions = new GetFunctionsQueryHandler(new DataBaseContext()).Handle(new GetFunctionsQuery
            {
                ForSpy = true
            });
            var spyFunctions = new GetAllSpyFunctionByIdQueryHandler(new DataBaseContext()).Handle(new GetAllSpyFunctionByIdQuery
            {
                SpyId = spyAccountId
            });

            var result = new SpySettingsViewModel
            {
                SpyId         = spyAccountId,
                SpyStatistics = detailedStatistic,
                SpyFunctions  = functions.Select(func => new SpyFunctionViewModel
                {
                    Name             = func.Name,
                    FunctionName     = func.FunctionName,
                    FunctionId       = func.FunctionId,
                    Assigned         = spyFunctions.Any(spyFunction => spyFunction.FunctionId == func.FunctionId && spyFunction.SpyId == spyAccountId),
                    FunctionTypeName = func.FunctionTypeName,
                    TypeName         = func.TypeName
                }).ToList()
            };

            return(result);
        }