Ejemplo n.º 1
0
        //public async Task<IActionResult> Index()
        //{
        //    int page = 1;
        //    int pageSize = 30;   // количество элементов на странице

        //    var source = db.Torrents.Take(pageSize).ToList();
        //    var count = await db.Torrents.CountAsync();
        //    PageInfo pageViewModel = new PageInfo(count, page, pageSize);
        //    TorrentViewModel viewModel = new TorrentViewModel
        //    {
        //        PageInfo = pageViewModel,
        //        torrents = source
        //    };
        //    return View("Index", viewModel);
        //}

        //public async Task<IActionResult> PageHelper(string s, int page = 1)
        //{
        //    int pageSize = 30;
        //    var query = db.Torrents.Where(p => string.IsNullOrWhiteSpace(s) || EF.Functions.Like(p.Title, $"%{s}%"));
        //    var count = await query.CountAsync();
        //    var torents = await query.Skip((page - 1) * pageSize).Take(pageSize).ToArrayAsync();
        //    PageInfo pageViewModel = new PageInfo(count, page, pageSize);
        //    TorrentViewModel viewModel = new TorrentViewModel
        //    {
        //        PageInfo = pageViewModel,
        //        torrents = torents,
        //        SearchString = s
        //    };
        //    return View(viewModel);
        //}

//Delete me please
        public async Task <IActionResult> Index(string s, int page = 1)
        {
            IQueryable <Torrent> query;
            int count;
            int pageSize = 30;   // количество элементов на странице

            if (s == null)
            {
                count = await db.Torrents.CountAsync();

                query = db.Torrents.Take(count);
            }
            else
            {
                query = db.Torrents.Where(p => string.IsNullOrWhiteSpace(s) || EF.Functions.Like(p.Title, $"%{s}%"));
                count = await query.CountAsync();
            }

            var torents = await query.Skip((page - 1) *pageSize).Take(pageSize).ToArrayAsync();

            PageInfo         pageViewModel = new PageInfo(count, page, pageSize);
            TorrentViewModel viewModel     = new TorrentViewModel
            {
                PageInfo     = pageViewModel,
                torrents     = torents,
                SearchString = s
            };
            var source = db.Torrents.Take(pageSize).ToList();

            return(View(viewModel));
        }
Ejemplo n.º 2
0
        public ActionResult Torrents(string type, int page = 1)
        {
            int pageSize = 10;

            if (type != null)
            {
                try
                {
                    this.torrentViewMdel = new TorrentViewModel
                    {
                        Torrents = this.torrentManager
                                   .GetTorrents(type)
                                   .ToPagedList(page, pageSize)
                    };
                }
                catch (ArgumentException ex)
                {
                    return(RedirectToAction("ErrorPage", new { error = ex.Message }));
                }
            }
            else
            {
                this.torrentViewMdel = new TorrentViewModel
                {
                    Torrents = this.torrentManager
                               .GetTorrents()
                               .ToPagedList(page, pageSize)
                }
            };
            return(View(this.torrentViewMdel));
        }
Ejemplo n.º 3
0
        public ViewModelBase()
        {
            SelectedTorrentFilesViewModel    = new SelectedTorrentFilesViewModel();
            SelectedTorrentInfoViewModel     = new SelectedTorrentInfoViewModel();
            SelectedTorrentPeersViewModel    = new SelectedTorrentPeersViewModel();
            SelectedTorrentTrackersViewModel = new SelectedTorrentTrackersViewModel();
            TorrentViewModel = new TorrentViewModel();

            OpenFileDialogCommand   = new OpenFileDialogCommand(this, new OpenFileDialogViewModel());
            SelectionChangedCommand = new SelectionChangedCommand(this);
            StartDownloadCommand    = new StartDownloadCommand(this, SelectedTorrentInfoViewModel);
            PauseDownloadCommand    = new PauseDownloadCommand(this, SelectedTorrentInfoViewModel);
        }
Ejemplo n.º 4
0
        public ActionResult Torrent(int id, int page = 1)
        {
            int pageSize = 5;

            try
            {
                this.torrentViewMdel = new TorrentViewModel
                {
                    Torrent         = this.torrentManager.GetTorrent(id),
                    Comments        = this.torrentManager.GetComments(id).ToPagedList(page, pageSize),
                    PopularTorrents = this.torrentManager.GetPopularTorrents()
                };
            }
            catch (ArgumentException ex)
            {
                return(RedirectToAction("ErrorPage", new { error = ex.Message }));
            }
            return(View(this.torrentViewMdel));
        }