// GET: Downloads
        public async Task <IActionResult> Index(
            string sortOrder,
            string currentFilter,
            string searchString,
            int?page,
            bool showDisabled = false)
        {
            ViewData["CurrentSort"]    = sortOrder;
            ViewData["NameSortParm"]   = string.IsNullOrEmpty(sortOrder) ? "name_desc" : "";
            ViewData["DateSortParm"]   = sortOrder == "Date" ? "date_desc" : "Date";
            ViewData["AmountSortParm"] = sortOrder == "amount" ? "amount_desc" : "amount";

            if (searchString != null)
            {
                page = 1;
            }
            else
            {
                searchString = currentFilter;
            }

            ViewData["CurrentFilter"] = searchString;

            ViewBag.ShowDisabled = showDisabled;

            var downloads = _downloadRepository.GetAll().Where(d => !d.Deleted && (d.Enabled || showDisabled) && (string.IsNullOrEmpty(searchString) || d.Title.Contains(searchString)));

            switch (sortOrder)
            {
            case "name_desc":
                downloads = downloads.OrderByDescending(c => c.Title);
                break;

            case "Date":
                downloads = downloads.OrderBy(c => c.Date);
                break;

            case "date_desc":
                downloads = downloads.OrderByDescending(c => c.Date);
                break;

            case "amount":
                downloads = downloads.OrderBy(c => c.AmountOfDownloads);
                break;

            case "amount_desc":
                downloads = downloads.OrderByDescending(c => c.AmountOfDownloads);
                break;

            default:
                downloads = downloads.OrderBy(c => c.Title);
                break;
            }
            return(View(new DownloadViewModel
            {
                DownloadsList = await PaginatedList <Download> .Create(downloads, page ?? 1, 5),
                DownloadsWithoutTranslation = await _itemTranslationRepository.GetDownloadsWithoutTranslation()
            }));
        }
        public async Task <IActionResult> Index(int?page)
        {
            var language = HttpContext?.Features?.Get <IRequestCultureFeature>()?.RequestCulture?.Culture
                           ?.TwoLetterISOLanguageName ?? "nl";
            var viewModel = new DownloadsViewModel
            {
                MostDownloaded = await _downloadRepository.GetAll().Where(d => d.Enabled && !d.Deleted && d.Language == language).OrderByDescending(d => d.AmountOfDownloads)
                                 .FirstOrDefaultAsync(),
                MostRecent = await _downloadRepository.GetAll().Where(d => d.Enabled && !d.Deleted && d.Language == language).OrderByDescending(d => d.Date).FirstOrDefaultAsync()
            };
            var all = _downloadRepository.GetAll().Where(d => d.Id != viewModel.MostDownloaded.Id && d.Enabled && !d.Deleted && d.Language == language)
                      .OrderBy(d => d.Date);

            viewModel.AllDownloads = await PaginatedList <Download> .Create(all, page ?? 1, 10);

            return(View(viewModel));
        }
示例#3
0
        /// <summary>
        /// Gets a download by GUID
        /// </summary>
        /// <param name="downloadGuid">Download GUID</param>
        /// <returns>Download</returns>
        public virtual Download GetDownloadByGuid(Guid downloadGuid)
        {
            if (downloadGuid == Guid.Empty)
            {
                return(null);
            }

            var query = from o in _downloadRepository.GetAll()
                        where o.DownloadGuid == downloadGuid
                        select o;
            var order = query.FirstOrDefault();

            return(order);
        }