Beispiel #1
0
        public async Task <IActionResult> Index()
        {
            AllFilesViewModel model = new AllFilesViewModel
            {
                Images = await _context.Images.Where(s => s.StartImage == 1).ToListAsync <Images>()
            };


            List <int> distinctCategoryIds = new List <int>();

            foreach (Images img in model.Images)
            {
                if (!distinctCategoryIds.Contains(img.CategoryId))
                {
                    distinctCategoryIds.Add(img.CategoryId);
                }
            }

            List <FileCategories> categories = new List <FileCategories>();

            foreach (int id in distinctCategoryIds)
            {
                categories.Add(await _context.FileCategories.FirstAsync <FileCategories>(i => i.CategoryId == id));
            }

            model.Categories = categories;

            return(View(model));

            /*
             * List<Images> model = await _context.Images.Where(s => s.StartImage == 1).ToListAsync();
             *
             * return View(model);
             */
        }
Beispiel #2
0
        public async Task <IActionResult> Start()
        {
            AllFilesViewModel model = new AllFilesViewModel
            {
                Images = await _context.Images.Where(p => p.IsPublished == 1).ToListAsync <Images>()
            };
            var SortedImages = model.Images.OrderByDescending(x => x.PublishedDate).ToList();

            model.Images = SortedImages;

            List <int> distinctCategoryIds = new List <int>();

            foreach (Images img in model.Images)
            {
                if (!distinctCategoryIds.Contains(img.CategoryId))
                {
                    distinctCategoryIds.Add(img.CategoryId);
                }
            }

            List <FileCategories> categories = new List <FileCategories>();

            foreach (int id in distinctCategoryIds)
            {
                categories.Add(await _context.FileCategories.FirstAsync <FileCategories>(i => i.CategoryId == id));
            }

            model.Categories = categories;

            return(View(model));
        }
Beispiel #3
0
        public async Task <IActionResult> Index()
        {
            if (!HttpContext.Session.Keys.Contains <string>("Authenticated"))
            {
                return(View("Unauthorized"));
            }

            AllFilesViewModel model = new AllFilesViewModel
            {
                Images      = await _context.Images.ToListAsync <Images>(),
                Files       = await _context.Files.ToListAsync <Files>(),
                Categories  = await _context.FileCategories.ToListAsync <FileCategories>(),
                FileFolders = await _context.Folders.ToListAsync <Folders>()
            };

            model.Categories = model.Categories.OrderBy <FileCategories, int>(i => i.CategoryId);
            model.Images     = model.Images.OrderByDescending <Images, DateTime>(t => t.UploadedDate);
            model.Files      = model.Files.OrderByDescending <Files, DateTime>(t => t.UploadedDate);

            return(View(model));
        }