public async Task <IActionResult> Index() { var applicationDbContext = _context.Product.Include(p => p.Company); var productFilter = from p in _context.Product select p; productFilter = productFilter.OrderByDescending(o => o.Price); int pageSize = 6; return(View(await PaginationList <Product> .CreateAsync(productFilter.AsNoTracking(), 1, pageSize))); }
public _ContentFeedViewModel(IEnumerable<Content> content, Guid? authorId, string groupUrl, int contentPerPage = 5) { AuthorId = authorId; GroupUrl = groupUrl; if (authorId.HasValue) content = content.OrderByDescending(x => x.IsUserAttached(authorId.Value)); if (!string.IsNullOrEmpty(groupUrl)) content = content.OrderByDescending(x => x.IsGroupAttached(groupUrl)); FeedContent = new PaginationList<_ContentFeed_ContentViewModel, Content>(content, contentPerPage, x => new _ContentFeed_ContentViewModel(x)); }
public PaginationList <Palavra> ObterPalavras(PalavraUrlQuery query) { var lista = new PaginationList <Palavra>(); var item = _banco.Palavras.AsNoTracking().AsQueryable(); if (query.Data.HasValue) { item = item.Where(a => a.Criado > query.Data.Value || a.Atualizado > query.Data.Value); } lista.Results.AddRange(item.ToArray()); return(lista); }
public ActionResult ObterTodas([FromQuery] PalavraUrlQuery query)//A data será para armazenar no app, para depois o aplicativo atualizar as palavras novas. { var item = _repository.ObterPalavras(query); if (item.Results.Count == 0) { return(NotFound()); } PaginationList <PalavraDTO> lista = CriarLinksListPalavraDTO(query, item); return(Ok(lista)); //return new JsonResult(_banco.Palavras); }
public virtual PaginationList <T> GetPagerByUser(string userName, Expression <Func <T, bool> > condition, int start, int takeCount) { using (var db = new U()) { var query = db.GetTable <T>().Where(p => db.GetDepsByUserName(userName).Select(i => i.DEPT_INFO_ID).Contains(p.DEPID)).Where(condition); var items = query.Skip(start).Take(takeCount).ToList(); var rs = new PaginationList <T>(items) { TotalCount = query.Count(), PageSize = takeCount }; return(rs); } }
public virtual PaginationList <T> GetPager(Expression <Func <T, bool> > condition, string sort, string orderBy, int start, int takeCount) { using (var db = new U()) { var query = db.GetTable <T>().Where(condition); var items = query.BuildOrderClause(sort, orderBy).Skip(start).Take(takeCount).ToList(); var rs = new PaginationList <T>(items) { TotalCount = query.Count(), PageSize = takeCount }; return(rs); } }
public IActionResult GetAll([FromQuery] WordQueryUrl query) { var item = _repository.GetAll(query); if (item.Results.Count == 0) { return(StatusCode(404)); } PaginationList <WordDTO> List = CreateLinksListWordDTO(query, item); return(Ok(List)); }
public virtual PaginationList <TResult> GetPagerByUser <TResult, TKey>(string createdBy, Expression <Func <T, TResult> > selector, Expression <Func <T, bool> > condition, Func <DataLoadOptions> loadOptions, Expression <Func <T, TKey> > orderBy, int start, int takeCount) { using (var db = new U()) { var query = db.GetTable <T>().Where(p => db.GetUsersByUserName(createdBy).Select(i => i.USER_INFO_NAME).Contains(p.CREATEDBY)).Where(condition); var items = query.OrderBy(orderBy).Select(selector).Skip(start).Take(takeCount).ToList(); var rs = new PaginationList <TResult>(items) { TotalCount = query.Count(), PageSize = takeCount }; return(rs); } }
public ActionResult GetWords([FromQuery] WordUrlQuery query) { var words = _wordRepository.GetWords(query); if (words.Results.Count == 0) { return(NotFound()); } PaginationList <WordDTO> list = CreateLinks(query, words); return(Ok(list)); }
public IActionResult FindAllWords([FromQuery] WordUrlQuery query) { var item = _repository.FindAllWordsAsync(query); if (item.Results.Count == 0) { return(NotFound()); } PaginationList <DTOWord> list = CreateLinkListDTOWord(query, item); return(Ok(list)); }
public virtual PaginationList <T> GetPagerByUser(string createdBy, Expression <Func <T, bool> > condition, string sort, string orderBy, int start, int takeCount) { using (var db = new U()) { var query = db.GetTable <T>().Where(p => db.GetUsersByUserName(createdBy).Select(i => i.USER_INFO_NAME).Contains(p.CREATEDBY)).Where(condition); var items = query.BuildOrderClause(sort, orderBy).Skip(start).Take(takeCount).ToList(); var rs = new PaginationList <T>(items) { TotalCount = query.Count(), PageSize = takeCount }; return(rs); } }
public ActionResult ObterTodas([FromQuery] PalavraUrlQuery query) { var item = _repository.ObterPalavras(query); if (item.Results.Count == 0) { return(NotFound()); } PaginationList <PalavraDTO> lista = CriarLinksListPalavraDTO(query, item); return(Ok(lista)); }
public virtual PaginationList <TResult> GetPager <TResult>(Expression <Func <T, TResult> > selector, Expression <Func <T, bool> > condition, int start, int takeCount) { using (var db = new U()) { var query = db.GetTable <T>().Where(condition); var items = query.Select(selector).Skip(start).Take(takeCount).ToList(); var rs = new PaginationList <TResult>(items) { TotalCount = query.Count(), PageSize = takeCount }; return(rs); } }
public async Task <PaginationList <TouristRoute> > GetTouristRoutesAsync( string keyword, string operatorType, int?ratingValue, int pageSize, int pageNumber, string orderBy) { IQueryable <TouristRoute> result = _context .TouristRoutes .Include(t => t.TouristRoutePictures); if (!string.IsNullOrWhiteSpace(keyword)) { keyword = keyword.Trim(); result = result.Where(t => t.Title.Contains(keyword)); } if (ratingValue >= 0) { result = operatorType switch { "largerThan" => result.Where(t => t.Rating >= ratingValue), "lessThan" => result.Where(t => t.Rating < ratingValue), _ => result.Where(t => t.Rating == ratingValue), }; } //var skip = (pageNumber -1) * pageSize; //result = result.Skip(skip); //result = result.Take(pageSize); //include vs join --> eager load if (!string.IsNullOrWhiteSpace(orderBy)) { //if (orderBy.ToLowerInvariant() == "OriginalPrice".ToLowerInvariant()) //{ // result = result.OrderBy(t => t.OriginalPrice); //} var touristRouteMappingDictionary = _propertyMappingService .GetPropertyMapping <TouristRouteDto, TouristRoute>(); result = result.ApplySort(orderBy, touristRouteMappingDictionary); } return(await PaginationList <TouristRoute> .CreateAsync( pageNumber, pageSize, result)); }
public async Task <PaginationList <Author> > GetFilteredAuthors(BookStoreContext context, AuthorFilterArgs filterArgs, int?catalogPage) { CurrentSortOrder = !string.IsNullOrEmpty(filterArgs.SortOrder) ? "desc" : "asc"; var authors = context.Author.Include(author => author.Book).Select(author => author); authors = GetFilteredAuthorsByGenre(authors, filterArgs.Genre); authors = GetFilteredAuthorsBySearchString(authors, filterArgs.SearchString, ref catalogPage); authors = SelectSortOrder(authors, filterArgs.SortOrder); return(await PaginationList <Author> .CreateAsync(authors.AsNoTracking(), catalogPage ?? 1, pageSize : 3)); }
public ActionResult get([FromQuery] QueryPaginacao query) { var item = _repository.get(query); if (item.Results.Count == 0) { return(NotFound()); } PaginationList <PalavraDTO> lista = CriarLinksListPalavraDTO(query, item); return(Ok(lista)); }
public virtual PaginationList <TResult> GetPagerByUser <TResult>(string userName, Expression <Func <T, TResult> > selector, Expression <Func <T, bool> > condition, Func <DataLoadOptions> loadOptions, string sort, string orderBy, int start, int takeCount) { using (var db = new U()) { db.LoadOptions = loadOptions(); var query = db.GetTable <T>().Where(p => db.GetDepsByUserName(userName).Select(i => i.DEPT_INFO_ID).Contains(p.DEPID)).Where(condition); var items = query.BuildOrderClause(sort, orderBy).Select(selector).Skip(start).Take(takeCount).ToList(); var rs = new PaginationList <TResult>(items) { TotalCount = query.Count(), PageSize = takeCount }; return(rs); } }
public async Task <PaginationList <Book> > GetFilteredBooks(BookStoreContext context, BookFilterArgs filterArgs, int?catalogPage) { var books = context.Book.Include(book => book.Author).Select(book => book); books = GetFilteredBooksBySearchString(books, filterArgs.SearchString, ref catalogPage); books = GetFilteredBooksByGenre(books, filterArgs.Genre); books = GetFilteredBooksByAuthor(books, filterArgs.Author); books = SwitchBookCondition(books, filterArgs.BookCondition); return(await PaginationList <Book> .CreateAsync(books.AsNoTracking(), catalogPage ?? 1, pageSize : 3)); }
public virtual PaginationList <T> GetPager <TKey>(Expression <Func <T, bool> > condition, Expression <Func <T, TKey> > orderBy, Func <DataLoadOptions> howToGetLoadOptions, int start, int takeCount) { using (var db = new U()) { db.LoadOptions = howToGetLoadOptions(); var query = db.GetTable <T>().Where(condition); var items = query.OrderBy(orderBy).Skip(start).Take(takeCount).ToList(); var rs = new PaginationList <T>(items) { TotalCount = query.Count(), PageSize = takeCount }; return(rs); } }
//[PlayableAuthorizationFilter] public async Task <IHttpActionResult> GetCycles(Int32 state = 0, Int32 page = 1, Int32 top = 5, String orderby = nameof(CyclesBE.idcycle), String ascending = "asc", String name = "") { var count = 0; List <CyclesBE> query = _services.GetAll(state, page, top, orderby, ascending, name, ref count); //HybridDictionary myfilters = new HybridDictionary(); //if (state != 0) // myfilters.Add("state", state); //if (idprincipal != 0) myfilters.Add("idbusiness", idprincipal); //ChallengeDTOCollectionRepresentation dt = new ChallengeDTOCollectionRepresentation(dtos.ToList(), //FilterHelper.GenerateFilter(myfilters, top, orderby, ascending), page, count, top); PaginationList <CyclesBE> mylist = new PaginationList <CyclesBE>(query, count); return(Ok(mylist)); }
public ActionResult ObterPalavras([FromQuery] PalavraUrlQuery query) { var item = _repository.ObterPalavras(query); if (item.Results.Count() == 0) { return(NotFound()); } PaginationList <PalavraDTO> lista = CriarLinksPalavraDTO(query, item); return(Ok(lista)); //Outra opção de retorno //return new JsonResult( _banco.Palavras ); }
public _ContentFeedViewModel(IEnumerable <Content> content, Guid?authorId, string groupUrl, int contentPerPage = 5) { AuthorId = authorId; GroupUrl = groupUrl; if (authorId.HasValue) { content = content.OrderByDescending(x => x.IsUserAttached(authorId.Value)); } if (!string.IsNullOrEmpty(groupUrl)) { content = content.OrderByDescending(x => x.IsGroupAttached(groupUrl)); } FeedContent = new PaginationList <_ContentFeed_ContentViewModel, Content>(content, contentPerPage, x => new _ContentFeed_ContentViewModel(x)); }
public async Task <PaginationList <Order> > GetOrdersByUserIdAsync( string userId, int pageSize, int pageNumber ) { IQueryable <Order> result = _context .Orders.Where(o => o.UserId == userId); return(await PaginationList <Order> .CreateAsync(pageNumber, pageSize, result)); //return await _context // .Orders // .Where(o => o.UserId == userId) // .ToListAsync(); }
// GET: api/Users public IHttpActionResult GetPaginatedUsers() { PaginationMeta paginationMeta = new PaginationMeta(); paginationMeta.Page = 111; paginationMeta.PageSize = 222; paginationMeta.SearchTerm = ""; paginationMeta.TotalPagesCount = 301; paginationMeta.TotalRecordsCount = 402; PaginationList <User> pagedList = new PaginationList <User>(); pagedList.PaginationResponseData = UsersServiceDapper.GetPaginatedUsers(); pagedList.PaginationMetaData = paginationMeta; return(Ok(pagedList)); }
public async Task <ResponseModel> GetUnPublishedAsyncPagination(Expression <Func <Post, bool> > filter = null, Expression <Func <Post, bool> > filterByUser = null, Func <IQueryable <Post>, IOrderedQueryable <Post> > orderBy = null, string includeProperties = "", int page = 1, int pageSize = 10) { try { var query = repository.GetUnPublishedToFilter(filter: filter, filterByUser: filterByUser, includeProperties: includeProperties); if (orderBy != null) { query = orderBy(query); } var result = await PaginationList <Post> .CreateAsync(query.AsNoTracking(), page, pageSize); return(ResponseData.Response(Status: 200, Data: result, Message: "Success")); } catch (Exception ex) { return(ResponseData.Response(Status: 302, Data: null, Message: "Error: " + ex.Message)); } }
public async Task <PaginationList <Drink> > GetDrinksAsync(string keyword, string country, string brand, string type, string priceOperator, double?priceValue, string orderBy, int pageNumber, int pageSize) { var drinks = _context .Drinks .Include(d => d.DrinkPictures) .AsQueryable <Drink>(); if (!string.IsNullOrEmpty(keyword)) { drinks = drinks.Where(d => d.Title.Contains(keyword)); } if (!string.IsNullOrEmpty(country)) { drinks = drinks.Where(d => d.Country.Contains(country)); } if (!string.IsNullOrEmpty(brand)) { drinks = drinks.Where(d => d.Brand.Contains(brand)); } if (!string.IsNullOrEmpty(type)) { drinks = drinks.Where(d => d.Title.Contains(type)); } if (!string.IsNullOrEmpty(priceOperator) && priceValue.HasValue) { drinks = priceOperator switch { "lessthan" => drinks.Where(d => d.Price < priceValue), "greaterthan" => drinks.Where(d => d.Price > priceValue), _ => drinks.Where(d => d.Price == priceValue), }; } if (!string.IsNullOrEmpty(orderBy)) { var mapping = _propertyMappingService.GetPropertyMapping <DrinkDTO, Drink>(); drinks = drinks.ApplySort(orderBy, mapping); } return(await PaginationList <Drink> .Create(pageNumber, pageSize, drinks)); }
public OperationResult <PaginationList <Author> > GetAuthors(AuthorsQueryParamters queryParamters) { bool hasOrderBy = queryParamters.OrderBy != null; bool hasSearchQuery = queryParamters.SearchQuery != null; try { using (CourseLibraryContext context = new CourseLibraryContext(options)) { var collection = context.Authors as IQueryable <Author>; if (hasSearchQuery) { collection = collection.Where(a => a.FirstName.Contains(queryParamters.SearchQuery) || a.LastName.Contains(queryParamters.SearchQuery) || a.MainCategory.Contains(queryParamters.SearchQuery)); } if (hasOrderBy) { string orderstring = filterationService.GetFiltrationString <AuthorDto, Author>(queryParamters.OrderBy); collection = collection.OrderBy(orderstring); } logger.Info($"Request authors with query paramters : {queryParamters}"); //TODO add pagination here PaginationList <Author> result = PaginationList <Author> .CreatePagination(collection, queryParamters.PageSize, queryParamters.PageNumber); return(new SuccessOperationResult <PaginationList <Author> > { Result = result, Code = ConstOperationCodes.SUCCESS_OPERATION }); } } catch (Exception e) { logger.Error($"Error in Course library Service GetAuthors : {e}"); return(new FailedOperationResult <PaginationList <Author> > { Code = ConstOperationCodes.FAILED_OPERATION }); } }
public _CommentsViewModel(User user, bool?invert = null) { if (user != null) { Invert = invert; UserId = user.Id; var comments = user.Comments.Where(x => !x.IsHidden); if (invert.HasValue && invert.Value) { comments = comments.OrderBy(c => c.DateTime); } else { comments = comments.OrderByDescending(c => c.DateTime); } Comments = comments.ToPaginationList(ConstHelper.CommentsPerPage, x => new _Comments_CommentViewModel(x)); } }
public async Task <IActionResult> Index(string searchString, string sortOrder, string filter, int?pageNumber) { var applicationDbContext = _context.Product.Include(p => p.Company); ViewData["Filter"] = searchString; ViewData["PriceSort"] = sortOrder == "Price" ? "Price_desc" : "Price"; if (searchString != null) { pageNumber = 1; } else { searchString = filter; } var productFilter = from p in _context.Product select p; if (!String.IsNullOrEmpty(searchString)) { productFilter = productFilter.Where(s => s.Name.Contains(searchString)); } switch (sortOrder) { case "Price": productFilter = productFilter.OrderBy(o => o.Price); break; case "Price_desc": productFilter = productFilter.OrderByDescending(o => o.Price); break; default: productFilter = productFilter.OrderBy(o => o.Name); break; } int pageSize = 5; return(View(await PaginationList <Product> .CreateAsync(productFilter.AsNoTracking(), pageNumber ?? 1, pageSize))); }
public async Task <PaginationList <TouristRoute> > GetTouristRoutesAsync( string keyword, string ratingOperator, int?ratingValue, int pageSize, int pageNumber, string orderBy ) { IQueryable <TouristRoute> result = _context .TouristRoutes .Include(t => t.TouristRoutePictures); if (!string.IsNullOrWhiteSpace(keyword)) { keyword = keyword.Trim(); result = result.Where(t => t.Title.Contains(keyword)); } if (ratingValue >= 0) { result = ratingOperator switch { "largerThan" => result.Where(t => t.Rating >= ratingValue), "lessThan" => result.Where(t => t.Rating <= ratingValue), _ => result.Where(t => t.Rating == ratingValue), }; } if (!string.IsNullOrWhiteSpace(orderBy)) { var touristRouteMappingDictionary = _propertyMappingService .GetPropertyMapping <TouristRouteDto, TouristRoute>(); result = result.ApplySort(orderBy, touristRouteMappingDictionary); } // include vs join return(await PaginationList <TouristRoute> .CreateAsync(pageNumber, pageSize, result)); }
public async Task <OperationResult <PaginationList <Course> > > GetCourses(CoursesQueryParameters queryParameters) { bool hasOrderBy = queryParameters.OrderBy != null; bool hasSearchQuery = queryParameters.SearchQuery != null; using (CourseLibraryContext context = new CourseLibraryContext(options)) { try { var collection = context.Courses as IQueryable <Course>; if (hasSearchQuery) { collection = context.Courses.Where(c => c.Title.Contains(queryParameters.SearchQuery)); } if (hasOrderBy) { string orderString = filterationService.GetFiltrationString <CourseDto, Course>(queryParameters.OrderBy); collection = context.Courses.OrderBy(orderString); } var courses = PaginationList <Course> .CreatePagination(collection, queryParameters.PageSize, queryParameters.PageNumber); return(new SuccessOperationResult <PaginationList <Course> > { Result = courses, Code = ConstOperationCodes.SUCCESS_OPERATION }); } catch (Exception e) { logger.Error($"error in courses library service get courses : {e.Message}"); return(new FailedOperationResult <PaginationList <Course> > { Code = ConstOperationCodes.FAILED_OPERATION }); } } }
public _ContentFeedViewModel() { FeedContent = new PaginationList<_ContentFeed_ContentViewModel, Content>(new List<Content>(), 0, x => new _ContentFeed_ContentViewModel(x)); }