public override async Task <ReturnPagingInfo <Event> > GetAllDataAsync(PagingInfo pagingInfo, CancellationToken cancellationToken) { var take = pagingInfo.PageSize; var skip = (pagingInfo.CurrentPage - 1) * pagingInfo.PageSize; var query = IncludeAll() .OrderByDescending(s => s.CreatedTime) .Select(i => new { Data = i, TotalCount = IncludeAll().Count() }); var entities = pagingInfo.PageSize != 0 ? await query.Skip(skip).Take(take).ToListAsync(cancellationToken) : await query.ToListAsync(cancellationToken); var totalCount = entities.First().TotalCount; var result = new ReturnPagingInfo <Event> { CurrentPage = pagingInfo.CurrentPage, PageSize = entities.Count, TotalItems = totalCount, TotalPages = (int)Math.Ceiling((double)totalCount / (pagingInfo.PageSize == 0 ? totalCount : pagingInfo.PageSize)), Data = entities.Select(i => i.Data).ToList() }; return(result); }
public async Task <ReturnPagingInfo <UserAchievement> > GetAllUsersByAchievementAsync(PagingInfo pagingInfo, Guid achievementId, CancellationToken cancellationToken) { var query = IncludeAll() .Where(o => o.Achievement.Id == achievementId) .AsQueryable(); if (pagingInfo.PageSize != 0) { query = query.Skip((pagingInfo.CurrentPage - 1) * pagingInfo.PageSize) .Take(pagingInfo.PageSize); } var items = await query.ToListAsync(cancellationToken); var result = new ReturnPagingInfo <UserAchievement>() { CurrentPage = pagingInfo.CurrentPage, PageSize = items.Count, TotalItems = query.Count(), TotalPages = (int)Math.Ceiling((double)query.Count() / (pagingInfo.PageSize == 0 ? query.Count() : pagingInfo.PageSize)), Data = items }; return(result); }
public override async Task<ReturnPagingInfo<RequestOrder>> GetAllDataAsync(PagingInfo pagingInfo, CancellationToken cancellationToken) { var take = pagingInfo.PageSize; var skip = (pagingInfo.CurrentPage - 1) * pagingInfo.PageSize; var query = IncludeAll() .Where(s => s.Status == GamificationEnums.RequestStatus.Pending) .OrderBy(s => s.Id) .Select(i => new { Data = i, TotalCount = IncludeAll().Count() }); var entities = pagingInfo.PageSize != 0 ? await query.Skip(skip).Take(take).ToListAsync(cancellationToken) : await query.ToListAsync(cancellationToken); var totalCount = entities.FirstOrDefault()?.TotalCount ?? 0; var result = new ReturnPagingInfo<RequestOrder> { CurrentPage = pagingInfo.CurrentPage, PageSize = entities.Count, TotalItems = totalCount, TotalPages = (int)Math.Ceiling((double)totalCount / (pagingInfo.PageSize == 0 ? totalCount : pagingInfo.PageSize)), Data = entities.Select(i => i.Data).ToList() }; return result; }
public async Task <ReturnPagingInfo <UserAchievement> > GetAllAchievementsByUserAsync(PagingInfo pagingInfo, Guid userId, CancellationToken cancellationToken) { var take = pagingInfo.PageSize; var skip = (pagingInfo.CurrentPage - 1) * pagingInfo.PageSize; var query = IncludeAll() .Where(i => i.User.Id == userId) .OrderByDescending(s => s.AddedTime) .Select(i => new { Data = i, TotalCount = IncludeAll().Count() }); var entities = pagingInfo.PageSize != 0 ? await query.Skip(skip).Take(take).ToListAsync(cancellationToken) : await query.ToListAsync(cancellationToken); var totalCount = entities.FirstOrDefault()?.TotalCount ?? 0; var result = new ReturnPagingInfo <UserAchievement> { CurrentPage = pagingInfo.CurrentPage, PageSize = entities.Count, TotalItems = totalCount, TotalPages = (int)Math.Ceiling((double)totalCount / (pagingInfo.PageSize == 0 ? totalCount : pagingInfo.PageSize)), Data = entities.Select(i => i.Data).ToList() }; return(result); }
public static ReturnPagingInfo <T> GetForModel <T>(PagingInfo pagingInfo, List <T> data) { var users = new ReturnPagingInfo <T> { Data = data, CurrentPage = pagingInfo.CurrentPage, PageSize = pagingInfo.PageSize, TotalItems = data.Count, TotalPages = (int)Math.Ceiling((double)data.Count / (pagingInfo.PageSize == 0 ? data.Count : pagingInfo.PageSize)) }; return(users); }
public static ReturnPagingInfo <TModel> GetWithModels <TModel, TEntity>(ReturnPagingInfo <TEntity> page, IMapper _mapper) { var readUserModel = page.Data.Select(i => _mapper.Map <TModel>(i)).ToList(); var result = new ReturnPagingInfo <TModel>() { CurrentPage = page.CurrentPage, PageSize = page.PageSize, TotalItems = page.TotalItems, TotalPages = page.TotalPages, Data = readUserModel }; return(result); }
public async Task <ReturnPagingInfo <ReadShortUserModel> > GetAllUsersWithShortInfoAsync(PagingInfo pagingInfo, CancellationToken cancellationToken) { var page = await _userRepository.GetAllDataAsync(pagingInfo, cancellationToken); var readUserModels = page.Data.Select(i => _mapper.Map <ReadShortUserModel>(i)).ToList(); var result = new ReturnPagingInfo <ReadShortUserModel>() { CurrentPage = page.CurrentPage, PageSize = page.PageSize, TotalItems = page.TotalItems, TotalPages = page.TotalPages, Data = readUserModels }; return(result); }
public async Task <ReturnPagingInfo <EventModel> > GetAllEventAsync(PagingInfo pagingInfo, CancellationToken cancellationToken) { var page = await _eventRepository.GetAllDataAsync(pagingInfo, cancellationToken); var eventModels = page.Data.Select(i => _mapper.Map <EventModel>(i)).ToList(); var result = new ReturnPagingInfo <EventModel> { CurrentPage = page.CurrentPage, PageSize = page.PageSize, TotalItems = page.TotalItems, TotalPages = page.TotalPages, Data = eventModels }; return(result); }
public async Task <ReturnPagingInfo <ReadCategoryModel> > GetAllCategoryAsync(PagingInfo pagingInfo, CancellationToken cancellationToken) { var page = await _categoryRepository.GetAllDataAsync(pagingInfo, cancellationToken); var readCategoryModels = page.Data.Select(category => _mapper.Map <ReadCategoryModel>(category)).ToList(); var result = new ReturnPagingInfo <ReadCategoryModel> { CurrentPage = page.CurrentPage, PageSize = page.PageSize, TotalItems = page.TotalItems, TotalPages = page.TotalPages, Data = readCategoryModels }; return(result); }
public async Task <ReturnPagingInfo <ReadUserAchievementModel> > GetAllAchievementsByUserAsync(PagingInfo pagingInfo, Guid userId, CancellationToken cancellationToken) { var page = await _userAchievementRepository .GetAllAchievementsByUserAsync(pagingInfo, userId, cancellationToken); var readAchievementModel = page.Data.Select(i => _mapper.Map <ReadUserAchievementModel>(i)).ToList(); var result = new ReturnPagingInfo <ReadUserAchievementModel>() { CurrentPage = page.CurrentPage, PageSize = page.PageSize, TotalItems = page.TotalItems, TotalPages = page.TotalPages, Data = readAchievementModel }; return(result); }