Esempio n. 1
0
        public async Task <PageList <Post> > GetAllFollowingPosts(Guid userId, PostResourceParameters postResourceParameters)
        {
            if (postResourceParameters == null)
            {
                throw new ArgumentNullException(nameof(postResourceParameters));
            }

            var user = await _context.Users.FindAsync(userId);

            List <Guid> allFollowingIds = user.Following.Select(uf => uf.FollowingId).ToList();

            var collection = _context.Posts as IQueryable <Post>;

            collection = collection.Where(p => allFollowingIds.Contains(p.AuthorId));

            if (!string.IsNullOrWhiteSpace(postResourceParameters.SearchQuery))
            {
                var searchinQuery = postResourceParameters.SearchQuery.Trim().ToLower();
                collection = collection.Where(p => p.Title.ToLower().Contains(searchinQuery));
            }

            if (!string.IsNullOrWhiteSpace(postResourceParameters.OrderBy))
            {
                var postPropertyMappingDictionary = _propertyMapping.GetPropertyMapping <PostOutputDto, Post>();
                collection = collection.ApplySort(postResourceParameters.OrderBy, postPropertyMappingDictionary);
            }

            return(PageList <Post> .Create(collection, postResourceParameters.PageNumber, postResourceParameters.PageSize));
        }
Esempio n. 2
0
        public PageList <Post> GetPosts(PostQueryFilter filters)
        {
            filters.PageIndex = filters.PageIndex == 0 ? _paginationOptions.DefaultPageIndex : filters.PageIndex;
            filters.PageSize  = filters.PageSize == 0 ? _paginationOptions.DefaultPageSize : filters.PageSize;

            var posts = _unitOfWork.RepoPost.GetAll();

            #region Filtros

            if (filters.UserId.HasValue)
            {
                posts = posts.Where(ele => ele.UserId == filters.UserId);
            }
            if (filters.Date.HasValue)
            {
                posts = posts.Where(ele => ele.Date.ToShortDateString() == filters.Date?.ToShortDateString());
            }
            if (!string.IsNullOrWhiteSpace(filters.Description))
            {
                posts = posts.Where(ele => ele.Description.ToLower().Contains(filters.Description.ToLower()));
            }

            #endregion


            #region Paginacion

            var pagePosts = PageList <Post> .Create(posts, filters.PageIndex, filters.PageSize);

            #endregion


            return(pagePosts);
        }
Esempio n. 3
0
        public async Task <PageList <Correspondencia> > GetAll(CorrespondenciaQueryFilter filters)
        {
            var correspondencias = await _unitOfWork.CorrespondenciaRepository.GetAllRelation();

            if (filters.Consecutivo != null)
            {
                correspondencias = correspondencias.Where(x => x.Consecutivo == filters.Consecutivo);
            }

            if (filters.Tipo != null)
            {
                correspondencias = correspondencias.Where(x => x.Tipo == filters.Tipo);
            }

            if (filters.RemitenteId != null)
            {
                correspondencias = correspondencias.Where(x => x.RemitenteId == filters.RemitenteId);
            }

            if (filters.DestinatarioId != null)
            {
                correspondencias = correspondencias.Where(x => x.DestinatarioId == filters.DestinatarioId);
            }

            var pageCorrespondencias = PageList <Correspondencia> .Create(correspondencias, filters.PageNumber, filters.PageSize);

            return(pageCorrespondencias);
        }
        public PageList <Author> GetAuthors(AuthorResourceParameters authorResourceParameters)
        {
            var collectionBeforePaging =
                _context.Authors.ApplySort(authorResourceParameters.OrderBy,
                                           _propertyMappingService.GetPropertyMapping <AuthorDto, Author>());

            if (!string.IsNullOrEmpty(authorResourceParameters.Genre))
            {
                // trim & ignore casing
                var genreForWhereClause = authorResourceParameters.Genre
                                          .Trim().ToLowerInvariant();
                collectionBeforePaging = collectionBeforePaging
                                         .Where(a => a.Genre.ToLowerInvariant() == genreForWhereClause);
            }

            if (!string.IsNullOrEmpty(authorResourceParameters.SearchQuery))
            {
                // trim & ignore casing
                var searchQueryForWhereClause = authorResourceParameters.SearchQuery
                                                .Trim().ToLowerInvariant();

                collectionBeforePaging = collectionBeforePaging
                                         .Where(a => a.Genre.ToLowerInvariant().Contains(searchQueryForWhereClause) ||
                                                a.FirstName.ToLowerInvariant().Contains(searchQueryForWhereClause) ||
                                                a.LastName.ToLowerInvariant().Contains(searchQueryForWhereClause));
            }

            return(PageList <Author> .Create(collectionBeforePaging,
                                             authorResourceParameters.PageNumber,
                                             authorResourceParameters.PageSize));
        }
