protected void EndSession_Click(object sender, EventArgs e) { using (FinalFantasyDrunkDataContext dc = new FinalFantasyDrunkDataContext()) { PizzaNight.Session session = (from t in dc.Sessions where t.ID == SessionID select t).FirstOrDefault(); session.DateEnded = DateTime.Now; dc.SubmitChanges(); } Response.Redirect("StartGame", false); Context.ApplicationInstance.CompleteRequest(); }
protected void gvContinue_RowDataBound(object sender, GridViewRowEventArgs e) { if (e.Row.RowIndex < 0) { return; } using (FinalFantasyDrunkDataContext dc = new FinalFantasyDrunkDataContext()) { string gameID = e.Row.Cells[0].Text; Game game = (from t in dc.Games where t.ID == int.Parse(gameID) select t).FirstOrDefault(); PizzaNight.Session session = game.Sessions.Where(x => !x.DateEnded.HasValue).FirstOrDefault(); if (session == null) { // Create new session and go ahead session = new PizzaNight.Session() { DateStarted = DateTime.Now, GameID = game.ID }; dc.Sessions.InsertOnSubmit(session); dc.SubmitChanges(); SessionPlayer newPlayerRobb = new SessionPlayer() { SessionID = session.ID, PlayerID = 1 }; SessionPlayer newPlayerBrian = new SessionPlayer() { SessionID = session.ID, PlayerID = 2 }; dc.SessionPlayers.InsertOnSubmit(newPlayerRobb); dc.SessionPlayers.InsertOnSubmit(newPlayerBrian); dc.SubmitChanges(); } HyperLink hl = new HyperLink() { NavigateUrl = "Session?id=" + session.ID, Text = "Go", CssClass = "btn btn-default btn-cs" }; e.Row.Cells[0].Controls.Add(hl); } }
private void LoadGameInfo() { using (FinalFantasyDrunkDataContext dc = new FinalFantasyDrunkDataContext()) { PizzaNight.Session currentSession = (from t in dc.Sessions where t.ID == SessionID select t).FirstOrDefault(); lblGameType.Text = currentSession.Game.GameType.Name; lblCharacterName.Text = currentSession.Game.CharacterName; DataTable dt = new DataTable(); dt.Columns.Add("Total Sessions"); dt.Columns.Add("Total Time"); dt.Columns.Add("Total Drinks"); DataRow dr = dt.NewRow(); dr[0] = currentSession.Game.Sessions.Count; dr[1] = GetTotalTime(currentSession.Game); dr[2] = GetDrinkCount(currentSession.Game); dt.Rows.Add(dr); gvGameInfo.DataSource = dt; gvGameInfo.DataBind(); var drinkRules = (from t in dc.Drinks where t.GameTypeID == currentSession.Game.GameTypeID orderby t.DrinkRule select t); List <SessionDrinkRule> sessionDrinkRules = new List <SessionDrinkRule>(); foreach (var rule in drinkRules) { SessionDrinkRule sessionRule = new SessionDrinkRule() { DrinkRule = rule.DrinkRule, DrinkPenalty = rule.Penalty, DrinkRuleID = rule.ID }; sessionRule.SessionCount = currentSession.SessionDrinks.Where(x => x.DrinkID == rule.ID).Count(); List <int> sessions = currentSession.Game.Sessions.Select(x => x.ID).ToList <int>(); sessionRule.TotalCount = (from t in dc.SessionDrinks where t.DrinkID == rule.ID && sessions.Contains(t.SessionID) select t).Count(); sessionDrinkRules.Add(sessionRule); } gvDrinks.DataSource = sessionDrinkRules.OrderByDescending(x => x.TotalCount).ThenByDescending(x => x.SessionCount).ThenBy(x => x.DrinkRule); gvDrinks.DataBind(); } }
protected void AddGame_Click(object sender, EventArgs e) { using (FinalFantasyDrunkDataContext dc = new FinalFantasyDrunkDataContext()) { Game game = new Game() { DateStarted = DateTime.Now, CharacterName = tbCharacterName.Text, LastPlayed = DateTime.Now, GameTypeID = int.Parse(ddGameType.SelectedValue) }; dc.Games.InsertOnSubmit(game); dc.SubmitChanges(); PizzaNight.Session session = new PizzaNight.Session() { GameID = game.ID, DateStarted = DateTime.Now }; dc.Sessions.InsertOnSubmit(session); dc.SubmitChanges(); SessionPlayer newPlayerRobb = new SessionPlayer() { SessionID = session.ID, PlayerID = 1 }; SessionPlayer newPlayerBrian = new SessionPlayer() { SessionID = session.ID, PlayerID = 2 }; dc.SessionPlayers.InsertOnSubmit(newPlayerRobb); dc.SessionPlayers.InsertOnSubmit(newPlayerBrian); dc.SubmitChanges(); Response.Redirect("Session?id=" + session.ID, false); } Context.ApplicationInstance.CompleteRequest(); }