示例#1
0
        public GetPublisherViewModel GetAll()
        {
            var publisherEntities = _publisherRepository.GetAll();
            var publisherViews    = new GetPublisherViewModel();

            publisherViews.Publishers = Mapper.Map <IEnumerable <Publisher>, List <GetPublisherViewItem> >(publisherEntities);
            return(publisherViews);
        }
示例#2
0
        public List <PublisherDTO> GetAll(int license = 0)
        {
            List <PublisherDTO> result = new List <PublisherDTO>();

            foreach (Publisher publisher in _publisherRepository.GetAll(license))
            {
                result.Add(Mapping.CreatorFromDalToBl(publisher));
            }
            return(result);
        }
        public void TestPublisherRepo_GetAll()
        {
            //Arrange
            PublisherRepository TestRepo = CreatePublisherTestRepo("PublisherGetAll");

            //Act
            var result = TestRepo.GetAll();

            //Assert
            Assert.IsTrue(result.Count() == _PublisherNumber);
        }
 public PublisherQuery(PublisherRepository repository)
 {
     FieldAsync <ListGraphType <PublisherType> >(
         name: "publishers",
         resolve: async context => await repository.GetAll()
         );
     FieldAsync <PublisherType>(
         name: "publisher",
         arguments: new QueryArguments(new QueryArgument <NonNullGraphType <IdGraphType> >
     {
         Name        = "Id",
         Description = "The id of the publisher you want to return"
     }),
         resolve: async context =>
     {
         var id = context.GetArgument <string>("Id");
         return(await repository.GetById(Guid.Parse((ReadOnlySpan <char>)id)));
     }
         );
 }
 private void LoadData()
 {
     publishers = publisherRepository.GetAll();
     authors    = authorRepository.GetAll();
     AddNewAuthorIfEmpty();
 }
 public List <Publisher> GetAll()
 {
     return(_publisherRepository.GetAll().ToList());
 }
示例#7
0
        public IEnumerable <Publisher> Get()
        {
            PublisherRepository r = new PublisherRepository();

            return(r.GetAll());
        }
        //
        // GET: /Books

        public ViewResult Index(int?page, int?pageSize, string sortBy, bool?sortDesc, int?PublisherId)
        {
            // Defaults
            if (!page.HasValue)
            {
                page = 1;
            }
            if (!pageSize.HasValue)
            {
                pageSize = 10;
            }

            IQueryable <Book> query = repository.GetAll().AsQueryable();
            // Filtering
            List <SelectListItem> selectList;

            if (PublisherId != null)
            {
                query = query.Where(x => x.PublisherId == PublisherId);
                ViewBag.PublisherId = PublisherId;
            }
            selectList = new List <SelectListItem>();
            selectList.Add(new SelectListItem()
            {
                Text = null, Value = null, Selected = PublisherId == null
            });
            selectList.AddRange(PublisherRepository.GetAll().ToList().Select(x => new SelectListItem()
            {
                Text = x.Name.ToString(), Value = x.Id.ToString(), Selected = PublisherId != null && PublisherId == x.Id
            }));
            ViewBag.Publishers        = selectList;
            ViewBag.SelectedPublisher = selectList.Where(x => x.Selected).Select(x => x.Text).FirstOrDefault();

            // Paging
            int pageCount = (int)((query.Count() + pageSize - 1) / pageSize);

            if (page > 1)
            {
                query = query.Skip((page.Value - 1) * pageSize.Value);
            }
            query = query.Take(pageSize.Value);
            if (page > 1)
            {
                ViewBag.Page = page.Value;
            }
            if (pageSize != 10)
            {
                ViewBag.PageSize = pageSize.Value;
            }
            if (pageCount > 1)
            {
                int       currentPage  = page.Value;
                const int visiblePages = 5;
                const int pageDelta    = 2;
                List <Tuple <string, bool, int> > paginationData = new List <Tuple <string, bool, int> >();           // text, enabled, page index
                paginationData.Add(new Tuple <string, bool, int>("Prev", currentPage > 1, currentPage - 1));
                if (pageCount <= visiblePages * 2)
                {
                    for (int i = 1; i <= pageCount; i++)
                    {
                        paginationData.Add(new Tuple <string, bool, int>(i.ToString(), true, i));
                    }
                }
                else
                {
                    if (currentPage < visiblePages)
                    {
                        // 12345..10
                        for (int i = 1; i <= visiblePages; i++)
                        {
                            paginationData.Add(new Tuple <string, bool, int>(i.ToString(), true, i));
                        }
                        paginationData.Add(new Tuple <string, bool, int>("...", false, -1));
                        paginationData.Add(new Tuple <string, bool, int>(pageCount.ToString(), true, pageCount));
                    }
                    else if (currentPage > pageCount - (visiblePages - 1))
                    {
                        // 1..678910
                        paginationData.Add(new Tuple <string, bool, int>("1", true, 1));
                        paginationData.Add(new Tuple <string, bool, int>("...", false, -1));
                        for (int i = pageCount - (visiblePages - 1); i <= pageCount; i++)
                        {
                            paginationData.Add(new Tuple <string, bool, int>(i.ToString(), true, i));
                        }
                    }
                    else
                    {
                        // 1..34567..10
                        paginationData.Add(new Tuple <string, bool, int>("1", true, 1));
                        paginationData.Add(new Tuple <string, bool, int>("...", false, -1));
                        for (int i = currentPage - pageDelta, count = currentPage + pageDelta; i <= count; i++)
                        {
                            paginationData.Add(new Tuple <string, bool, int>(i.ToString(), true, i));
                        }
                        paginationData.Add(new Tuple <string, bool, int>("...", false, -1));
                        paginationData.Add(new Tuple <string, bool, int>(pageCount.ToString(), true, pageCount));
                    }
                }
                paginationData.Add(new Tuple <string, bool, int>("Next", currentPage < pageCount, currentPage + 1));
                ViewBag.PaginationData = paginationData;
            }

            // Sorting
            if (!string.IsNullOrEmpty(sortBy))
            {
                bool ascending = !sortDesc.HasValue || !sortDesc.Value;
                if (sortBy == "ISBN")
                {
                    query = OrderBy(query, x => x.ISBN, ascending);
                }
                if (sortBy == "Publisher")
                {
                    query = OrderBy(query, x => x.PublisherId, ascending);
                }
                if (sortBy == "Langauge")
                {
                    query = OrderBy(query, x => x.Langauge, ascending);
                }
                if (sortBy == "ArDescription")
                {
                    query = OrderBy(query, x => x.ArDescription, ascending);
                }
                if (sortBy == "EnDescription")
                {
                    query = OrderBy(query, x => x.EnDescription, ascending);
                }
                if (sortBy == "Category")
                {
                    query = OrderBy(query, x => x.Category, ascending);
                }
                if (sortBy == "Price")
                {
                    query = OrderBy(query, x => x.Price, ascending);
                }
                ViewBag.SortBy = sortBy;
                if (sortDesc != null && sortDesc.Value)
                {
                    ViewBag.SortDesc = sortDesc.Value;
                }
            }

            ViewBag.Entities = query.ToList();
            return(View());
        }