コード例 #1
0
        private List <GenreListViewModel> GetGenre()
        {
            var genres = this.genreService.GetAllGenres()
                         .OrderByDescending(x => x.Name).ToList();

            var genre = new GenreListViewModel()
            {
                Id   = null,
                Name = "Изберете жанр",
            };

            genres.Add(genre);
            genres.Reverse();
            return(genres);
        }
        public override void ViewDidLoad()
        {
            base.ViewDidLoad();
            // Perform any additional setup after loading the view, typically from a nib.

            ViewModel = new GenreListViewModel();
            // Setup UITableView.
            refreshControl = new UIRefreshControl();
            refreshControl.ValueChanged += RefreshControl_ValueChanged;
            TableView.Add(refreshControl);
            TableView.Source = new GenreDataSource(ViewModel);

            Title = ViewModel.Title;

            ViewModel.PropertyChanged          += IsBusy_PropertyChanged;
            ViewModel.Genres.CollectionChanged += Items_CollectionChanged;
        }
コード例 #3
0
        public IActionResult Genre(string genre, string sortOrder)
        {
            this.ViewBag.TitleSortParam = string.IsNullOrEmpty(sortOrder) ? "title_desc" : string.Empty;
            this.ViewBag.PriceSortParam = sortOrder == "price_asc" ? "price_desc" : "price_asc";

            var viewModel = new GenreListViewModel
            {
                GenreName = genre,
                Games     = this.searchService.GetAll <GameInListViewModel>()
                            .Where(x => x.GenreName == genre)
                            .OrderBy(x => x.Title),
            };

            if (sortOrder == "title_desc")
            {
                viewModel.Games = this.searchService.GetAll <GameInListViewModel>()
                                  .Where(x => x.GenreName == genre)
                                  .OrderByDescending(x => x.Title);
            }

            if (sortOrder == "price_desc")
            {
                viewModel.Games = this.searchService.GetAll <GameInListViewModel>()
                                  .Where(x => x.GenreName == genre)
                                  .OrderByDescending(x => x.CurrentPrice);
            }

            if (sortOrder == "price_asc")
            {
                viewModel.Games = this.searchService.GetAll <GameInListViewModel>()
                                  .Where(x => x.GenreName == genre)
                                  .OrderBy(x => x.CurrentPrice);
            }

            return(this.View(viewModel));
        }
コード例 #4
0
        public GivenBooksViewModel GetGevenBooks(GivenBooksViewModel model, string userId)
        {
            var firstName        = model.SearchGivenBook.FirstName;
            var lastName         = model.SearchGivenBook.LastName;
            var email            = model.SearchGivenBook.Email;
            var bookName         = model.SearchGivenBook.BookName;
            var author           = model.SearchGivenBook.Author;
            var genreId          = model.SearchGivenBook.GenreId;
            var sortMethodId     = model.SortMethodId;
            var countBooksOfPage = model.CountBooksOfPage;
            var currentPage      = model.CurrentPage;
            var catalogNumber    = model.SearchGivenBook.CatalogNumber;

            var givenBooks = this.context.GetBooks
                             .Where(gb =>
                                    gb.DeletedOn == null &&
                                    gb.Book.UserId == userId)
                             .Select(gb => new GivenBookViewModel()
            {
                Author        = gb.Book.Author,
                Id            = gb.Id,
                BookName      = gb.Book.BookName,
                GenreName     = gb.Book.Genre.Name,
                GenreId       = gb.Book.GenreId,
                CatalogNumber = gb.Book.CatalogNumber,
                FirstName     = gb.User.FirstName,
                LastName      = gb.User.LastName,
                UserName      = gb.User.UserName,

                ReturnedOn = gb.ReturnedOn,
                CreatedOn  = gb.CreatedOn,
            });

            givenBooks = this.SelectBooks(
                bookName,
                author,
                genreId,
                firstName,
                lastName,
                email,
                catalogNumber,
                givenBooks);

            givenBooks = this.SortBooks(sortMethodId, givenBooks);

            var genres = this.genreService.GetAllGenres()
                         .OrderByDescending(x => x.Name).ToList();

            var genre = new GenreListViewModel()
            {
                Id   = null,
                Name = "Изберете жанр",
            };

            genres.Add(genre);
            genres.Reverse();
            int maxCountPage = givenBooks.Count() / countBooksOfPage;

            if (givenBooks.Count() % countBooksOfPage != 0)
            {
                maxCountPage++;
            }

            var viewBook = givenBooks.Skip((currentPage - 1) * countBooksOfPage)
                           .Take(countBooksOfPage);

            var searchGivenBook = new GivenBookViewModel()
            {
                CatalogNumber = catalogNumber,
                Author        = author,
                BookName      = bookName,
                GenreId       = genreId,
            };

            var returnModel = new GivenBooksViewModel()
            {
                Books            = viewBook,
                SearchGivenBook  = searchGivenBook,
                SortMethodId     = sortMethodId,
                Genres           = genres,
                MaxCountPage     = maxCountPage,
                CurrentPage      = currentPage,
                CountBooksOfPage = countBooksOfPage,
            };

            return(returnModel);
        }
