Пример #1
0
        public ListBooksViewModel GetPreviousReadBooks(string userId, SearchViewModel model)
        {
            ListBooksViewModel View = new ListBooksViewModel();
            List <BookModel>   books;
            List <Guid>        booksId = new List <Guid>();

            View.HoldersList      = _holdersService.GetIdBooksByUser(userId);
            View.NotificationList = _notificationService.GetIdBooksByUser(userId);

            var logs = _statusLogService.GetList(userId);

            foreach (var log in logs)
            {
                if (log.Operation == Operations.Returned && !View.HoldersList.Contains(log.BookId))
                {
                    booksId.Add(log.BookId);
                }
            }

            if (model != null)
            {
                books = _bookService.GetBooks(booksId.Distinct().ToList(), model);
            }
            else
            {
                books = _bookService.GetBooks(booksId.Distinct().ToList());
            }

            View.Books = GetListBooks(books, userId);

            return(View);
        }
Пример #2
0
        public void Setup()
        {
            var firebaseRemoteConfMok = new Mock <IRemoteConfig>();

            firebaseRemoteConfMok.Setup(x => x.GetRemoteDataString("Print_Type"))
            .Returns("books");

            ViewModel  = new ListBooksViewModel(firebaseRemoteConfMok.Object);
            restClient = new Mock <RestClient>().Object;
        }
Пример #3
0
        public IActionResult ListBooks([FromForm] PageInfoModel pageInfo, [FromForm] SearchViewModel model)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    ListBooksViewModel result = null;

                    switch (pageInfo.ActionName.Replace("/", ""))
                    {
                    case "AllBooks":
                        result = _libraryLogic.GetAllBook(this.CurrentUser(), model);
                        break;

                    case "CurrentReadList":
                        result = _libraryLogic.GetCurrentReadBooks(this.CurrentUser(), model);
                        break;

                    case "PreviousReadList":
                        result = _libraryLogic.GetPreviousReadBooks(this.CurrentUser(), model);
                        break;
                    }

                    if (result != null)
                    {
                        result.PageView = pageInfo.PageItems;

                        if (pageInfo.PageItems == 1)
                        {
                            pageInfo.PageItems = 4;
                        }


                        result.Search = model;

                        ViewBag.Pagination = Pagination(pageInfo, result);

                        result.Books = result.Books.OrderByDescending(book => (book.Aviable != 0)).ThenBy(book => book.Title).Skip((pageInfo.Page - 1) * pageInfo.PageItems).Take(pageInfo.PageItems).ToList();

                        return(PartialView(result));
                    }

                    return(PartialView(result));
                }
                else
                {
                    return(BadRequest());
                }
            }
            catch (Exception ex)
            {
                return(BadRequest(ex.Message));
            }
        }
        public ActionResult List(int?page, string query, string searchType)
        {
            Regex regexForTwoPagesCountNumbers = new Regex(@"(\d+)\W(\d+)");
            var   pageNumber = page ?? 1;
            var   books      = this.Data.Books.All()
                               .OrderByDescending(b => b.CreatedOn)
                               .Select(BookInListViewModel.Create)
                               .ToList();
            var viewModel = new ListBooksViewModel();

            if (!string.IsNullOrEmpty(query))
            {
                switch (searchType)
                {
                case "1":
                    books = books.Where(b => b.Name.ToLower().Equals(query.ToLower())).ToList();
                    break;

                case "2":
                    books = books.Where(b => b.Genre.ToLower().Equals(query.ToLower())).ToList();
                    break;

                case "3":
                    Match matchNumbers = regexForTwoPagesCountNumbers.Match(query);
                    if (matchNumbers.Groups.Count == 3)
                    {
                        var firstNumber  = Int32.Parse(matchNumbers.Groups[1].Value);
                        var secondNumber = Int32.Parse(matchNumbers.Groups[2].Value);
                        books = books.Where(b => b.PageCount >= firstNumber && b.PageCount <= secondNumber).ToList();
                        break;
                    }
                    Regex regexForOnePagesCountNumber = new Regex(@"(\d+)");
                    matchNumbers = regexForOnePagesCountNumber.Match(query);
                    var number = Int32.Parse(matchNumbers.Groups[1].Value);
                    books = books.Where(b => b.PageCount >= number).ToList();
                    break;
                }

                viewModel.SearchBooks = books;
                return(PartialView("_SearchBooksPartial", viewModel));
            }

            var pageOfBooks = books.ToPagedList(pageNumber, 7);

            viewModel.Books = pageOfBooks;

            if ((Request.IsAjaxRequest() && string.IsNullOrEmpty(query)))
            {
                return(PartialView("_ListBooksPartial", viewModel));
            }

            return(View(viewModel));
        }
Пример #5
0
        /// <summary>
        /// Возвращает модель пагинации страницы
        /// </summary>
        /// <param name="pageInfo"> Информация о странице </param>
        /// <param name="books"> Список книг страницы </param>
        /// <returns> Модель пагинации страницы</returns>
        public static Pagination Pagination(PageInfoModel pageInfo, ListBooksViewModel books)
        {
            Pagination pagination = new Pagination
            {
                PageItemsAmount       = pageInfo.PageItems,
                CurrentPage           = pageInfo.Page,
                ControllerName        = "Library",
                ActionName            = pageInfo.ActionName.Replace("/", ""),
                ShowLastAndFirstPages = true
            };

            pagination.ItemsAmount = books.Books.Count();
            pagination.Refresh();

            return(pagination);
        }
Пример #6
0
        public ListBooksViewModel GetAllBook(string userId, SearchViewModel model)
        {
            ListBooksViewModel View = new ListBooksViewModel();
            List <BookModel>   books;

            if (model != null)
            {
                books = _bookService.GetAllBooks(model);
            }
            else
            {
                books = _bookService.GetAllBooks();
            }

            View.Books            = GetListBooks(books, userId);
            View.HoldersList      = _holdersService.GetIdBooksByUser(userId);
            View.NotificationList = _notificationService.GetIdBooksByUser(userId);

            return(View);
        }
Пример #7
0
 public ListBookxPage()
 {
     InitializeComponent();
     this.BindingContext = ViewModel = (Application.Current as App).Container.Resolve <ListBooksViewModel>();
 }