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

namespace WebApplication1.Controllers {
  public class CommerceRepositoryController : Controller {
    private ArticleCommerceRepositoryBase _Repository;
    private ArticleCommerceRepositoryBase Repository {
      get {
        if( _Repository == null )
          _Repository = ArticleCommerceRepositoryFactory.Instancier();
        return _Repository;
      }
    }
    public ActionResult Index() {
      ViewBag.Caddie = Repository.ListerCaddie();
      ViewBag.Stock = Repository.ListerStock();
      return View( "Index" );
    }
    public ActionResult Ajouter( Guid? id ) {
      if( Request.HttpMethod != "POST" )
        return RedirectToAction( "Index" );
      ArticleCommerce a = Repository.AjouterAuCaddie( id.Value );
      ViewBag.ArticleAjoute = a;
      return Index();
    }
    public ActionResult Vider() {
      if( Request.HttpMethod != "POST" )
        return RedirectToAction( "Index" );
      Repository.ViderCaddie();
      return Index(); // Simple exécution de méthode
    }
    protected override void Dispose( bool disposing ) {
      if( disposing && _Repository != null )
        _Repository.Dispose();
      base.Dispose( disposing );
    }
  }
}