コード例 #5
0
        public AllAddedBooksViewModel GetBooks(AllAddedBooksViewModel model)
        {
            var bookCatalogNumber = model.SearchBook.CatalogNumber;
            var title             = model.SearchBook.Title;
            var author            = model.SearchBook.Author;
            var genreId           = model.SearchBook.GenreId;
            var sortMethodId      = model.SortMethodId;
            var countBooksOfPage  = model.CountBooksOfPage;
            var currentPage       = model.CurrentPage;

            var books = this.context.Books.Where(b =>
                                                 b.DeletedOn == null)
                        .Select(b => new BookViewModel()
            {
                Author        = b.Author,
                BookId        = b.Id,
                Title         = b.Title,
                GenreName     = b.Genre.Name,
                GenreId       = b.GenreId,
                CatalogNumber = b.CatalogNumber,
                Logo          = b.Logo,
                Review        = b.Review,
            });

            books = this.SelectBooks(bookCatalogNumber, title, author, genreId, books);

            books = this.SortBooks(sortMethodId, books);

            var genres = this.genreService.GetAllGenres()
                         .OrderByDescending(x => x.Name).ToList();

            var genre = new GenreListViewModel()
            {
                Id   = null,
                Name = "Избери жанр",
            };

            genres.Add(genre);
            genres.Reverse();
            int maxCountPage = books.Count() / countBooksOfPage;

            if (books.Count() % countBooksOfPage != 0)
            {
                maxCountPage++;
            }

            var viewBook = books.Skip((currentPage - 1) * countBooksOfPage)
                           .Take(countBooksOfPage);
            var searchBook = new BookViewModel()
            {
                Author  = author,
                Title   = title,
                GenreId = genreId,
            };

            var returnModel = new AllAddedBooksViewModel()
            {
                Books            = viewBook,
                SearchBook       = searchBook,
                SortMethodId     = sortMethodId,
                Genres           = genres,
                MaxCountPage     = maxCountPage,
                CurrentPage      = currentPage,
                CountBooksOfPage = countBooksOfPage,
            };

            return(returnModel);
        }
