using System;
using System.Collections.Generic;
using System.Data;
using System.Data.Entity;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using TFC.Context;
using TFC.Models;

namespace TFC.Controllers
{ 
    public class ExerciceController : Controller
    {
        private DataContext db = new DataContext();

        
        //
        // GET: /Exercice/
        //[Authorize(Roles = "Trainer")]
        public ViewResult Index()
        {
            return View(db.Exercice.ToList());
        }

        //
        // GET: /Exercice/Details/5
        [Authorize(Roles = "Trainer")]
        public ViewResult Details(int id)
        {
            Exercice Exercice = db.Exercice.Find(id);
            return View(Exercice);
        }

        //
        // GET: /Exercice/Create
        [Authorize(Roles = "Trainer")]
        public ActionResult Create()
        {
            return View();
        } 

        //
        // POST: /Exercice/Create

        [HttpPost]
        public ActionResult Create(Exercice Exercice)
        {
            if (ModelState.IsValid)
            {
                db.Exercice.Add(Exercice);
                db.SaveChanges();
                return RedirectToAction("Index");  
            }

            return View(Exercice);
        }
        
        //
        // GET: /Exercice/Edit/5
        [Authorize(Roles = "Trainer")] 
        public ActionResult Edit(int id)
        {
            Exercice Exercice = db.Exercice.Find(id);
            return View(Exercice);
        }

        //
        // POST: /Exercice/Edit/5

        [HttpPost]
        public ActionResult Edit(Exercice Exercice)
        {
            if (ModelState.IsValid)
            {
                db.Entry(Exercice).State = EntityState.Modified;
                db.SaveChanges();
                return RedirectToAction("Index");
            }
            return View(Exercice);
        }

        //
        // GET: /Exercice/Delete/5
        [Authorize(Roles = "Trainer")] 
        public ActionResult Delete(int id)
        {
            Exercice Exercice = db.Exercice.Find(id);
            return View(Exercice);
        }

        //
        // POST: /Exercice/Delete/5

        [HttpPost, ActionName("Delete")]
        public ActionResult DeleteConfirmed(int id)
        {            
            Exercice Exercice = db.Exercice.Find(id);
            db.Exercice.Remove(Exercice);
            db.SaveChanges();
            return RedirectToAction("Index");
        }

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