Esempio n. 5
0
        public PageList <Author> GetAuthors(AuthorsResourceParameters authorsResourceParameters)
        {
            if (!string.IsNullOrEmpty(authorsResourceParameters.Genre))
            {
                string genre      = authorsResourceParameters.Genre.Trim().ToLowerInvariant();
                var    collection = _authors.OrderBy(a => a.FirstName)
                                    .OrderBy(a => a.LastName)
                                    .Where(item => item.Genre.ToLowerInvariant() == genre).AsQueryable();
                return(PageList <Author> .Create(collection, authorsResourceParameters.PageNumber, authorsResourceParameters.PageSize));
            }
            if (!string.IsNullOrEmpty(authorsResourceParameters.SearchQuery))
            {
                string searchQuery = authorsResourceParameters.SearchQuery.Trim().ToLowerInvariant();
                var    collection  = _authors.OrderBy(a => a.FirstName)
                                     .OrderBy(a => a.LastName)
                                     .Where(item => item.Genre.ToLowerInvariant().Contains(searchQuery) ||
                                            item.FirstName.ToLowerInvariant().Contains(searchQuery) ||
                                            item.LastName.ToLowerInvariant().Contains(searchQuery)).AsQueryable();
                return(PageList <Author> .Create(collection, authorsResourceParameters.PageNumber, authorsResourceParameters.PageSize));
            }
            var collectionBeforePaging = _authors
                                         .OrderBy(a => a.FirstName)
                                         .OrderBy(a => a.LastName);

            return(PageList <Author> .Create(collectionBeforePaging.AsQueryable(), authorsResourceParameters.PageNumber, authorsResourceParameters.PageSize));
        }
        public PageList <Author> GetAuthors(AuthorsResourceParameters authorsResourceParameters)
        {
            if (authorsResourceParameters == null)
            {
                throw new ArgumentNullException(nameof(authorsResourceParameters));
            }

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

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

            if (!string.IsNullOrWhiteSpace(authorsResourceParameters.OrderBy))
            {
                var authorPropertyMappingDictionary =
                    _propertyMappingService.GetPropertyMapping <AuthorDto, Author>();
                collection = collection.ApplySort(authorsResourceParameters.OrderBy, authorPropertyMappingDictionary);
            }
            return(PageList <Author> .Create(collection, authorsResourceParameters.PageNumber, authorsResourceParameters.PageSize));
        }
Esempio n. 7
0
        public async Task <PageList <Company> > GetCompaniesAsync(CompanyParametersDto parameters)
        {
            if (parameters == null)
            {
                throw new ArgumentNullException(nameof(CompanyRepository));
            }

            var data = _db.Company as IQueryable <Company>;

            if (!string.IsNullOrWhiteSpace(parameters.CompanyName))
            {
                data = data.Where(m => m.Name.Equals(parameters.CompanyName));
            }

            if (!string.IsNullOrWhiteSpace(parameters.Search))
            {
                data = data.Where(m => m.Introduction.Contains(parameters.Search) ||
                                  m.Country.Contains(parameters.Search) ||
                                  m.Name.Contains(parameters.Search));
            }

            var mappingDictionary = _service.GetPropertyMapping <CompanyDto, Company>();

            data = data.ApplySort(parameters.OrderBy, mappingDictionary);

            return(await PageList <Company> .Create(data, parameters.PageNum, parameters.PageSize));
        }
