protected void Session_End(object sender, EventArgs e) { TicTacRepository repository = new TicTacRepository(); string playerName = (string)Session["Player"]; PlayerModel player = repository.Select<PlayerModel>().FirstOrDefault(x => x.Name == playerName); if (player != null) repository.Delete<PlayerModel>(player); }
protected void Application_Start() { AreaRegistration.RegisterAllAreas(); RouteConfig.RegisterRoutes(RouteTable.Routes); BundleConfig.RegisterBundles(BundleTable.Bundles); GlobalConfiguration.Configure(WebApiConfig.Register); // recreate database every time model is changed Database.SetInitializer(new DropCreateDatabaseIfModelChanges<TicTacContext>()); // insert bot database data TicTacRepository repository = new TicTacRepository(); if (!repository.Select<PlayerModel>().Where(x => x.Name == "bot").Any()) { PlayerModel bot = new PlayerModel { Name = "bot" }; repository.Insert<PlayerModel>(bot); } }