﻿// Copyright (c) 2018 Nikolay Zahariev <zahasoft.com>. Licensed under the MIT License.

namespace Zahasoft.Weblog.Present.Controllers
{
    using Domain;
    using Services;
    using System.Web.Mvc;

    public class WordsController : BaseController
    {
        readonly IWordService wordService;

        public WordsController(IWordService wordService)
        {
            this.wordService = wordService;
        }

        // GET: /words
        [AllowAnonymous]
        public ActionResult Index()
        {
            var words = wordService.FindWords();

            if (words == null)
            {
                RedirectToError();
            }

            return PartialView(words);
        }

        // GET: /words/show/{slug}
        [AllowAnonymous]
        public ActionResult Show(string slug)
        {
            if (slug == null)
            {
                return RedirectToError();
            }

            Word word = wordService.FindWordBySlug(slug);

            if (word == null)
            {
                return RedirectToError();
            }

            return PartialView(word);
        }
    }
}
