using System.Data.Entity;
using System.Data.Entity.ModelConfiguration.Conventions;
using MileageTraker.Web.Models;

namespace MileageTraker.Web.Context
{
	public class MileageTrakerContext : DbContext
	{
		public DbSet<Log> Logs { get; set; }
		public DbSet<Vehicle> Vehicles { get; set; }
		public DbSet<City> Cities { get; set; }
		public DbSet<User> Users { get; set; }
		public DbSet<Role> Roles { get; set; }
		public DbSet<PurposeType> PurposeTypes { get; set; }

		/*
		 * 			WebSecurity.Register("Demo", "123456", "demo@demo.com", true, "Demo", "Demo");
			Roles.CreateRole("Admin");
			Roles.AddUserToRole("Demo", "Admin");
		 */

		protected override void OnModelCreating(DbModelBuilder modelBuilder)
		{
			modelBuilder.Conventions.Remove<PluralizingTableNameConvention>();
			modelBuilder.Entity<Log>()
			            .HasOptional(l => l.VehiclePreviousLog)
						.WithMany()
			            .HasForeignKey(l => l.VehiclePreviousLogId);
		}
	}
}