Esempio n. 1
0
        public async Task <IPage <CredentialRole> > Get(CredentialRoleFilter filter)
        {
            Func <CredentialRole, object> orderByPredicate = null;

            if (filter.SortBy == CredentialRoleSorting.Code)
            {
                orderByPredicate = x => x.Code;
            }
            else if (filter.SortBy == CredentialRoleSorting.Description)
            {
                orderByPredicate = x => x.Description;
            }

            IEnumerable <CredentialRole> query = Roles;

            if (filter.OrderBy == Order.Desc)
            {
                query = query.OrderByDescending(orderByPredicate);
            }
            else
            {
                query = query.OrderBy(orderByPredicate);
            }

            if (!string.IsNullOrEmpty(filter.FreeText))
            {
                string searched = filter.FreeText.ToLower();

                query =
                    query
                    .Where(x =>
                           x.Code.ToLower().Contains(searched) ||
                           x.Description.ToLower().Contains(searched));
            }

            if (!string.IsNullOrEmpty(filter.Code))
            {
                string searched = filter.Code.ToLower();
                query = query.Where(x => x.Code.ToLower().Contains(searched));
            }

            if (!string.IsNullOrEmpty(filter.Description))
            {
                string searched = filter.Description.ToLower();
                query = query.Where(x => x.Description.ToLower().Contains(searched));
            }

            var count = query.Count();

            var list = query
                       .Skip((filter.Page - 1) * filter.PageSize)
                       .Take(filter.PageSize)
                       .ToList();

            return(new Page <CredentialRole>(count, list));
        }
Esempio n. 2
0
        public Task <IPage <CredentialRole> > GetRoles(string credentialId, CredentialRoleFilter credentialRoleFilter)
        {
            if (string.IsNullOrEmpty(credentialId))
            {
                throw new ArgumentNullException(nameof(credentialId));
            }

            if (credentialRoleFilter == null)
            {
                throw new ArgumentNullException(nameof(credentialRoleFilter));
            }

            var credential          = Credentials.FirstOrDefault(x => x.CredentialId == credentialId);
            var credentialRoleStore = new InMemoryCredentialRoleStore(credential.Roles);

            var page = credentialRoleStore.Get(credentialRoleFilter);

            return(page);
        }