using Library.Domain.Abstract;
using Library.Presentation.Models;
using System.Linq;
using System.Web.Mvc;

namespace Library.Presentation.Controllers
{
    public class NavigationController : Controller
    {
        private IBookRepository repository;

        public NavigationController(IBookRepository repository)
        {
            this.repository = repository;
        }

        public PartialViewResult GenresMenu(string genre = null)
        {
            NavigationViewModel navigationModel = new NavigationViewModel
            {
                Genres = repository.Books
                            .Select(b => b.Genre)
                            .Distinct()
                            .OrderBy(g => g),
                SelectedGenre = genre
            };
            return PartialView(navigationModel);
        }
    }
}