public IEnumerable <Author> GetAuthors(AuthorsResourcesParameters authorsResourcesParameters)
        {
            if (authorsResourcesParameters == null)
            {
                throw new ArgumentNullException(nameof(authorsResourcesParameters));
            }

            if (string.IsNullOrEmpty(authorsResourcesParameters.MainCategory) &&
                string.IsNullOrEmpty(authorsResourcesParameters.SearchQuery))
            {
                return(GetAuthors());
            }

            var collection = _context.Authors as IQueryable <Author>;

            if (!string.IsNullOrEmpty(authorsResourcesParameters.MainCategory))
            {
                var mainCategory = authorsResourcesParameters.MainCategory.Trim();

                collection = collection.Where(a => a.MainCategory == mainCategory);
            }
            if (!string.IsNullOrEmpty(authorsResourcesParameters.SearchQuery))
            {
                var searchQuery = authorsResourcesParameters.SearchQuery.Trim();
                collection = collection.Where(a => a.MainCategory.Contains(searchQuery) || a.FirstName.Contains(searchQuery) || a.LastName.Contains(searchQuery));
            }

            return(collection.ToList <Author>());
        }
        public ActionResult <IEnumerable <AuthorDTO> > GetAuthors(
            [FromQuery] AuthorsResourcesParameters authorsResourceParameters)
        {
            var authorsFromRepo = _courseLibraryRepository.GetAuthors(authorsResourceParameters);

            return(Ok(_mapper.Map <IEnumerable <AuthorDTO> >(authorsFromRepo)));
        }
        public IEnumerable <Author> GetAuthors(AuthorsResourcesParameters authorsResourcesParameters)
        {
            if (authorsResourcesParameters == null)
            {
                return(_context.Authors.ToList <Author>());
            }
            if (string.IsNullOrEmpty(authorsResourcesParameters.MainCategory) && string.IsNullOrEmpty(authorsResourcesParameters.SearchQuery))
            {
                return(GetAuthors());
            }

            var collection = _context.Authors as IQueryable <Author>;

            if (!string.IsNullOrWhiteSpace(authorsResourcesParameters.MainCategory))
            {
                collection = collection
                             .Where(m => m.MainCategory.Trim().ToUpper().Contains(authorsResourcesParameters.MainCategory.Trim().ToUpper()));
            }

            if (!string.IsNullOrWhiteSpace(authorsResourcesParameters.SearchQuery))
            {
                var searchQuery = authorsResourcesParameters.SearchQuery.Trim().ToUpper();
                collection = collection.Where(m => m.MainCategory.Trim().ToUpper().Contains(searchQuery) ||
                                              m.FirstName.Trim().ToUpper().Contains(searchQuery) ||
                                              m.LastName.Trim().ToUpper().Contains(searchQuery));
            }
            return(collection.ToList <Author>());
        }