using Microsoft.AspNet.Identity.EntityFramework;
using System;
using System.Data.Entity;
using System.Web;

namespace Sevomin.Models
{
    public class SevominDbContext : IdentityDbContext<User>
    {        
        #region Singleton
        private static object locker = new object();

        public SevominDbContext() : base("SevominConnectionString") { }
        
        public static SevominDbContext Current
        {
            get
            {
                lock (locker)
                {
                    if (HttpContext.Current.Items["DataContexMember"] != null &&
                        HttpContext.Current.Items["DataContexMember"] is SevominDbContext)
                        return (SevominDbContext)HttpContext.Current.Items["DataContexMember"];
                    RenewMember();
                    return (SevominDbContext)HttpContext.Current.Items["DataContexMember"];
                }
            }

        }

        public static void RenewMember()
        {
            SevominDbContext pe =
                new SevominDbContext();
            HttpContext.Current.Items["DataContexMember"] = pe;
            GC.Collect();
        }

        #endregion        

        public DbSet<Parameter> Parameters { get; set; }
        public DbSet<ParameterValue> ParameterValues { get; set; }
        public DbSet<Job> Jobs { get; set; }
        public DbSet<DovominJob> DovominJobs { get; set; }
    }
}
