Exemplo n.º 1
0
        /// <summary>
        /// Gets the specified page of authors matching <paramref name="filter" />.
        /// </summary>
        /// <param name="filter">The filter.</param>
        /// <returns>
        /// Page of authors.
        /// </returns>
        /// <exception cref="ArgumentNullException">filter</exception>
        public DataPage <Author> GetAuthors(AuthorFilter filter)
        {
            if (filter == null)
            {
                throw new ArgumentNullException(nameof(filter));
            }

            PrepareAuthorFilter(filter);

            using (var db = GetContext())
            {
                var authors = db.Authors.AsQueryable();
                if (!string.IsNullOrEmpty(filter.Last))
                {
                    authors = authors.Where(a => a.Lastx.Contains(filter.Last));
                }

                int tot = authors.Count();

                // sort and page
                authors = authors.OrderBy(a => a.Last)
                          .ThenBy(a => a.First)
                          .ThenBy(a => a.Suffix)
                          .ThenBy(a => a.Id);
                var pgAuthors = authors.Skip(filter.GetSkipCount())
                                .Take(filter.PageSize)
                                .ToList();

                return(new DataPage <Author>(
                           filter.PageNumber,
                           filter.PageSize,
                           tot,
                           (from a in pgAuthors select EfHelper.GetAuthor(a)).ToList()));
            }
        }
        public IEnumerable <AuthorDto> GetAuthors(out int totalRecords, AuthorFilter filter)
        {
            totalRecords = 0;
            var entities = Context.Author.Select(i => i);

            if (!string.IsNullOrWhiteSpace(filter.FirstName))
            {
                entities = entities.Where(i => EF.Functions.Like(i.FirstName, $"{filter.FirstName}%"));
            }
            if (!string.IsNullOrWhiteSpace(filter.LastName))
            {
                entities = entities.Where(i => EF.Functions.Like(i.LastName, $"{filter.LastName}%"));
            }
            if (!string.IsNullOrWhiteSpace(filter.Alias))
            {
                entities = entities.Where(i => EF.Functions.Like(i.Alias, $"{filter.Alias}%"));
            }

            totalRecords = entities.Count();
            if (totalRecords <= filter.Skip)
            {
                filter.Skip = 0;
            }
            entities = entities.ApplySortToEntities(filter.SortMembers);

            List <AuthorDto> authors = entities
                                       .Skip(filter.Skip)
                                       .Take(filter.Take)
                                       .ProjectToType <AuthorDto>().ToList();

            return(authors);
        }
Exemplo n.º 3
0
 private static void PrepareAuthorFilter(AuthorFilter filter)
 {
     if (string.IsNullOrEmpty(filter.Last))
     {
         filter.Last = StandardFilter.Apply(filter.Last, true);
     }
 }
Exemplo n.º 4
0
        public async Task <IActionResult> DeleteAuthorFilter(AuthorFilter filter)
        {
            if (!await authorService.GetFilters().AnyAsync(x => x.Id == filter.Id))
            {
                return(NotFound());
            }

            await authorService.DeleteFilter(filter.Id);

            return(NoContent());
        }
Exemplo n.º 5
0
        public List <Guid> GetFilterAuthorIdsDirectly(AuthorFilter authorFilter)
        {
            string query = _defaultSelectCommand;

            query += String.Format(" And HourRate >= {0} And HourRate <= {1}", authorFilter.HourRateMin, authorFilter.HourRateMax);
            string jobCount = "(Select Count(*) From Job Where a.PersonId = Job.AuthorId)";

            query += " And " + jobCount + " >= " + authorFilter.CountOfPastJobsMin;
            query += " And " + jobCount + " <= " + authorFilter.CountOfPastJobsMax;
            query += String.Format(" And (Title Like '%{0}%' Or Overview Like '%{0}%')", authorFilter.SearchString);

            return(GetCustomList(query));
        }
Exemplo n.º 6
0
        public PartialViewResult GetAuthorsByFilter(AuthorFilter authorFilter, int page = 1)
        {
            if (Session["PersonId"] == null)
            {
                return(null);
            }

            List <Guid> authorIds = AuthorRepository.Instance.GetFilterAuthorIdsDirectly(authorFilter);

            InitAuthorsPartial(authorIds, page);

            return(PartialView("_Authors", authorFilter));
        }
Exemplo n.º 7
0
        public async Task TestListTotalPages(int limit)
        {
            // Arrange
            using var dbContext = GetBookSellerContext($"{nameof(AuthorTests)}_{nameof(TestListTotalPages)}_{limit}", TOTAL_RECORDS);
            var controller = new AuthorsController(dbContext);
            var filter     = new AuthorFilter {
                Limit = limit
            };

            // Act
            var response = await controller.List(filter);

            // Assert
            Assert.Equal(ExpectedTotalPages(limit, TOTAL_RECORDS), response.Value.TotalPages);
        }
