using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace WebApplication1.Models {
	public class Article { // public => internal si on veut utiliser un repository masquant à la vue les types métier dans un view model
		public Guid Id { get; set; }
		public Decimal PrixAchat { get; set; }
		public Decimal PrixVente { get; set; }
		public int Quantite { get; set; }
		public string Nom { get; set; }
		public Article() {
			Id = Guid.NewGuid();
		}
		[System.Diagnostics.CodeAnalysis.SuppressMessage( "Microsoft.Security", "CA2104:DoNotDeclareReadOnlyMutableReferenceTypes" )]
		public static readonly Dictionary<Guid, Article> Stock;
		public static Dictionary<Guid, Article> CaddieUtilisateur {
			get {
				var caddie = (Dictionary<Guid, Article>)HttpContext.Current.Session["CaddieUtilisateur"];
				if( caddie == null )
					HttpContext.Current.Session["CaddieUtilisateur"] = caddie = new Dictionary<Guid, Article>();
				return caddie;
			}
		}
		static Article() {
			Stock = new Dictionary<Guid, Article>();
			Article a;
			a = new Article() { Nom = "Kharkhorin", PrixAchat = 2.5m, PrixVente = 5m, Quantite = 12345 };
			Stock.Add( a.Id, a );
			a = new Article() { Nom = "Chinggis", PrixAchat = 2.5m, PrixVente = 5m, Quantite = 12399 };
			Stock.Add( a.Id, a );
			a = new Article() { Nom = "Altaï", PrixAchat = 4m, PrixVente = 8m, Quantite = 985 };
			Stock.Add( a.Id, a );
			a = new Article() { Nom = "Altan Gov", PrixAchat = 5.25m, PrixVente = 10.5m, Quantite = 5896 };
			Stock.Add( a.Id, a );
			a = new Article() { Nom = "Yah-Uu", PrixAchat = 2.95m, PrixVente = 5.9m, Quantite = 8752 };
			Stock.Add( a.Id, a );
		}
	}
}