Esempio n. 8
0
        /// <summary>
        ///
        /// </summary>
        /// <returns></returns>
        public PageList <Post> Get(PostQueryFilter filters)
        {
            filters.PageNumer = filters.PageNumer == 0 ? _paginationOptions.DefaultPageNumber : filters.PageNumer;
            filters.PageSize  = filters.PageSize == 0 ? _paginationOptions.DefaultPageSize : filters.PageSize;

            var post = _unitOfWork.PostRepository.GetAll();

            if (filters.UserId != null)
            {
                post = post.Where(x => x.UserId == filters.UserId);
            }

            if (filters.Date != null)
            {
                post = post.Where(
                    x => x.Date.ToShortDateString() == filters.Date?.ToShortDateString());
            }

            if (filters.Description != null)
            {
                post = post.Where(
                    x => x.Description.ToLower() == filters.Description.ToLower());
            }


            var pagePost = PageList <Post> .Create(post, filters.PageNumer, filters.PageSize);


            return(pagePost);
        }
Esempio n. 9
0
        public PageList <Ingreso> GetIngresos(IngresoQueryFilter filters)
        {
            var ingresos = _unitOfWork.IngresoRepository.GetAll();

            if (filters.Nombre != null)
            {
                ingresos = ingresos.Where(x => x.Nombre.ToLower().Contains(filters.Nombre.ToLower()));
            }

            if (filters.Apellido != null)
            {
                ingresos = ingresos.Where(x => x.Apellido.ToLower().Contains(filters.Apellido.ToLower()));
            }

            if (filters.Edad != null)
            {
                ingresos = ingresos.Where(x => x.Edad == filters.Edad);
            }

            if (filters.Casa != null)
            {
                ingresos = ingresos.Where(x => x.Casa == filters.Casa);
            }

            var pageIngesos = PageList <Ingreso> .Create(ingresos, filters.PageNumber, filters.PageSize);

            return(pageIngesos);
        }
Esempio n. 10
0
        public static PageListViewModel <T> Create(IEnumerable <T> Employee, int page, int size)
        {
            PageList <T> PaginationTutorials;

            PaginationTutorials = PageList <T> .Create(Employee, page, size);

            return(new PageListViewModel <T>(PaginationTutorials.TotalItems, PaginationTutorials, PaginationTutorials.CurrentPage, PaginationTutorials.TotalPages));
        }
        public PageList <ShortenedUrlEntity> FindAll(UrlResourceParameter urlResourceParameter)
        {
            var urls = _urlShortenerContext.ShortenedUrls.
                       OrderByDescending(u => u.CreationDate);

            return(PageList <ShortenedUrlEntity> .Create(urls,
                                                         urlResourceParameter.PageNumber,
                                                         urlResourceParameter.PageSize));
        }
Esempio n. 12
0
        public PageList <T> GetEntities <T>(Expression <Func <T, bool> > query = null, ResourceCollectionParameters resourceCollectionParameters = null)
        {
            var(pageIdx, pageSize) = resourceCollectionParameters.GetPaginationTuple();
            var entities = GetQueryableEntities <T>();

            var result = query == null ? PageList <T> .Create(entities, pageIdx, pageSize) : PageList <T> .Create(entities.Where(query), pageIdx, pageSize);

            return(result);
        }
Esempio n. 13
0
        public IEnumerable <Event> GetAllWithComments(Expression <Func <Event, bool> > filter, int pageIndex, int pageSize)
        {
            var events = _context.EventSet
                         .Include(e => e.Author)
                         .Include(e => e.Comments)
                         .ThenInclude(p => p.Author)
                         .Where(filter);

            return(PageList <Event> .Create(events, pageIndex, pageSize).AsEnumerable());
        }
Esempio n. 14
0
        public PageList <Employee> Employees(PageSizes sizes)
        {
            var employees = db.Employee.OrderBy(r => r.EmployeeId);

            if (!string.IsNullOrWhiteSpace(sizes.Orderby))
            {
                var employee = propertyMapping.GetPropertyMapping <EmployeesDto, Employee>();
                employees = employees.ApplySort(sizes.Orderby, employee);
            }
            return(PageList <Employee> .Create(employees, sizes.PageNumber, sizes.PageSize));
        }
