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 ExempleDropDownListController : Controller {
    public ActionResult Index() {
      lock ( Article.Stock ) {
        ViewBag.OptionsDuSelect = Article.Stock.Values.Select( a => new SelectListItem() { Text = $"{a.Nom} - {a.PrixVente} € ({a.Quantite})", Value = a.Id.ToString() } ).ToList();
        ViewBag.Articles = Article.Stock.Values.Select( a => new ArticleCommerce( a ) ).ToList();
      }
      return View();
    }
    [HttpPost]
    public string Index( Guid? idArticleParCtrlr, Guid? idArticleParVue ) {
      Article articleParCtrlr;
      Article.Stock.TryGetValue( idArticleParCtrlr.GetValueOrDefault(), out articleParCtrlr );
      Article articleParVue;
      Article.Stock.TryGetValue( idArticleParVue.GetValueOrDefault(), out articleParVue );
      return $"1er article : {articleParCtrlr?.Nom}<br />2nd article : {articleParVue?.Nom}";
    }
  }
}