public async Task <IEnumerable <Journey> > GetAllAsync( string company, string country, DateTime dateFrom, DateTime dateTo, ISortingInfo sortingInfo) { var query = BuildIndexQuery(company, country, dateFrom, dateTo, sortingInfo, false); var data = await query.ToListAsync(); return(data); }
public async Task <int> CountAllAsync( string company, string country, DateTime?dateFrom, DateTime?dateTo, ISortingInfo sortingInfo) { var query = BuildIndexQuery(company, country, dateFrom, dateTo, sortingInfo, false); var count = await query.CountAsync(); return(count); }
public async Task <IEnumerable <JourneyViewModel> > GetAllAsync( string company, string country, DateTime?dateFrom, DateTime?dateTo, ISortingInfo sortingInfo, IPagingInfo pagingInfo) { var query = BuildIndexQuery(company, country, dateFrom, dateTo, sortingInfo, true, pagingInfo); var data = await query.Select(v => _mapper.Map <Journey, JourneyViewModel>(v)).ToListAsync(); return(data); }
public IQueryable <Journey> BuildIndexQuery( string company, string country, DateTime?dateFrom, DateTime?dateTo, ISortingInfo sortingInfo, bool withIncludes = true, IPagingInfo pagingInfo = null) { // var filterModel = _requestModelService.GetModel<JourneyFilterModel>(); IQueryable <Journey> query = _databaseContext.Journeys.Include(j => j.User); if (withIncludes) { query = query .Include(j => j.Countries) .Include(j => j.JourneyVehicles) .ThenInclude(jv => jv.Vehicle); } if (!_roleService.IsAdmin) { query = query .Where(j => j.User.UserName == _httpContextAccessor.HttpContext.User.Identity.Name); } if (dateFrom.HasValue) { query = query .Where(j => j.EndDate >= dateFrom.Value.Date); } if (dateTo.HasValue) { dateTo = dateTo.Value.Date.AddDays(1).AddSeconds(-1); query = query .Where(j => j.EndDate <= dateTo); } if (!string.IsNullOrWhiteSpace(company)) { query = query .Where(j => j.UserId == company); } if (!string.IsNullOrWhiteSpace(country)) { query = query .Where(j => j.Countries.Any(c => c.Name == country)); } if (!string.IsNullOrWhiteSpace(sortingInfo?.ColumnName)) { query = sortingInfo.IsAscending ? query.OrderBy(j => EF.Property <object>(j, sortingInfo.ColumnName)) : query.OrderByDescending(j => EF.Property <object>(j, sortingInfo.ColumnName)); } else { query = query.OrderByDescending(j => j.EndDate); } if (pagingInfo != null) { query = query .Skip((pagingInfo.PageNumber - 1) * pagingInfo.PageSize) .Take(pagingInfo.PageSize); } return(query); }