Esempio n. 15
0
        public PageList <Trivia> GetTrivia(Paging paging)
        {
            var questions = db.Trivias.OrderBy(r => r.Id);

            if (!string.IsNullOrWhiteSpace(paging.Orderby))
            {
                var question = propertyMapping.GetPropertyMapping <QuestionsDto, Trivia>();
                questions = questions.ApplySort(paging.Orderby, question);
            }
            return(PageList <Trivia> .Create(questions, paging.PageNumber, paging.PageSize));
        }
Esempio n. 16
0
        public async Task <PageList <Tag> > GetAll(TagsResourceParameters parameters)
        {
            if (parameters == null)
            {
                throw new ArgumentNullException(nameof(parameters));
            }
            var model = await _context.Tags.Include(c => c.Products).ThenInclude(c => c.Product).ToListAsync();

            var data = _mapper.Map <List <TagEntity>, List <Tag> >(model).AsQueryable();

            return(PageList <Tag> .Create(data, parameters.PageNumber, parameters.PageSize));
        }
Esempio n. 17
0
        public PageList <HmmNote> GetEntities(Expression <Func <HmmNote, bool> > query = null, ResourceCollectionParameters resourceCollectionParameters = null)
        {
            var(pageIdx, pageSize) = resourceCollectionParameters.GetPaginationTuple();
            var notes = query == null
                ? DataContext.Notes.Include(n => n.Author).Include(n => n.Catalog)
                : DataContext.Notes.Include(n => n.Author).Include(n => n.Catalog).Where(query);

            var result = resourceCollectionParameters == null
                ? PageList <HmmNote> .Create(notes, pageIdx, pageSize)
                : PageList <HmmNote> .Create(notes.ApplySort(resourceCollectionParameters.OrderBy), pageIdx, pageSize);

            return(result);
        }
        public ApplicationResult <PageList <UserInfoDto> > GetAll(PaginationParameters paginationParameters)
        {
            var userListInfoReadModel = _userRepository.GetAll(paginationParameters);

            var userListMapped = Mapper.Map <IEnumerable <UserInfoDto> >(userListInfoReadModel);

            var userPagedList = PageList <UserInfoDto> .Create(userListMapped.AsQueryable(),
                                                               paginationParameters.PageNumber, paginationParameters.PageSize);

            return(new ApplicationResult <PageList <UserInfoDto> >()
            {
                Data = userPagedList,
                IsSuccessful = true
            });
        }
Esempio n. 19
0
        public async Task <PageList <Usuario> > GetAll(UsuarioQueryFilter filters)
        {
            var usuarios = await _unitOfWork.UsuarioRepository.GetAll();

            if (filters.UserName != null)
            {
                usuarios = usuarios.Where(x => x.UserName.ToLower().Contains(filters.UserName.ToLower()));
            }

            if (filters.Rol != null)
            {
                usuarios = usuarios.Where(x => x.Rol == filters.Rol);
            }

            var pageTerceros = PageList <Usuario> .Create(usuarios, filters.PageNumber, filters.PageSize);

            return(pageTerceros);
        }
Esempio n. 20
0
        public PageList <User> GetEntities(UserResourceParameter parameter)
        {
            var users = context.Users.AsQueryable <User>();

            if (!string.IsNullOrWhiteSpace(parameter.Username))
            {
                users = users.Where(user => user.Username == parameter.Username.Trim());
            }

            if (!string.IsNullOrWhiteSpace(parameter.searchQuery))
            {
                var searchQuery = parameter.searchQuery.ToLowerInvariant().Trim();
                users = users.Where(user => user.Username.ToLowerInvariant().Contains(searchQuery) || user.Email.ToLowerInvariant().Contains(searchQuery) || user.Name.ToLowerInvariant().Contains(searchQuery));
            }

            users = users.ApplySort <User>(parameter.OrderBy, propertyMappingService.GetPropertyMapping <UserForDisplayDTO, User>());
            return(PageList <User> .Create(users, parameter.PageNumber, parameter.PageSize));
        }
