Exemplo n.º 1
0
        public async Task <RealmResponse> GetRealmByCode(ClaimsPrincipal claim, string code)
        {
            var response = new RealmResponse();

            var user = await _userService.GetCurrentUser(claim);

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

            var realm = await _realmDataService.GetRealmAsync(code);

            if (realm == null)
            {
                response.ErrorMessages.Add($"Realm(code: {code}) was not found.");
            }
            else if (realm.IsAuthenticationRestricted && claim == null)
            {
                response.ErrorMessages.Add($"Realm(code: {code}) requires you to be authenticated to view it.");
            }
            else if (realm.IsPrivate && realm.ApplicationUserId != userId)
            {
                response.ErrorMessages.Add($"Realm(code: {code}) is a private realm.");
            }
            else
            {
                response.Data = await MapRealmAndBuildFragmentsMap(realm);
            }

            return(response);
        }
Exemplo n.º 2
0
        public async Task <FragmentMatchResponse> GetFilterMatchedFragments(ClaimsPrincipal claim, string code, string filter)
        {
            var response = new FragmentMatchResponse();

            var user = await _userService.GetCurrentUser(claim);

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

            var realm = await _realmDataService.GetRealmAsync(code);

            if (realm == null)
            {
                response.ErrorMessages.Add($"Realm(code: {code}) was not found.");
            }
            else if (realm.IsAuthenticationRestricted && claim == null)
            {
                response.ErrorMessages.Add($"Realm(code: {code}) requires you to be authenticated to view it.");
            }
            else if (realm.IsPrivate && realm.ApplicationUserId != userId)
            {
                response.ErrorMessages.Add($"Realm(code: {code}) is a private realm.");
            }
            else
            {
                var fragments = await _fragmentDataService.FilterRealmFragments(realm.Id, filter);

                response.Data = _mapper.Map <List <FragmentMatchViewModel> >(fragments);
            }

            return(response);
        }