コード例 #6
0
        private TakenBooksViewModel GetBooks(TakenBooksViewModel model, string userId)
        {
            var title            = model.SearchTakenBook.Title;
            var author           = model.SearchTakenBook.Author;
            var genreId          = model.SearchTakenBook.GenreId;
            var sortMethodId     = model.SortMethodId;
            var countBooksOfPage = model.CountBooksOfPage;
            var currentPage      = model.CurrentPage;
            var catalogNumber    = model.SearchTakenBook.CatalogNumber;

            var getbooks = this.context.GetBooks.Where(b =>
                                                       b.DeletedOn == null &&
                                                       b.UserId == userId)
                           .Select(b => new TakenBookViewModel()
            {
                Author        = b.Book.Author,
                Id            = b.Id,
                Title         = b.Book.Title,
                Genre         = b.Book.Genre.Name,
                GenreId       = b.Book.GenreId,
                CreatedOn     = b.CreatedOn,
                ReturnedOn    = b.ReturnedOn,
                LibraryId     = b.Book.UserId,
                LibraryEmail  = b.Book.User.Email,
                CatalogNumber = b.Book.CatalogNumber,
            });

            getbooks = this.SelectBooks(catalogNumber, title, author, genreId, getbooks);

            getbooks = this.SortBooks(sortMethodId, getbooks);

            var genres = this.genreService.GetAllGenres()
                         .OrderByDescending(x => x.Name).ToList();

            var genre = new GenreListViewModel()
            {
                Id   = null,
                Name = "Избери жанр",
            };

            genres.Add(genre);
            genres.Reverse();
            int maxCountPage = getbooks.Count() / countBooksOfPage;

            if (getbooks.Count() % countBooksOfPage != 0)
            {
                maxCountPage++;
            }

            var viewBook = getbooks.Skip((currentPage - 1) * countBooksOfPage)
                           .Take(countBooksOfPage);
            var searchTakenBook = new TakenBookViewModel()
            {
                Author  = author,
                Title   = title,
                GenreId = genreId,
            };

            var returnModel = new TakenBooksViewModel()
            {
                Books            = getbooks,
                SearchTakenBook  = searchTakenBook,
                SortMethodId     = sortMethodId,
                Genres           = genres,
                MaxCountPage     = maxCountPage,
                CurrentPage      = currentPage,
                CountBooksOfPage = countBooksOfPage,
            };

            return(returnModel);
        }
コード例 #7
0
 public GenreListPage(GenreListViewModel viewModel)
 {
     InitializeComponent();
     this.DataContext = viewModel;
 }
コード例 #8
0
        public AllBooksViewModel GetAllBooks(string userId, string bookName,
                                             string author, string genreId, string sortMethodId,
                                             int currentPage, int CountBooksOfPage)
        {
            var books = context.Books.Where(b =>
                                            b.DeletedOn == null &&
                                            b.UserId == userId)
                        .Select(b => new BookViewModel()
            {
                Author    = b.Author,
                BookId    = b.Id,
                BookName  = b.BookName,
                GenreName = b.Genre.Name,
                GenreId   = b.GenreId
            });

            if (bookName != null)
            {
                books = books.Where(b => b.BookName.Contains(bookName));
            }

            if (author != null)
            {
                books = books.Where(b => b.Author.Contains(author));
            }

            if (genreId != null)
            {
                books = books.Where(b => b.GenreId == genreId);
            }

            if (sortMethodId == "Име на книгата я-а")
            {
                books = books.OrderByDescending(b => b.BookName);
            }
            else if (sortMethodId == "Име на автора а-я")
            {
                books = books.OrderBy(b => b.Author);
            }
            else if (sortMethodId == "Име на автора я-а")
            {
                books = books.OrderByDescending(b => b.Author);
            }
            else if (sortMethodId == "Жанр а-я")
            {
                books = books.OrderBy(b => b.GenreName);
            }
            else if (sortMethodId == "Жанр я-а")
            {
                books = books.OrderByDescending(b => b.GenreName);
            }
            else
            {
                books = books.OrderBy(b => b.BookName);
            }

            var genres = GetAllGenres().OrderByDescending(x => x.Name).ToList();

            var genre = new GenreListViewModel()
            {
                Id   = null,
                Name = "Изберете жанр"
            };

            genres.Add(genre);
            genres.Reverse();
            int maxCountPage = books.Count() / CountBooksOfPage;

            if (books.Count() % CountBooksOfPage != 0)
            {
                maxCountPage++;
            }

            var viewBook = books.Skip((currentPage - 1) * CountBooksOfPage)
                           .Take(CountBooksOfPage);


            var model = new AllBooksViewModel()
            {
                Books            = viewBook,
                Author           = author,
                BookName         = bookName,
                GenreId          = genreId,
                SortMethodId     = sortMethodId,
                Genres           = genres,
                MaxCountPage     = maxCountPage,
                CurrentPage      = currentPage,
                CountBooksOfPage = CountBooksOfPage
            };

            return(model);
        }
 public GenreDataSource(GenreListViewModel viewModel)
 {
     this.viewModel = viewModel;
 }