<commit_before>﻿using System.Data.Entity;
using System.Linq;
using System.Web.Mvc;
using AstroPhotoGallery.Extensions;
using AstroPhotoGallery.Models;
using PagedList;

namespace AstroPhotoGallery.Controllers
{
    public class HomeController : Controller
    {
        //
        //GET: Home/Index
        public ActionResult Index()
        {
            using (var db = new GalleryDbContext())
            {
                //Get pictures from database
                var categories = db.Categories
                   .Include(c => c.Pictures)
                   .OrderBy(c => c.Name)
                   .Take(4)
                   .ToList();

                return View(categories);
            }
        }

        //
        //GET: Home/ListCategories
        public ActionResult ListCategories(string searchString, int? page, string currentFilter)
        {
            if (searchString != null)
            {
                page = 1;
            }
            else
            {
                searchString = currentFilter;
            }

            ViewBag.CurrentFilter = searchString;

            using (var db = new GalleryDbContext())
            {
                var categories = db.Categories
                    .Include(c => c.Pictures)
                    .OrderBy(c => c.Name)
                    .ToList();

                if (categories.Count == 0)
                {
                    this.AddNotification("No categories found.", NotificationType.ERROR);

                    return RedirectToAction("Index");
                }

                if (!string.IsNullOrEmpty(searchString))
                {
                    categories = categories
                        .Where(c => c.Name.ToLower()
                        .Contains(searchString.ToLower()))
                        .ToList();
                }

                int pageSize = 8;
                int pageNumber = (page ?? 1);

                return View(categories.ToPagedList(pageNumber, pageSize));
            }

        }

        //
        //GET: Home/ListPictures/id
        public ActionResult ListPictures(int? categoryId)
        {
            if (categoryId == null)
            {
                this.AddNotification("No category ID provided.", NotificationType.ERROR);
                return RedirectToAction("Index");
            }

            using (var db = new GalleryDbContext())
            {
                var category = db.Categories.FirstOrDefault(c => c.Id == categoryId);

                if (category == null)
                {
                    this.AddNotification("Category doesn't exist.", NotificationType.ERROR);
                    return RedirectToAction("Index");
                }

                TempData["CategoryName"] = category.Name;

                var pictures = db.Pictures
                    .Where(p => p.CategoryId == categoryId)
                    .Include(p => p.PicUploader)
                    .Include(p=>p.Tags)
                    .ToList();

                return View(pictures);
            }
        }
    }
}<commit_msg>change number of pics to be pulled from the DB<commit_after>﻿using System.Data.Entity;
using System.Linq;
using System.Web.Mvc;
using AstroPhotoGallery.Extensions;
using AstroPhotoGallery.Models;
using PagedList;

namespace AstroPhotoGallery.Controllers
{
    public class HomeController : Controller
    {
        //
        //GET: Home/Index
        public ActionResult Index()
        {
            using (var db = new GalleryDbContext())
            {
                //Get pictures from database
                var categories = db.Categories
                   .Include(c => c.Pictures)
                   .OrderBy(c => c.Name)
                   .Take(6)
                   .ToList();

                return View(categories);
            }
        }

        //
        //GET: Home/ListCategories
        public ActionResult ListCategories(string searchString, int? page, string currentFilter)
        {
            if (searchString != null)
            {
                page = 1;
            }
            else
            {
                searchString = currentFilter;
            }

            ViewBag.CurrentFilter = searchString;

            using (var db = new GalleryDbContext())
            {
                var categories = db.Categories
                    .Include(c => c.Pictures)
                    .OrderBy(c => c.Name)
                    .ToList();

                if (categories.Count == 0)
                {
                    this.AddNotification("No categories found.", NotificationType.ERROR);

                    return RedirectToAction("Index");
                }

                if (!string.IsNullOrEmpty(searchString))
                {
                    categories = categories
                        .Where(c => c.Name.ToLower()
                        .Contains(searchString.ToLower()))
                        .ToList();
                }

                int pageSize = 6;
                int pageNumber = (page ?? 1);

                return View(categories.ToPagedList(pageNumber, pageSize));
            }
        }

        //
        //GET: Home/ListPictures/id
        public ActionResult ListPictures(int? categoryId)
        {
            if (categoryId == null)
            {
                this.AddNotification("No category ID provided.", NotificationType.ERROR);
                return RedirectToAction("Index");
            }

            using (var db = new GalleryDbContext())
            {
                var category = db.Categories.FirstOrDefault(c => c.Id == categoryId);

                if (category == null)
                {
                    this.AddNotification("Category doesn't exist.", NotificationType.ERROR);
                    return RedirectToAction("Index");
                }

                TempData["CategoryName"] = category.Name;

                var pictures = db.Pictures
                    .Where(p => p.CategoryId == categoryId)
                    .Include(p => p.PicUploader)
                    .Include(p => p.Tags)
                    .ToList();

                return View(pictures);
            }
        }

        public ActionResult Contacts()
        {
            return View();
        }

        public ActionResult About()
        {
            return View();
        }
    }
}
{'fraction_non_alphanumeric': 0.09311804358049851, 'fraction_numerical': 0.0015676438313215238, 'mean_word_length': 1.15467747382641, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 21, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '937359', 'n_tokens_mistral': 1599, 'n_tokens_neox': 1445, 'n_words': 324}