Esempio n. 21
0
        public PageList <User> GetUsers(UsersResourceParameters usersResourceParameters)
        {
            if (usersResourceParameters == null)
            {
                throw new ArgumentNullException(nameof(usersResourceParameters));
            }

            var collection = _context.Users as IQueryable <User>;

            if (!string.IsNullOrWhiteSpace(usersResourceParameters.Email))
            {
                var email = usersResourceParameters.Email.Trim();
                collection = collection.Where(user => user.Email == email);
            }

            if (!string.IsNullOrWhiteSpace(usersResourceParameters.SearchQuery))
            {
                var searchQuery = usersResourceParameters.SearchQuery.Trim();
                collection = collection.Where(user => user.Email.Contains(searchQuery) ||
                                              user.FirstName.Contains(searchQuery) ||
                                              user.LastName.Contains(searchQuery));
            }

            if (!string.IsNullOrWhiteSpace(usersResourceParameters.SearchQuery))
            {
                var searchQuery = usersResourceParameters.SearchQuery.Trim();
                collection = collection.Where(user => user.Email.Contains(searchQuery) ||
                                              user.FirstName.Contains(searchQuery) ||
                                              user.LastName.Contains(searchQuery));
            }

            if (!string.IsNullOrWhiteSpace(usersResourceParameters.OrderBy))
            {
                // get mapping dictionary
                var userPropertyMappingDictionary = _propertyMappingService.GetPropertyMapping <UserDto, User>();

                collection = collection.ApplySort(usersResourceParameters.OrderBy, userPropertyMappingDictionary);
            }

            return(PageList <User> .Create(collection,
                                           usersResourceParameters.PageNumber,
                                           usersResourceParameters.PageSize));
        }
        public PageList <Video> GetEntities(string user, VideoResourceParameters parameters)
        {
            var collectionBeforePaging = context.Videos.OrderBy(x => x.UploadedDate).AsQueryable();

            collectionBeforePaging = context.Videos.ApplySort(parameters.OrderBy, propertyMappingService.GetPropertyMapping <VideoForDisplayDTO, Video>());
            if (!string.IsNullOrEmpty(parameters.Title))
            {
                var filterClause = parameters.Title.Trim().ToLowerInvariant();
                collectionBeforePaging = collectionBeforePaging.Where(x => x.Title.ToLowerInvariant() == filterClause);
            }

            if (!string.IsNullOrEmpty(parameters.searchQuery))
            {
                var searchQuery = parameters.searchQuery.Trim().ToLowerInvariant();
                collectionBeforePaging = collectionBeforePaging.Where(a => a.Properties.ToLowerInvariant().Contains(searchQuery) || a.Title.ToLowerInvariant().Contains(searchQuery) || a.Username.Contains(searchQuery));
            }
            return(PageList <Video> .Create(collectionBeforePaging, parameters.pageNumber, parameters.PageSize));

            // return context.Videos.Where(x => x.Username == user).OrderBy(x => x.UploadedDate).Skip(parameters.PageSize * (parameters.pageNumber - 1)).Take(parameters.PageSize).ToList();
        }
Esempio n. 23
0
        public PageList <User> GetUsers(UserQueryFilter filter)
        {
            filter.PageNumber = filter.PageNumber == 0 ? _paginationOptions.DefaultPageNumber : filter.PageNumber;
            filter.PageSize   = filter.PageSize == 0 ? _paginationOptions.DefaultPageSize : filter.PageSize;
            var data = _unitofWork.UserRepository.GetUsers();

            if (filter.UserId != null)
            {
                data = data.Where(x => x.IdUser == filter.UserId);
            }
            if (filter.Name != null)
            {
                data = data.Where(x => x.Name == filter.Name);
            }


            var userPage = PageList <User> .Create(data, filter.PageNumber, filter.PageSize);

            return(userPage);
        }
