예제 #1
0
        public async Task <QueryResultDto <RentalDto> > GetAllRentalMoviesAsync(
            RentalDataTableSettings settings)
        {
            if (!settings.UserId.HasValue)
            {
                _logger.LogError("Id of user is required!");
                throw new BusinessLogicException("Something goes wrong try to Re-login!");
            }

            return(await GetRentalMoviesAsync(settings));
        }
예제 #2
0
        private async Task <QueryResultDto <RentalDto> > GetRentalMoviesAsync(
            RentalDataTableSettings settings)
        {
            try
            {
                var query = Context.Rentals.AsQueryable();

                if (settings.UserId > 0)
                {
                    query = query.Where(m => m.User.Id == (settings.UserId));
                }
                var totalRecords = await query.CountAsync();


                if (!string.IsNullOrEmpty(settings.Search))
                {
                    query        = SearchRentals(settings.Search, query);
                    totalRecords = query.Count();
                }

                var columnsMap = GetColumnsMap();

                query = query
                        .Include(r => r.Movie)
                        .ThenInclude(m => m.Genre)
                        .Include(r => r.User)
                        .ApplyOrdering(settings, columnsMap);

//                if (settings.UserId <= 0)
//                {
//                    query = query.Include(r => r.User);
//                }

                query = query.ApplyPaging(settings);

                var resultDto = (await query.ToListAsync()).Select(_mapper.Map <Rental, RentalDto>);

                return(new QueryResultDto <RentalDto>
                {
                    Items = resultDto.ToList(),
                    TotalItems = totalRecords
                });
            }
            catch (Exception ex)
            {
                _logger.LogError("DataBase error, could`t fetch rentals", ex);
                throw new BusinessLogicException("Could not fetch data!", ex);
            }
        }
 public async Task <QueryResultDto <RentalDto> > GetAllRentalsWithUsersMoviesAsync([FromQuery] RentalDataTableSettings model)
 {
     return(await _rentalService.GetAllRentalMoviesWithUsersAsync(model));
 }
예제 #4
0
 public async Task <QueryResultDto <RentalDto> > GetAllRentalMoviesWithUsersAsync(
     RentalDataTableSettings settings)
 {
     return(await GetRentalMoviesAsync(settings));
 }