using System;
using System.Data.Entity;
using System.Linq;
using System.Net;
using System.Web.Mvc;
using WebApplication1.Models;

namespace WebApplication1.Controllers {
  public class AnnoncesController : Controller {
    private PetitesAnnoncesContext db = new PetitesAnnoncesContext();
    public ActionResult Index() {
      var annonces = db.Annonces.Include( a => a.Redacteur );
      return View( annonces.ToList() );
    }
    public ActionResult Delete( Guid? id ) {
      if( id == null )
        return new HttpStatusCodeResult( HttpStatusCode.BadRequest );
      Annonce annonce = db.Annonces.Find( id );
      if( annonce == null )
        return HttpNotFound();
      return View( annonce );
    }
    [HttpPost, ActionName( "Delete" ), ValidateAntiForgeryToken]
    public ActionResult DeleteConfirmed( Guid id ) {
      Annonce annonce = db.Annonces.Find( id );
      db.Annonces.Remove( annonce );
      db.SaveChanges();
      return RedirectToAction( "Index" );
    }
    protected override void Dispose( bool disposing ) {
      if( disposing )
        db.Dispose();
      base.Dispose( disposing );
    }
  }
}
