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

using Microsoft.AspNet.Identity;

namespace WebApplication1.Controllers {
  public class ExempleSecuriteApplicativeController : Controller {
    public ActionResult Index() {
      ViewBag.Utilisateur = User.Identity.Name;
      ViewBag.UserIdApplicatif = User.Identity.GetUserId(); // SSI using Microsoft.AspNet.Identity
			ViewBag.IdentiteIIS = System.Security.Principal.WindowsIdentity.GetCurrent().Name;
      
      using( var dc = new NorthwindEntities() ) {
        return View( "Index", dc.Products.Where( p => p.CategoryID == 1 ).Select( p => new { p.ProductID, p.ProductName } ).ToList().Select( p => new ProductPourListeViewModel() { ProductID = p.ProductID, ProductName = p.ProductName } ).ToList() );
      }
    }
    [ActionName("Supprimer"), Authorize( Users = @"toto@toto.com" )]
    public ActionResult Supprimer( int? productID ) {
      if( productID == null ) // Survient sur une redirection après login
        return RedirectToAction( "Index" );
      ViewBag.Message = $"On dit que {productID} est supprimé...";
      return Index();
    }
  }
}
