예제 #1
0
            private async Task <PaginatedList <ContactDto> > ReadFromCache(FilterQuery request)
            {
                var cache = await _cache.GetAsync <PaginatedList <ContactDto> >();

                cache.Restore(request.PageNumber, request.PageSize);

                return(cache);
            }
예제 #2
0
 public async Task <PaginatedList <ContactDto> > Handle(FilterQuery request,
                                                        CancellationToken cancellationToken)
 {
     try
     {
         return(await ReadFromCache(request));
     }
     catch (NotFoundException)
     {
         return(await ReadFromDatabase(request));
     }
 }
예제 #3
0
            // Helpers.

            private async Task <PaginatedList <ContactDto> > ReadFromDatabase(FilterQuery query, object key)
            {
                var model = new ContactDto
                {
                    OwnerUserId = query.OwnerUserId,
                    FirstName   = query.FirstName ?? string.Empty,
                    LastName    = query.LastName ?? string.Empty,
                    Email       = query.Email ?? string.Empty
                };

                return(await _context.Contacts
                       .Where(e => e.OwnerUserId == query.OwnerUserId)
                       .ProjectTo <ContactDto>(_mapper.ConfigurationProvider)
                       .Where(await model.FilterAsync())
                       .ProjectToPaginatedListAsync(query.PageNumber, query.PageSize)
                       .MapUsersAsync(_usersFacade)
                       .Cache(_cache, key));
            }
예제 #4
0
            public async Task <PaginatedList <ContactDto> > Handle(FilterQuery query, CancellationToken cancellationToken)
            {
                var key = query.Identify();

                try
                {
                    _logger.LogInformation("[WLODZIMIERZ.API / Contacts] Reading from the cache: {Name} {@Query}",
                                           nameof(FilterQuery), query);

                    return(await ReadFromCache(key));
                }
                catch (NotFoundException)
                {
                    _logger.LogWarning("[WLODZIMIERZ.API / Contacts] No entry found for the passed key in the cache");

                    _logger.LogInformation("[WLODZIMIERZ.API / Contacts] Reading from the database: {Name} {@Query}",
                                           nameof(FilterQuery), query);

                    return(await ReadFromDatabase(query, key));
                }
            }
예제 #5
0
            // Helpers.

            private async Task <PaginatedList <ContactDto> > ReadFromDatabase(FilterQuery query)
            {
                var model = new ContactDto
                {
                    ContactId   = query.ContactId ?? 0,
                    OwnerUserId = query.OwnerUserId,
                    FirstName   = query.FirstName ?? string.Empty,
                    LastName    = query.LastName ?? string.Empty,
                    Email       = query.Email ?? string.Empty
                };

                var contacts = await _context.Contacts
                               .Where(e => e.OwnerUserId == query.OwnerUserId)
                               .ProjectTo <ContactDto>(_mapper.ConfigurationProvider)
                               .Where(await model.FilterAsync())
                               .PaginatedListAsync(query.PageNumber, query.PageSize);

                await _cache.CreateAsync(contacts);

                return(contacts);
            }