Exemplo n.º 8
0
        public ActionResult FindAuthors()
        {
            if (Session["PersonId"] == null)
            {
                return(Redirect(ControllersLibrary.LogInPage));
            }

            ViewBag.Skills = SkillRepository.Instance.GetAllItems().OrderBy(i => i.Title);
            AuthorFilter af        = new AuthorFilter();
            List <Guid>  authorIds = AuthorRepository.Instance.GetFilterAuthorIdsDirectly(af);

            InitAuthorsPartial(authorIds, 1);

            return(View(af));
        }
Exemplo n.º 9
0
        public ActionResult GetAuthors(Pagination pagination, AuthorFilter authorFilter, string orderBy = "Name")
        {
            var orderByEntities = OrderMapper.MapTo <Author>(orderBy);

            IPagedList <Author> authors = _libraryRepository.GetAuthors(pagination, authorFilter, orderByEntities);
            var authorDtos = _mapper.Map <IEnumerable <AuthorDto> >(authors);

            var result = new
            {
                meta  = authors.GetMetaData(),
                value = authorDtos
            };

            return(Ok(result));
        }
Exemplo n.º 10
0
        public void GetByFilterTest()
        {
            //Arrange
            Mock <IUnitOfWork>           unitOfWorkMock = new Mock <IUnitOfWork>();
            Mock <IRepository <Author> > repositoryMock = new Mock <IRepository <Author> >();

            unitOfWorkMock.Setup(getRepository => getRepository.GetRepository <Author>()).Returns(repositoryMock.Object);
            repositoryMock.Setup(rep => rep.Get(It.IsAny <Expression <Func <Author, bool> > >())).Returns(authors.AsQueryable);
            AuthorService authorService = new AuthorService(unitOfWorkMock.Object);
            AuthorFilter  authorfilter  = new AuthorFilter();


            //Act

            IEnumerable <AuthorDTO> authorsDto = authorService.Get(authorfilter);

            //Assert
            Assert.NotNull(authorsDto);
            Assert.NotEmpty(authorsDto);
            Assert.Equal(5, authorsDto.Count());
        }
Exemplo n.º 11
0
        public async Task TestListFilter(string propertyName)
        {
            // Arrange
            using var dbContext = GetBookSellerContext($"{nameof(AuthorTests)}_{nameof(TestListFilter)}", TOTAL_RECORDS);
            var firstAuthor = dbContext.Author.First();

            firstAuthor.FirstName = "[TEST]fIrStNaMe[TEST]";
            firstAuthor.LastName  = "[TEST]lAsTNaMe[TEST]";
            dbContext.SaveChanges();

            var filter = new AuthorFilter();

            typeof(AuthorFilter).GetProperty(propertyName).SetValue(filter, propertyName);

            var controller = new AuthorsController(dbContext);

            // Act
            var response = await controller.List(filter);

            // Assert
            Assert.Single(response.Value.Items);
        }
Exemplo n.º 12
0
 List <Guid> IAuthorRepository.GetFilterAuthorIdsDirectly(AuthorFilter authorFilter)
 {
     return(Channel.GetFilterAuthorIdsDirectly(authorFilter));
 }
Exemplo n.º 13
0
 public List <Guid> GetFilterAuthorIdsDirectly(AuthorFilter authorFilter)
 {
     return(Proxy.GetFilterAuthorIdsDirectly(authorFilter));
 }
Exemplo n.º 14
0
        public async Task <IEnumerable <AuthorModel> > GetAuthorsAsync(PaginationQuery paginationFilter = null, AuthorFilter filter = null)
        {
            var skip = (paginationFilter.PageNumber - 1) * paginationFilter.PageSize;

            if (filter.Name is null)
            {
                var authorsNoFilter = _mapper.Map <IEnumerable <Author>, IEnumerable <AuthorModel> >
                                          (await _authorRepository.GetAuthorsAsync(skip, paginationFilter.PageSize));

                return(authorsNoFilter);
            }

            var authorsFilter = _mapper.Map <IEnumerable <Author>, IEnumerable <AuthorModel> >
                                    (await _authorRepository.GetAuthorsAsync(skip, paginationFilter.PageSize, filter));

            return(authorsFilter);
        }
Exemplo n.º 15
0
 public AuthorsController(IUnitOfWork uow)
 {
     this.uow = uow;
     af       = new AuthorFilter(uow);
 }
Exemplo n.º 16
0
 public List <Guid> GetFilterAuthorIdsDirectly(AuthorFilter authorFilter)
 {
     return(AuthorRepository.Instance.GetFilterAuthorIdsDirectly(authorFilter));
 }
