using CD67.FicheCollege.Entity;
using CD67.FicheCollege.Factory;
using CD67.FicheCollege.MVC.Models;
using System.Net;
using System.Web.Mvc;

namespace CD67.FicheCollege.MVC.Controllers
{
    public class RestaurationController : Controller
    {
        private Entities db = new Entities();

        // GET: Actions
        public ActionResult Index(int? annee_id)
        {
            if (annee_id == null)
            {
                return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
            }
            AnneeFactory fact = new AnneeFactory(db);
            Annee annee = fact.getById(annee_id);
            AnneeViewModel model = new AnneeViewModel(annee, db, ModeAcces.Lecture);

            RestaurationParametreFactory paramFactory = new RestaurationParametreFactory(db);
            RestaurationParametre param = paramFactory.getBy(x => x.Annee_Id == annee_id.Value);

            if (param == null)
                ViewBag.Ouverture = false;
            else
                ViewBag.Ouverture = param.Campagne;

            return View(model);
        }


        protected override void Dispose(bool disposing)
        {
            if (disposing)
            {
                db.Dispose();
            }
            base.Dispose(disposing);
        }
    }
}