using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using WebApplication1.Models;

namespace WebApplication1.Controllers {
  public class ExempleAFaireEFCodeFirstController : Controller {
    AFaireContext DC = new AFaireContext();
    public ActionResult Index() {
      return View( "Index", DC.Taches );
    }
    public ActionResult Ajouter( string nomTache ) {
      if( nomTache == null )
        return RedirectToAction( "Index" );
      if( !string.IsNullOrWhiteSpace( nomTache ) ) {
				Tache nvTache = new Tache() { Nom = nomTache, Echeance = DateTime.Now, NbParticipants = 1 };
				DC.Taches.Add( nvTache );
        DC.SaveChanges();
      }
      return Index();
    }
    public ActionResult Supprimer( Guid? id ) {
      if( id == null )
        return RedirectToAction( "Index" );
      DC.Entry( new Tache() { Id = id.Value } ).State = System.Data.Entity.EntityState.Deleted;
      DC.SaveChanges();
      return Index();
    }
    protected override void Dispose( bool disposing ) {
      if( disposing )
        DC.Dispose();
      base.Dispose( disposing );
    }
  }
}