Exemplo n.º 17
0
        public async Task <IEnumerable <Author> > GetAuthorsAsync(int skip, int pageSize, AuthorFilter filter)
        {
            var authorList = await _dbSet.Include("AuthorInPrintingEditions.PrintingEdition")
                             .Where(a => a.Name.ToLower().Contains(filter.Name.ToLower()))
                             .Skip(skip)
                             .Take(pageSize)
                             .ToListAsync();

            return(authorList);
        }
        public async Task <IActionResult> GetAuthors([FromQuery] PaginationQuery paginationQuery, [FromQuery] AuthorFilter filter)
        {
            var authorResponse = await _authorService.GetAuthorsAsync();

            if (paginationQuery is null || paginationQuery.PageSize < 1 || paginationQuery.PageNumber < 1)
            {
                return(Ok(new PagedResponse <AuthorModel>(authorResponse)));
            }

            authorResponse = await _authorService.GetAuthorsAsync(paginationQuery, filter);

            var paginationResponse = PaginationProvider.CreatePaginatedResponse(_uriService,
                                                                                $"api/{ControllerContext.ActionDescriptor.ControllerName}/{Constants.Routes.AUTHORS_GET_ALL_ROUTE}",
                                                                                paginationQuery, filter,
                                                                                authorResponse);

            return(Ok(paginationResponse));
        }
Exemplo n.º 19
0
        public IActionResult DisplaySearchResults(String TitleString, String AuthorString, int UniqueNumber, int SelectedGenre,
                                                  TitleFilter SelectedTitleFilter, AuthorFilter SelectedAuthorFilter, PopularityFilter SelectedPopularityFilter,
                                                  DateFilter SelectedDateFilter, RatingFilter SelectedRatingFilter, StockFilter SelectedStockFilter)
        {
            List <Book> SelectedBooks = new List <Book>();
            var         query         = from r in _context.Books.Include(b => b.Genre)
                                        select r;

            if (TitleString != null && TitleString != "")
            {
                query = query.Where(r => r.Title.Contains(TitleString));
            }

            if (AuthorString != null && AuthorString != "")
            {
                query = query.Where(r => r.Author.Contains(AuthorString));
            }

            if (UniqueNumber != 0)
            {
                query = query.Where(r => r.UniqueID == UniqueNumber);
            }

            if (SelectedGenre != 0)
            {
                Genre GenreToDisplay = _context.Genres.Find(SelectedGenre);
                query = query.Where(r => r.Genre == GenreToDisplay);
            }

            if (SelectedStockFilter == StockFilter.True)
            {
                query = query.Where(b => b.CopiesOnHand > 0);
            }

            //if no sort
            SelectedBooks = query.Include(b => b.Reviews).ToList();

            if (SelectedTitleFilter == TitleFilter.Ascending)
            {
                SelectedBooks = query.OrderBy(r => r.Title).ToList();
            }
            else if (SelectedTitleFilter == TitleFilter.Descending)
            {
                SelectedBooks = query.OrderByDescending(r => r.Title).ToList();
            }

            if (SelectedAuthorFilter == AuthorFilter.Ascending)
            {
                SelectedBooks = query.OrderBy(r => r.Author).ToList();
            }
            else if (SelectedAuthorFilter == AuthorFilter.Descending)
            {
                SelectedBooks = query.OrderByDescending(r => r.Author).ToList();
            }

            //POPULARTY FILTER CODE
            if (SelectedPopularityFilter == PopularityFilter.Ascending)
            {
                query = query.OrderByDescending(r => r.CopiesSold);
            }
            //don't need filter if not chosen - no else


            if (SelectedDateFilter == DateFilter.Oldest)
            {
                SelectedBooks = query.OrderBy(r => r.PublishedDate).ToList();
            }
            else if (SelectedDateFilter == DateFilter.Newest)
            {
                SelectedBooks = query.OrderByDescending(r => r.PublishedDate).ToList();
            }

            if (SelectedRatingFilter == RatingFilter.Descending)
            {
                //Int32 AvgRating = 0;
                //Int32
                //List<Book> books = _context.Books.Include(b => b.Reviews).Where(b => b.Reviews != null).ToList();
                //foreach(Book b in books)
                //{
                //    AvgRating +=
                //}
                //foreach(Book book in query)
                SelectedBooks = query.OrderByDescending(r => r.AvgRating).ToList();
            }

            //execute the query and store it into the SelectedRepositories list
            //SelectedBooks = query.Include(r => r.Reviews).ToList();
            ViewBag.SelectedBooks = SelectedBooks.Count();
            ViewBag.TotalBooks    = _context.Books.Count();
            //pass the filtered results to display in view
            return(View("Index", SelectedBooks));
        }