Ejemplo n.º 1
0
        public async Task <PaginationResult <Reservation> > GetReservationsAsync(QueryObject queryObject)
        {
            var query = _reservationDbContext.Reservations.EagerLoadRelatedObjects()
                        .AsQueryable();

            if (queryObject.UserId.HasValue)
            {
                query = query.Where(res => res.CreatedByUserId == queryObject.UserId.Value);
            }

            var dictionary = new Dictionary <string, Expression <Func <Reservation, object> > >()
            {
                [Constants.SortByCreatedDateTime] = reservation => reservation.CreatedDateTime,
                [Constants.SortByContactName]     = reservation => reservation.Contact.Name,
                [Constants.SortByRanking]         = reservation => reservation.UserLikesReservation.Count()
            };

            if (queryObject?.SortBy != null && dictionary.ContainsKey(queryObject.SortBy))
            {
                query = queryObject.IsSortAscending
                        ? query.OrderBy(dictionary[queryObject.SortBy])
                        : query.OrderByDescending(dictionary[queryObject.SortBy]);
            }

            return(await PaginationResult <Reservation> .CreateAsync(query, queryObject.Page, queryObject.PageSize));
        }
Ejemplo n.º 2
0
        public async Task <PaginationResult <User> > GetUsers(QueryObject queryObject)
        {
            var query = _galleryDbContext.Users.AsQueryable();

            if (queryObject.UserId.HasValue)
            {
                query = query.Where(user => user.Id == queryObject.UserId.Value);
            }
            return(await PaginationResult <User> .CreateAsync(query, queryObject.Page, queryObject.PageSize));
        }
Ejemplo n.º 3
0
        public async Task <PaginationResult <Picture> > GetPictures(QueryObject queryObject)
        {
            var query = _galleryDbContext.Pictures.AsQueryable();

            if (queryObject.UserId.HasValue)
            {
                query = query.Where(pic => pic.OwnerUserId == queryObject.UserId.Value);
            }

            if (!string.IsNullOrWhiteSpace(queryObject.SortBy) &&
                string.Compare(queryObject.SortBy, "UploadedDateTime", StringComparison.OrdinalIgnoreCase) == 0)
            {
                query = queryObject.IsSortAscending
                        ? query.OrderBy(pic => pic.UploadedDateTime)
                        : query.OrderByDescending(pic => pic.UploadedDateTime);
            }

            return(await PaginationResult <Picture> .CreateAsync(query, queryObject.Page, queryObject.PageSize));
        }
Ejemplo n.º 4
0
        public async Task <PaginationResult <Contact> > GetContactsAsync(QueryObject queryObject)
        {
            var query = _reservationDbContext.Contacts.EagerLoadRelatedObjects().AsQueryable();

            var dictionary = new Dictionary <string, Expression <Func <Contact, object> > >()
            {
                [Constants.SortByContactName] = contact => contact.Name,
                [Constants.SortByPhone]       = contact => contact.Phone,
                [Constants.SortByBirthDate]   = contact => contact.BirthDate,
                [Constants.SortByContactType] = contact => contact.ContactType.Name
            };

            if (queryObject?.SortBy != null && dictionary.ContainsKey(queryObject.SortBy))
            {
                query = queryObject.IsSortAscending
                        ? query.OrderBy(dictionary[queryObject.SortBy])
                        : query.OrderByDescending(dictionary[queryObject.SortBy]);
            }

            return(await PaginationResult <Contact> .CreateAsync(query, queryObject.Page, queryObject.PageSize));
        }
Ejemplo n.º 5
0
        public async Task <PaginationResult <QueryObjectTopHeadLinesRequest> > GetTracesTopheadlinesRequestsAsync(QueryObject queryObject)
        {
            var query = _newsDbContext.TopHeadLinesRequests.EagerLoadRelatedObjects().AsQueryable();

            var dictionary = new Dictionary <string, Expression <Func <QueryObjectTopHeadLinesRequest, object> > >()
            {
                [Constants.SortByCreatedByUser] = request => request.CreatedByUser.UserName,
                [Constants.SortByQ]             = request => request.Q,
                [Constants.SortByCreatedAt]     = request => request.CreatedAt,
                [Constants.SortByLanguage]      = request => request.Language,
                [Constants.SortByCategory]      = request => request.Category,
                [Constants.SortByCountry]       = request => request.Country
            };

            if (queryObject?.SortBy != null && dictionary.ContainsKey(queryObject.SortBy))
            {
                query = queryObject.IsSortAscending
                        ? query.OrderBy(dictionary[queryObject.SortBy])
                        : query.OrderByDescending(dictionary[queryObject.SortBy]);
            }

            return(await PaginationResult <QueryObjectTopHeadLinesRequest> .CreateAsync(query, queryObject.Page, queryObject.PageSize));
        }
Ejemplo n.º 6
0
        public async Task <PaginationResult <User> > GetUsersAsync(QueryObject queryObject)
        {
            var query = _newsDbContext.Users.Include(u => u.UserRoles).ThenInclude(ur => ur.Role).AsQueryable();

            return(await PaginationResult <User> .CreateAsync(query, queryObject.Page, queryObject.PageSize));
        }