Esempio n. 24
0
        public PageList <Post> GetPosts(PostQueryFilter filters)
        {
            var posts = _postRepository.GetPosts();

            if (filters.UserId != null)
            {
                posts = posts.Where(x => x.UserId == filters.UserId);
            }
            if (filters.Date != null)
            {
                posts = posts.Where(x => x.Date.ToShortDateString() == filters.Date?.ToShortDateString());
            }
            if (filters.Description != null)
            {
                posts = posts.Where(x => x.Description.ToLower().Contains(filters.Description.ToLower()));
            }
            var pagedPosts = PageList <Post> .Create(posts, filters.PageNumber, filters.PageSize);

            return(pagedPosts);
        }
        public async Task <PageList <Organization> > GetOrganizations(OrganizationResourceParameters organizationResourceParameters)
        {
            var organizationBeforePaging =
                _context.Organizations.ApplySort(organizationResourceParameters.OrderBy, _propertyMappingService.GetPropertyMapping <OrganizationDto, Organization>());

            if (!string.IsNullOrEmpty(organizationResourceParameters.Name))
            {
                var descriptionForWhereClause = organizationResourceParameters.Name.Trim().ToLowerInvariant();
                organizationBeforePaging =
                    organizationBeforePaging.Where(o => o.Name.ToLowerInvariant().Contains(descriptionForWhereClause));
            }

            var organizations = await PageList <Organization>
                                .Create(organizationBeforePaging
                                        , organizationResourceParameters.CurrentPage
                                        , organizationResourceParameters.PageSize
                                        );

            return(organizations);
        }
        public PageList <Band> GetBands(BandResourceParameters bandResourceParameters)
        {
            if (bandResourceParameters == null)
            {
                throw new ArgumentNullException(nameof(bandResourceParameters));
            }

            //if (string.IsNullOrWhiteSpace(bandResourceParameters.MainGenre) && string.IsNullOrWhiteSpace(bandResourceParameters.SearchQuery))
            //    return await GetBands();

            var collection = _context.Bands as IQueryable <Band>;

            if (!string.IsNullOrWhiteSpace(bandResourceParameters.MainGenre))
            {
                // Doing mainGenre filtering
                var mainGenre = bandResourceParameters.MainGenre.Trim();
                collection = collection.Where(b => b.MainGenre == mainGenre);
            }

            if (!string.IsNullOrWhiteSpace(bandResourceParameters.SearchQuery))
            {
                var searhcQuery = bandResourceParameters.SearchQuery.Trim().ToLower();
                collection = collection.Where(b => b.Name.ToLower().Contains(searhcQuery));
            }

            // Do Sorting here

            if (!string.IsNullOrWhiteSpace(bandResourceParameters.OrderBy))
            {
                var bandPropertyMappingDictionary = _propertyMappingService.GetPropertyMappig <BandDto, Band>(); // Get the band PropertyMapping
                collection = collection.ApplySort(bandResourceParameters.OrderBy, bandPropertyMappingDictionary);
            }


            return(PageList <Band> .Create(collection, bandResourceParameters.PageNumber, bandResourceParameters.PageSize));

            //return await collection
            //    .Skip(bandResourceParameters.PageSize * (bandResourceParameters.PageNumber - 1)) // If it's the first page, then skip 0
            //    .Take(bandResourceParameters.PageSize)
            //    .ToListAsync();
        }
