Ejemplo n.º 1
0
        public async Task<TagRelatedEntitiesResponse> GetRealmsWithTags(ClaimsPrincipal claim, TagRelatedEntitiesRequest request)
        {
            var response = new TagRelatedEntitiesResponse();
            var user = await _userService.GetCurrentUser(claim);
            var userId = user == null ? string.Empty : user.Id;

            // Realms valid to user
            var realms = await _realmDataService.GetRealms(userId);

            // Realms for these tags
            var tagOptions = await _tagDataService
                .GetTagsForScopeQuery(TagScope.Realm)
                .Include(x => x.Realms)
                .OrderBy(x => x.Name)
                .ToListAsync();

            var tags = tagOptions
                .Where(x => request.TagCodes.Contains(x.Code))
                .ToList();

            var tagRealmIds = tags.SelectMany(x => x.Realms.Select(r => r.Id)).Distinct();
            var realmIds = tagRealmIds
                .Where(x => tags.All(t => t.Realms.Any(r => r.Id == x)))
                .ToList();

            response.Data.Tags = _mapper.Map<List<TagDropdownModel>>(tags);
            response.Data.TagOptions = _mapper.Map<List<TagDropdownModel>>(tagOptions);
            response.Data.Items = _mapper.Map<List<TagRelatedItem>>(
                realms
                    .Where(r => realmIds.Contains(r.Id))
                    .OrderBy(r => r.Name)
            );

            return response;
        }
Ejemplo n.º 2
0
        public async Task <List <RealmItemViewModel> > GetRealms(ClaimsPrincipal claim)
        {
            var user = await _userService.GetCurrentUser(claim);

            var userId = user == null ? string.Empty : user.Id;

            var realms = await _realmDataService.GetRealms(userId);

            return(_mapper.Map <List <RealmItemViewModel> >(realms)
                   .OrderBy(x => x.Name)
                   .ThenByDescending(x => x.FragmentCount)
                   .ToList());
        }