示例#1
0
        public List <GroupFunctionViewModel> GetGroupFunctions()
        {
            var functions = new GetFunctionsQueryHandler(new DataBaseContext()).Handle(new GetFunctionsQuery
            {
                ForSpy = false
            });

            var groups         = new GetGroupsQueryHandler(new DataBaseContext()).Handle(new GetGroupsQuery());
            var groupFunctions = new GroupFunctionsQueryHandler(new DataBaseContext()).Handle(new GroupFunctionsQuery());

            var result = groups.Select(group => new GroupFunctionViewModel
            {
                GroupId   = group.Id,
                GroupName = group.Name,
                Functions = functions.Select(function => new FunctionViewModel
                {
                    Name         = function.Name,
                    FunctionName = function.FunctionName,
                    FunctionId   = function.FunctionId,
                    Assigned     =
                        groupFunctions.Any(
                            groupFunction =>
                            groupFunction.FunctionId == function.FunctionId && groupFunction.GroupId == group.Id),
                    FunctionTypeName = function.FunctionTypeName,
                    TypeName         = function.TypeName
                }).ToList()
            }).ToList();

            return(result);
        }
示例#2
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);
        }