Esempio n. 27
0
        public PageList <Comment> GetCommentsForPost(Guid postId, CommentResourceParameters commentResourceParameters)
        {
            if (postId == Guid.Empty)
            {
                throw new ArgumentNullException(nameof(postId));
            }


            var collection = _context.Comments as IQueryable <Comment>;

            // No SearchingQuery Needed

            collection = collection.Include(c => c.Author).Where(c => c.BelongPostId == postId);

            if (!string.IsNullOrWhiteSpace(commentResourceParameters.OrderBy))
            {
                var commentPropertyMappingDictionary = _propertyMapping.GetPropertyMapping <PostOutputDto, Post>();
                collection = collection.ApplySort(commentResourceParameters.OrderBy, commentPropertyMappingDictionary);
            }

            return(PageList <Comment> .Create(collection, commentResourceParameters.PageNumber, commentResourceParameters.PageSize));
        }
        public PageList <Author> GetAuthors(AuthorResourceParameters authorResourceParameters)
        {
            string mainCategory = authorResourceParameters.MainCategory;
            string searchQuery  = authorResourceParameters.SearchQuery;

            //if (string.IsNullOrEmpty(mainCategory) && string.IsNullOrEmpty(searchQuery))
            //    return GetAuthors();

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

            if (!string.IsNullOrEmpty(mainCategory))
            {
                mainCategory = mainCategory.Trim();
                collection   = collection.Where(a => a.MainCategory == mainCategory);
            }

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

            if (!string.IsNullOrWhiteSpace(authorResourceParameters.OrderBy))
            {
                //get property mapping dictionary
                var authorPropertyMappingDictionary = _propertyMappingService.GetPropertyMapping <AuthorDto, Author>();
                collection = collection.ApplySort(authorResourceParameters.OrderBy, authorPropertyMappingDictionary);
            }

            //paging and page size
            //return collection.
            //    Skip(authorResourceParameters.PageSize*(authorResourceParameters.PageNumber-1))
            //    .Take(authorResourceParameters.PageSize)
            //    .ToList();

            return(PageList <Author> .Create(collection, authorResourceParameters.PageNumber, authorResourceParameters.PageSize));
        }
Esempio n. 29
0
        public async Task <PageList <Tercero> > GetAll(TerceroQueryFilter filters)
        {
            var terceros = await _unitOfWork.TerceroRepository.GetAll();

            if (filters.Identificaion != null)
            {
                terceros = terceros.Where(x => x.Identificaion.ToLower().Contains(filters.Identificaion.ToLower()));
            }

            if (filters.Nombres != null)
            {
                terceros = terceros.Where(x => x.Nombres.ToLower().Contains(filters.Nombres.ToLower()));
            }

            if (filters.Apellidos != null)
            {
                terceros = terceros.Where(x => x.Apellidos != null && x.Apellidos.ToLower().Contains(filters.Apellidos.ToLower()));
            }

            if (filters.Correo != null)
            {
                terceros = terceros.Where(x => x.Correo != null && x.Correo.ToLower().Contains(filters.Correo.ToLower()));
            }

            if (filters.Direccion != null)
            {
                terceros = terceros.Where(x => x.Direccion != null && x.Direccion.ToLower().Contains(filters.Direccion.ToLower()));
            }

            if (filters.Telefono != null)
            {
                terceros = terceros.Where(x => x.Telefono != null && x.Telefono.ToLower().Contains(filters.Telefono.ToLower()));
            }

            var pageTerceros = PageList <Tercero> .Create(terceros, filters.PageNumber, filters.PageSize);

            return(pageTerceros);
        }
        public PageList <ServiceInfo> GetServiceInfos(ServiceInfoResourceParameters serviceInfoResourceParameters)
        {
            if (serviceInfoResourceParameters == null)
            {
                throw new ArgumentNullException(nameof(serviceInfoResourceParameters));
            }

            var collection = _context.ServiceInfos as IQueryable <ServiceInfo>;

            if (!string.IsNullOrWhiteSpace(serviceInfoResourceParameters.SearchQuery))
            {
                string searchinQuery = serviceInfoResourceParameters.SearchQuery.Trim().ToLower();
                collection = collection.Where(s => s.CenterName.ToLower().Contains(searchinQuery) || s.LocalCenterName.ToLower().Contains(searchinQuery));
            }

            if (!string.IsNullOrWhiteSpace(serviceInfoResourceParameters.OrderBy))
            {
                var postPropertyMappingDictionary = _propertyMapping.GetPropertyMapping <ServiceInfoOutputDto, ServiceInfo>();
                collection = collection.ApplySort(serviceInfoResourceParameters.OrderBy, postPropertyMappingDictionary);
            }

            return(PageList <ServiceInfo> .Create(collection, serviceInfoResourceParameters.PageNumber, serviceInfoResourceParameters.PageSize));
        }