public async Task <PagedResults <Room> > GetRoomsAsync( PagingOptions pagingOptions, SortOptions <Room, RoomEntity> sortOptions, SearchOptions <Room, RoomEntity> searchOptions) { //pull all rooms out of context and map each one of it to room resource - instead of duplicating code in GetRoomAsync here - we can use queryableExtentions in automapper to project all at once IQueryable <RoomEntity> query = _context.Rooms; query = searchOptions.Apply(query); //apply sort options to query before it goes and hits the database. //Apply method is used to update this query with any additional stuff we need to add sorting to the query before it goes to the database query = sortOptions.Apply(query); var size = await query.CountAsync(); var items = await query .Skip(pagingOptions.Offset.Value) .Take(pagingOptions.Limit.Value) .ProjectTo <Room>(_mappingConfiguration)//provide mapping configuration to ProjectTo, for which we need to inject IConfigurationProvider from AutoMapper .ToArrayAsync(); return(new PagedResults <Room> { Items = items, TotalSize = size }); }
public async Task <PagedResults <Template> > GetTemplatesAsync( PagingOptions pagingOptions, SortOptions <Template, TemplateEntity> sortOptions, SearchOptions <Template, TemplateEntity> searchOptions, CancellationToken ct) { IQueryable <TemplateEntity> query = _context.Template; query = searchOptions.Apply(query); query = sortOptions.Apply(query); var allTemplates = await query .ProjectTo <Template>() .ToListAsync(); var pagedTemplates = allTemplates .Skip(pagingOptions.Offset.Value) .Take(pagingOptions.Limit.Value); return(new PagedResults <Template> { Items = pagedTemplates, TotalSize = allTemplates.Count }); }
public async Task <PagedResults <User> > GetUsersAsync( PagingOptions pagingOptions, SortOptions <User, UserEntity> sortOptions, SearchOptions <User, UserEntity> searchOptions, CancellationToken ct) { IQueryable <UserEntity> query = _userManager.Users; query = searchOptions.Apply(query); query = sortOptions.Apply(query); var size = await query.CountAsync(ct); var items = await query .Skip(pagingOptions.Offset.Value) .Take(pagingOptions.Limit.Value) .ProjectTo <User>() .ToArrayAsync(ct); return(new PagedResults <User> { Items = items, TotalSize = size }); }
public async Task <PagedResults <RoomResource> > GetRoomsAsync( PagingOptions pagingOptions, SortOptions <RoomResource, RoomEntity> sortOptions, SearchOptions <RoomResource, RoomEntity> searchOptions, CancellationToken cancellationToken) { IQueryable <RoomEntity> query = _context.Rooms; query = searchOptions.Apply(query); query = sortOptions.Apply(query); var size = await query.CountAsync(cancellationToken); var items = await query .Skip(pagingOptions.Offset.Value) .Take(pagingOptions.Limit.Value) .ProjectTo <RoomResource>() .ToArrayAsync(cancellationToken); return(new PagedResults <RoomResource> { Items = items, TotalSize = size }); }
public async Task <PagedResult <SAPEmployee> > GetSAPEmployeesAsync( PagingOptions pagingOptions, SearchOptions <SAPEmployee, SAPEmployeeEntity> searchOptions, SortOptions <SAPEmployee, SAPEmployeeEntity> sortOptions, CancellationToken ct) { IQueryable <SAPEmployeeEntity> query = _dbContext.SAPEmployees .Where(emp => emp.UserName != null && emp.UserName.Trim() != ""); query = searchOptions.Apply(query); query = sortOptions.Apply(query); var size = await query.CountAsync(ct); var items = await query .Skip(pagingOptions.Offset.Value) .Take(pagingOptions.Limit.Value) .ProjectTo <SAPEmployee>().ToArrayAsync(ct); return(new PagedResult <SAPEmployee> { Items = items, Size = size }); }
public async Task <PagedResults <EndpointEntity> > GetEndpointsByOwnerIdAsync(Guid ownerId, PagingOptions pagingOptions, SortOptions <EndpointViewModel, EndpointEntity> sortOptions, SearchOptions <EndpointViewModel, EndpointEntity> searchOptions, CancellationToken ct) { IQueryable <EndpointEntity> query = _context.Endpoints .Where(r => r.Owner.IdentityId == ownerId) .Include(r => r.Owner) .Include(r => r.Client); query = searchOptions.Apply(query); query = sortOptions.Apply(query); var size = await query.CountAsync(ct); var items = await query .Skip(pagingOptions.Offset.Value) .Take(pagingOptions.Limit.Value) .ToArrayAsync(ct); return(new PagedResults <EndpointEntity> { Items = items, TotalSize = size }); }
public async Task <PagedResults <User> > GetUsersByRoleAsync( PagingOptions pagingOptions, SortOptions <User, UserEntity> sortOptions, SearchOptions <User, UserEntity> searchOptions, string role, CancellationToken ct) { var users = await _userManager.GetUsersInRoleAsync(role); IQueryable <UserEntity> query = users.AsQueryable(); query = searchOptions.Apply(query); query = sortOptions.Apply(query); var size = query.Count(); var items = query .Skip(pagingOptions.Offset.Value) .Take(pagingOptions.Limit.Value) .ProjectTo <User>(_mappingConfiguration) .ToArray(); return(new PagedResults <User> { Items = items, TotalSize = size }); }
public async Task <Collection <EventEntry> > GetEntriesByEventAsync( int eventId, SortOptions <EventEntry, EventEntryEntity> sortOptions, SearchOptions <EventEntry, EventEntryEntity> searchOptions, CancellationToken ct) { IQueryable <EventEntryEntity> query = _context.EventEntries.Where(r => r.eventId == eventId); query = searchOptions.Apply(query); query = sortOptions.Apply(query); var items = await query .ProjectTo <EventEntry>() .ToArrayAsync(ct); AttemptsProcessor ap = new AttemptsProcessor(_context, eventId); foreach (var ent in items) { EventMarks em = await ap.GetAttempts(ent.entryId, ct); ent.Marks = em.Attempts; ent.MarkType = em.MarkType; } return(new Collection <EventEntry> { Value = items }); }
public async Task <PagedResults <Event> > GetAllByByPocAsync( PagingOptions pagingOptions, SortOptions <Event, EventEntity> sortOptions, SearchOptions <Event, EventEntity> searchOptions, long pocId, CancellationToken ct) { IQueryable <EventEntity> query = _context.Events.AsNoTracking().Where(x => x.Poc.Any(p => p.PocId.Equals(pocId))); query = searchOptions.Apply(query); query = sortOptions.Apply(query); var size = await query.CountAsync(ct); var items = await query .Include(x => x.Poc) .Include(x => x.Participant) .Skip(pagingOptions.Offset.Value) .Take(pagingOptions.Limit.Value) .ProjectTo <Event>(_mappingConfiguration) .ToArrayAsync(ct); return(new PagedResults <Event> { Items = items, TotalSize = size }); }
public async Task <PagedResults <Booking> > GetBookingsAsync( PagingOptions pagingOptions, SortOptions <Booking, BookingEntity> sortOptions, SearchOptions <Booking, BookingEntity> searchOptions) { IQueryable <BookingEntity> query = _context.Bookings .Include(b => b.User) .Include(b => b.Room); query = searchOptions.Apply(query); query = sortOptions.Apply(query); var size = await query.CountAsync(); var items = await query .Skip(pagingOptions.Offset.Value) .Take(pagingOptions.Limit.Value) .ProjectTo <Booking>(_mappingConfiguration) .ToArrayAsync(); return(new PagedResults <Booking> { Items = items, TotalSize = size }); }
public async Task <PagedResults <Athlete> > GetAthletesByMeetAsync( int id, PagingOptions pagingOptions, SortOptions <Athlete, AthleteEntity> sortOptions, SearchOptions <Athlete, AthleteEntity> searchOptions, CancellationToken ct) { IQueryable <AthleteEntity> query = _context.Athletes.Where(r => r.meetId == id); query = searchOptions.Apply(query); query = sortOptions.Apply(query); var size = await query.CountAsync(ct); var items = await query .Skip(pagingOptions.Offset.Value) .Take(pagingOptions.Limit.Value) .ProjectTo <Athlete>() .ToArrayAsync(ct); return(new PagedResults <Athlete> { Items = items, TotalSize = size, }); }
public async Task <PagedResults <Room> > GetRoomsAsync(PagingOptions pagingOptions, SortOptions <Room, RoomEntity> sortOptions, SearchOptions <Room, RoomEntity> searchOptions, CancellationToken ct) { IQueryable <RoomEntity> query = _context.Rooms; // step 1: searching data by parameters query = searchOptions.Apply(query); // step 2: sorting data after searching query = sortOptions.Apply(query); var size = await query.CountAsync(ct); var items = await query .Skip(pagingOptions.Offset.Value) .Take(pagingOptions.Limit.Value) .ProjectTo <Room>() .ToArrayAsync(ct); return(new PagedResults <Room> { Items = items, TotalSize = size }); }
public async Task <PagedResults <CityData> > GetCitiesAsync( PagingOptions pagingOptions, SortOptions <CityData, CityEntity> sortOptions, SearchOptions <CityData, CityEntity> searchOptions) { IQueryable <CityEntity> query = _context.Cities.Include(x => x.Coord); query = searchOptions.Apply(query); query = sortOptions.Apply(query); int size = await query.CountAsync(); CityEntity[] items = await query .Skip(pagingOptions.Offset.Value) .Take(pagingOptions.Limit.Value) .ToArrayAsync(); return(new PagedResults <CityData> { Items = items.Select(x => new CityData() { Id = x.Id, Name = x.Name, State = x.State, Country = x.Country, Coord = new Coord() { Lon = (x.Coord == null) ? 0 : x.Coord.Lon, Lat = (x.Coord == null) ? 0 : x.Coord.Lat } }), TotalSize = size }); }
public async Task <PagedResults <Room> > GetRoomsAsync( PagingOptions pagingOptions, SortOptions <Room, RoomEntity> sortOptions, SearchOptions <Room, RoomEntity> searchOptions) { IQueryable <RoomEntity> query = _context.Rooms; query = searchOptions.Apply(query); query = sortOptions.Apply(query); var size = await query.CountAsync(); var items = await query .Skip(pagingOptions.Offset.Value) .Take(pagingOptions.Limit.Value) .ProjectTo <Room>(_mappingConfiguration) .ToArrayAsync(); return(new PagedResults <Room> { Items = items, TotalSize = size }); }
public async Task <PagedResults <Booking> > GetBookingsForUserIdAsync( Guid userId, PagingOptions pagingOptions, SortOptions <Booking, BookingEntity> sortOptions, SearchOptions <Booking, BookingEntity> searchOptions, CancellationToken ct) { IQueryable <BookingEntity> query = _context.Bookings .Include(b => b.User) .Include(b => b.Room) .Where(b => b.User.Id == userId); query = searchOptions.Apply(query); query = sortOptions.Apply(query); var size = await query.CountAsync(ct); var items = await query .Skip(pagingOptions.Offset.Value) .Take(pagingOptions.Limit.Value) .ProjectTo <Booking>() .ToArrayAsync(ct); return(new PagedResults <Booking> { Items = items, TotalSize = size }); }
public async Task <IEnumerable <Room> > GetRoomsAsync(SortOptions <Room, RoomEntity> sortOptions, SearchOptions <Room, RoomEntity> searchOptions) { IQueryable <RoomEntity> query = _context.Rooms; query = searchOptions.Apply(query); //zabezpecenie searchovania query = sortOptions.Apply(query); //zabezpecenie sortovania return(await query.ProjectTo <Room>(_mappingConfiguration).ToArrayAsync()); }
public async Task <PagedResults <Opening> > GetOpeningsAsync( PagingOptions pagingOptions, SortOptions <Opening, OpeningEntity> sortOptions, SearchOptions <Opening, OpeningEntity> searchOptions, CancellationToken ct) { var rooms = await _context.Rooms.ToArrayAsync(); var allOpenings = new List <OpeningEntity>(); foreach (var room in rooms) { // Generate a sequence of raw opening slots var allPossibleOpenings = _dateLogicService.GetAllSlots( DateTimeOffset.UtcNow, _dateLogicService.FurthestPossibleBooking(DateTimeOffset.UtcNow)) .ToArray(); var conflictedSlots = await GetConflictingSlots( room.Id, allPossibleOpenings.First().StartAt, allPossibleOpenings.Last().EndAt, ct); // Remove the slots that have conflicts and project var openings = allPossibleOpenings .Except(conflictedSlots, new BookingRangeComparer()) .Select(slot => new OpeningEntity { RoomId = room.Id, Rate = room.Rate, StartAt = slot.StartAt, EndAt = slot.EndAt }); allOpenings.AddRange(openings); } var pseudoQuery = allOpenings.AsQueryable(); pseudoQuery = searchOptions.Apply(pseudoQuery); pseudoQuery = sortOptions.Apply(pseudoQuery); var size = pseudoQuery.Count(); var items = pseudoQuery .Skip(pagingOptions.Offset.Value) .Take(pagingOptions.Limit.Value) .ProjectTo <Opening>() .ToArray(); return(new PagedResults <Opening> { TotalSize = size, Items = items }); }
public async Task <List <BusStopViewModel> > GetAllBusStopsAsync(SearchOptions <BusStopViewModel, BusStop> searchOptions) { IQueryable <BusStop> query = Context.BusStops; query = searchOptions.Apply(query); List <BusStop> busStops = await query.ToListAsync(); List <BusStopViewModel> busStopView = mapper.Map <List <BusStop>, List <BusStopViewModel> >(busStops); return(busStopView); }
public List <Room> GetRooms(SortOptions <Room> sortOptions, SearchOptions <Room> searchOptions) { IQueryable <Room> query = _context.Rooms; query = searchOptions.Apply(query); query = sortOptions.Apply(query); if (_context.Rooms.Count() == 0) { SetErrorResponse(300, string.Empty); } return(query.ToList <Room>()); }
public async Task <IEnumerable <TodoTask> > GetTasksAsync( SearchOptions <TodoTask, TodoTaskEntity> searchOptions, CancellationToken ct) { IQueryable <TodoTaskEntity> query = _dbContext.Tasks; query = searchOptions.Apply(query); var entities = await query.Include(x => x.Category).ToArrayAsync(ct); return(entities.Select(x => Mapper.Map <TodoTask>(x))); }
public async Task <IEnumerable <TopicResultDto> > GetAll(string userId, SearchOptions <TopicResultDto, Topic> searchOptions, PagingOptions pagingOptions, FilterOptions filterOptions) { var query = _context.Topics .Where(t => !t.IsDeleted) .Include(t => t.Category) .Include(t => t.User) .Include(t => t.Comments) .Include(t => t.Views) .AsQueryable(); query = pagingOptions.Apply(filterOptions.Apply(searchOptions.Apply(query), userId)); return((await query.ToListAsync()).Select(TopicResultDto.Create)); }
public async Task <IEnumerable <ProductResultDto> > GetProductsBySubcategory(string subcategoryUri, FilterOptions <ProductResultDto, Product> filterOptions, SearchOptions <ProductResultDto, Product> searchOptions, PagingOptions pageOptions) { var subcategory = await _categoryService.GetSubcategoryByUri(subcategoryUri); if (subcategory == null) { throw new KeyNotFoundException("Subcategory not found"); } var products = _context.Products .Where(p => p.SubcategoryId == subcategory.Id).AsQueryable(); if (!products.Any()) { return(new List <ProductResultDto>()); } if (pageOptions == null) { pageOptions = new PagingOptions { Offset = 0, Limit = 24 }; } IQueryable <Product> query = null; if (filterOptions != null) { query = filterOptions.Apply(products); if (query == null) { return(new List <ProductResultDto>()); } } return(searchOptions.Apply(query ?? products) .Include(p => p.Images) .Include(p => p.Seller) .OrderByDescending(p => p.DateTime) .Skip(pageOptions.Offset ?? default) .Take(pageOptions.Limit ?? 24).AsEnumerable() .Select(ProductResultDto.Create)); }
public async Task <PagedResults <User> > SearchUsersAsync(PagingOptions pagingOptions, SortOptions <User , UserEntity> sortOptions, SearchOptions <User, UserEntity> searchOptions) { IQueryable <UserEntity> query = _context.Users; query = searchOptions.Apply(query); query = sortOptions.Apply(query); var items = query.Skip(pagingOptions.Offset.Value) .Take(pagingOptions.Limit.Value) .ProjectTo <User>(_mapper.ConfigurationProvider); // return await query.ToArrayAsync(); return(new PagedResults <User>() { Items = items.ToArray(), TotalSize = await query.CountAsync() }); }
public async Task <PagedResults <Card> > GetCardsAsync(SortOptions <Card, CardEntity> sortOptions, SearchOptions <Card, CardEntity> searchOptions) { var query = _repositoryWrapper.Card.GetAll(x => x.CardStatistics); query = searchOptions.Apply(query); query = sortOptions.Apply(query); var totalSize = await query.CountAsync(); var items = await query .ProjectTo <Card>(_mappingConfiguration) .ToListAsync(); return(new PagedResults <Card> { Items = items, TotalSize = totalSize }); }
public async Task <PagedResults <Event> > GetEventsByMeetAsync( int meetId, PagingOptions pagingOptions, SortOptions <Event, EventEntity> sortOptions, SearchOptions <Event, EventEntity> searchOptions, CancellationToken ct) { IQueryable <EventEntity> query = _context.Events .Where(r => r.meetId == meetId); query = searchOptions.Apply(query); query = sortOptions.Apply(query); var size = await query.CountAsync(ct); var items = await query .Skip(pagingOptions.Offset.Value) .Take(pagingOptions.Limit.Value) .ProjectTo <Event>() .ToArrayAsync(ct); BarHeightsProcessor bhp = new BarHeightsProcessor(_context, meetId); foreach (var evt in items) { evt.Params = await _paramsProcessor .GetParameters(evt.eventId, ct); if (evt.Params.EventType[0] == 'V') { evt.BarHeights = await bhp.GetHeights(evt.eventId, ct); } } return(new PagedResults <Event> { Items = items, TotalSize = size, }); }
public IEnumerable <ProductResultDto> GetProductsForHome(SearchOptions <ProductResultDto, Product> searchOptions, PagingOptions pageOptions) { if (pageOptions == null) { pageOptions = new PagingOptions { Offset = 0, Limit = 24 }; } var query = _context.Products.AsQueryable(); return(searchOptions.Apply(query) .Include(p => p.Images) .Include(p => p.Seller) .OrderByDescending(p => p.DateTime) .Skip(pageOptions.Offset ?? default) .Take(pageOptions.Limit ?? 24).AsEnumerable() .Select(ProductResultDto.Create)); }
public async Task <PagedResults <Question> > GetAllByFeedbackTypeAsync( PagingOptions pagingOptions, SortOptions <Question, QuestionEntity> sortOptions, SearchOptions <Question, QuestionEntity> searchOptions, string feedbackType, CancellationToken ct) { IQueryable <QuestionEntity> query = _context.Questions.AsNoTracking().Where(x => x.Active && x.FeedbackType.Equals(feedbackType)); query = searchOptions.Apply(query); query = sortOptions.Apply(query); var size = await query.CountAsync(ct); var items = await query .Include(x => x.Answers) .Skip(pagingOptions.Offset.Value) .Take(pagingOptions.Limit.Value) //.ProjectTo<Question>(_mappingConfiguration) .Select(x => new Question { Id = x.Id, Description = x.Description, Answers = x.Answers.Where(a => a.Active).AsQueryable().ProjectTo <Answer>(_mappingConfiguration), Active = x.Active, AllowMultipleAnswer = x.AllowMultipleAnswer, FreeTextQuestion = x.FreeTextQuestion, CustomQuestion = x.CustomQuestion, FeedbackType = x.FeedbackType, CreatedAt = x.CreatedAt, ModifiedAt = x.ModifiedAt }) .ToArrayAsync(ct); return(new PagedResults <Question> { Items = items, TotalSize = size }); }
public async Task <Collection <Event> > GetEventsByAthleteAsync( int athleteId, SortOptions <Event, EventEntity> sortOptions, SearchOptions <Event, EventEntity> searchOptions, CancellationToken ct) { var entries = _context.EventEntries.Where(r => r.athleteId == athleteId) .Select(r => r.eventId); IQueryable <EventEntity> query = _context.Events.Where(e => entries.Contains(e.eventId)); query = searchOptions.Apply(query); query = sortOptions.Apply(query); var items = await query .ProjectTo <Event>() .ToArrayAsync(ct); BarHeightsProcessor bhp = new BarHeightsProcessor( _context, items[0].meetId); foreach (var evt in items) { evt.Params = await _paramsProcessor .GetParameters(evt.eventId, ct); if (evt.Params.EventType[0] == 'V') { evt.BarHeights = await bhp.GetHeights(evt.eventId, ct); } } return(new Collection <Event> { Value = items }); }
public async Task <PagedResults <Card> > GetCardsAsync(PagingOptions pagingOptions, SortOptions <Card, CardEntity> sortOptions, SearchOptions <Card, CardEntity> searchOptions) { var query = _repositoryWrapper.Card.GetAll(); query = searchOptions.Apply(query); query = sortOptions.Apply(query); var totalSize = await query.CountAsync(); var items = await query .Skip(pagingOptions.Offset.Value) .Take(pagingOptions.Limit.Value) .ProjectTo <Card>(_mappingConfiguration) .ToListAsync(); return(new PagedResults <Card> { Items = items, TotalSize = totalSize }); }
/// <summary> /// Gets the available categories async. /// </summary> /// <returns>The available categories async.</returns> /// <param name="pagingOptions">Paging options.</param> /// <param name="searchOptions">Search options.</param> public async Task <PagedResults <string> > GetAvailableCategoriesAsync( PagingOptions pagingOptions, SearchOptions <BSWord, BSWordEntity> searchOptions) { IQueryable <BSWordEntity> query = _context.BSWords.Where(x => x.Category != null); query = searchOptions.Apply(query); var items = await query .Select(x => x.Category) .Distinct() .Skip(pagingOptions.Offset.Value) .Take(pagingOptions.Limit.Value) .ToArrayAsync(); var size = items.Count(); return(new PagedResults <string> { Items = items, TotalSize = size }); }