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 <PageResults <Room> > GetRoomsAsync( PagingOptions pagingOptions, SortOptions <Room, RoomEntity> sortOptions, CancellationToken ct) { var rooms = await _context.Rooms.ToArrayAsync(); IQueryable <RoomEntity> query = _context.Rooms; query = sortOptions.Apply(query); var pagedRooms = await query .Skip(pagingOptions.Offset.Value) .Take(pagingOptions.Limit.Value) .Select(entity => _mapper.Map <Room>(entity)) .ToArrayAsync(ct); return(new PageResults <Room> { Items = pagedRooms, TotalSize = rooms.Count() }); }
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 <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 <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 <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 <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 <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 <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) { //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 <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 <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> > 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 <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 new async Task <PagedResults <ProductDto> > GetListAsync(int offset, int limit, string keyword, SortOptions <ProductDto, ProductEntity> sortOptions, FilterOptions <ProductDto, ProductEntity> filterOptions, IQueryable <ProductEntity> querySearch) { IQueryable <ProductEntity> query = _entity; query = sortOptions.Apply(query); query = filterOptions.Apply(query); if (keyword != null) { query = querySearch; } var size = await query.CountAsync(); var items = await query .Skip(offset *limit) .Take(limit) .ProjectTo <ProductDto>() .ToArrayAsync(); return(new PagedResults <ProductDto> { 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 <UserDto> > GetListAsync(int offset, int limit, string keyword, SortOptions <UserDto, UserEntity> sortOptions, FilterOptions <UserDto, UserEntity> filterOptions, IQueryable <UserEntity> querySearch ) { IQueryable <UserEntity> query = _entity; query = sortOptions.Apply(query); query = filterOptions.Apply(query); if (keyword != null) { query = querySearch; } var size = await query.CountAsync(); var items = await query .Skip(offset *limit) .Take(limit) .ToArrayAsync(); List <UserDto> returnUserList = new List <UserDto>(); foreach (UserEntity user in items) { var roleNames = await _userManager.GetRolesAsync(user); var userStorages = _context.UserStorages.Where(us => us.UserId == user.Id).Include(us => us.Storage).OrderBy(s => s.Storage.Name); var storages = new List <StorageDto>(); foreach (var userStorage in userStorages) { storages.Add(Mapper.Map <StorageDto>(userStorage.Storage)); } var userDto = new UserDto { FirstName = user.FirstName, LastName = user.LastName, Email = user.Email, PhoneNumber = user.PhoneNumber, Id = user.Id, UserName = user.UserName, JobTitle = user.JobTitle, IsActive = user.IsActive, RoleNames = roleNames, AccessibleStorages = storages }; returnUserList.Add(userDto); } return(new PagedResults <UserDto> { Items = returnUserList, TotalSize = size }); }
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 <PagedResults <OrderDto> > GetListAsync( int offset, int limit, string keyword, SortOptions <OrderDto, OrderEntity> sortOptions, FilterOptions <OrderDto, OrderEntity> filterOptions, IQueryable <OrderEntity> querySearch) { IQueryable <OrderEntity> query = _order; query = sortOptions.Apply(query); query = filterOptions.Apply(query); if (keyword != null) { // DateTime a = DateTime.ParseExact(DateTime.Now.Date.ToString(), "dd/MM/yyyy", // System.Globalization.CultureInfo.InvariantCulture).Date; query = query.Where(p => p.Code.Contains(keyword) || p.Status.Contains(keyword) ); } var items = await query .Skip(offset *limit) .Take(limit) .ToArrayAsync(); var totalSize = await query.CountAsync(); var returnItems = Mapper.Map <List <OrderDto> >(items); for (var i = 0; i < items.Length; i++) { returnItems[i].PackageList = new List <PackageDto>(); var packageIdList = JsonConvert.DeserializeObject <List <Guid> >(items[i].PackageIdList); foreach (Guid packageId in packageIdList) { var package = await _context.Packages.SingleOrDefaultAsync(s => s.Id == packageId); if (package == null) { throw new Exception("Can not find storage with Id=" + packageId); } var packageDto = Mapper.Map <PackageDto>(package); returnItems[i].PackageList.Add(packageDto); } } return(new PagedResults <OrderDto> { Items = returnItems, TotalSize = totalSize }); }
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 <PagedResults <Opening> > GetOpeningsAsync(PagingOptions pagingOptions, SortOptions <Opening, OpeningEntity> sortOptions) { var rooms = await _context.Rooms.ToArrayAsync(); var allOpenings = new List <OpeningEntity>(); foreach (var room in rooms) { var allPossibleOpenings = _dateLogicService.GetAllSlots( DateTimeOffset.UtcNow, _dateLogicService.FurthestPossibleBooking(DateTimeOffset.UtcNow)) .ToArray(); var conflictedSlots = await GetConflictingSlots( room.Id, allPossibleOpenings.First().StartAt, allPossibleOpenings.Last().EndAt); //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 }); //.Select(model => _mapper.Map<Opening>(model)); allOpenings.AddRange(openings); } IQueryable <OpeningEntity> pseudoQuery = allOpenings.AsQueryable(); pseudoQuery = sortOptions.Apply(pseudoQuery); var pagedOpenings = pseudoQuery .Skip(pagingOptions.Offset.Value) .Take(pagingOptions.Limit.Value) .ProjectTo <Opening>(_mappingConfiguration) .ToArray(); var size = pseudoQuery.Count(); return(new PagedResults <Opening> { Items = pagedOpenings, TotalSize = size } ); }
public async Task <PagedResults <InventoryDto> > GetListAsync(int offset, int limit, string keyword, ICollection <Guid> storageIds, SortOptions <InventoryDto, InventoryEntity> sortOptions, FilterOptions <InventoryDto, InventoryEntity> filterOptions) { IQueryable <InventoryEntity> querySearch; querySearch = _entity.Where(x => x.Code.Contains(keyword) || x.Note.Contains(keyword) || x.Storage.Name.Contains(keyword) || x.ProductList.Contains(keyword) ); try { DateTime searchDate = DateTime.ParseExact(keyword, "dd/MM/yyyy", System.Globalization.CultureInfo.InvariantCulture).Date; querySearch = _entity.Where(x => x.CreatedDateTime.Date == searchDate.Date || x.BalanceDateTime == searchDate.Date); } catch (Exception) { } IQueryable <InventoryEntity> query = _entity; query = sortOptions.Apply(query); query = filterOptions.Apply(query); if (keyword != null) { query = querySearch; } query = query.Where(w => storageIds.Contains(w.StorageId)); var items = await query .Skip(offset *limit) .Take(limit) .ProjectTo <InventoryDto>() .ToArrayAsync(); var size = await query.CountAsync(); return(new PagedResults <InventoryDto> { Items = items, TotalSize = size }); }
public async Task <PagedResults <UserDto> > GetListAsync(int offset, int limit, string keyword, SortOptions <UserDto, UserEntity> sortOptions, FilterOptions <UserDto, UserEntity> filterOptions, IQueryable <UserEntity> querySearch ) { IQueryable <UserEntity> query = _entity; query = sortOptions.Apply(query); query = filterOptions.Apply(query); if (keyword != null) { query = querySearch; } var size = await query.CountAsync(); var items = await query .Skip(offset *limit) .Take(limit) .ToArrayAsync(); List <UserDto> returnUserList = new List <UserDto>(); foreach (UserEntity user in items) { var roleNames = await _userManager.GetRolesAsync(user); var userDto = new UserDto { FirstName = user.FirstName, LastName = user.LastName, Email = user.Email, Id = user.Id, UserName = user.UserName, JobTitle = user.JobTitle, IsActive = user.IsActive, RoleNames = roleNames }; returnUserList.Add(userDto); } return(new PagedResults <UserDto> { Items = returnUserList, TotalSize = size }); }
public async Task <PagedResults <User> > GetOrderedUsersAsync(PagingOptions pagingOptions , SortOptions <User, UserEntity> sortOptions) { IQueryable <UserEntity> query = _context.Users; 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 <Arena> > GetArenas(SortOptions <Arena, ArenaEntity> sortOptions) { var query = _repositoryWrapper.Arena.GetAll(); query = sortOptions.Apply(query); var totalSize = await query.CountAsync(); var items = await query .ProjectTo <Arena>(_mappingConfiguration) .ToListAsync(); return(new PagedResults <Arena> { Items = items, TotalSize = totalSize }); }
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 <Mobile> > GetMobilesAsync(PagingOptions pagingOptions, SortOptions <Mobile, MobileEntity> sortOptions) { IQueryable <MobileEntity> query = _context.Mobiles; query = sortOptions.Apply(query); var size = await query.CountAsync(); var items = await query .Skip(pagingOptions.Offset.Value) .Take(pagingOptions.Limit.Value) .ProjectTo <Mobile>(_mapper.ConfigurationProvider) .ToArrayAsync(); return(new PagedResults <Mobile> { Items = items, TotalSize = size }); }
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, }); }