protected void Login1_Authenticate(object sender, AuthenticateEventArgs e) { string name = Login1.UserName.Trim(); string pass = Login1.Password.Trim(); dbcon.User_Admin_Tables.Load(); foreach (User_Admin_Table x in dbcon.User_Admin_Tables) { if (Login1.UserName.Equals(x.username) && Login1.Password.Equals(x.password)) { User_Admin_Table myPerson = (from y in dbcon.User_Admin_Tables.Local where y.username.Trim().Equals(name) && y.password.Trim().Equals(pass) select y).FirstOrDefault(); //int role = myPerson.Admin_Account; Session.Add("iD", myPerson.Id); Session.Add("name", myPerson.FirstName); Session.Add("balance", myPerson.Balance); FormsAuthentication.RedirectFromLoginPage(Login1.UserName, true); if (myPerson.Admin_Account == 1) { Response.Redirect("~/Admin.aspx"); } else { Response.Redirect("~/Default.aspx"); } } } }
protected void Page_Load(object sender, EventArgs e) { dbcon.User_Admin_Tables.Load(); User_Admin_Table myPerson = (from x in dbcon.User_Admin_Tables.Local where x.username.Trim().Equals(User.Identity.Name) select x).FirstOrDefault(); //Label1.Text = Session["name"].ToString(); }
protected void Page_Load(object sender, EventArgs e) { int userId = Convert.ToInt32(HttpContext.Current.Session["iD"]); User_Admin_Table bettingPerson = (from x in dbcon.User_Admin_Tables where x.Id == userId select x).First(); Label4.Text = bettingPerson.Balance.ToString(); }
protected void Button1_Click(object sender, EventArgs e) { int matchId = Convert.ToInt32(TextBox1.Text); string team = DropDownList1.SelectedItem.Text; decimal amount = Convert.ToDecimal(TextBox2.Text); int userId = Convert.ToInt32(HttpContext.Current.Session["iD"]); Bet newBet = new Bet { MatchId = matchId, HomeAway = team, BetAmount = amount, UserId = userId }; User_Admin_Table bettingPerson = (from x in dbcon.User_Admin_Tables where x.Id == userId select x).First(); //verifies that the person has enough money if (bettingPerson.Balance >= amount) { bettingPerson.Balance -= amount; dbcon.Bets.Add(newBet); dbcon.SaveChanges(); GridView1.DataBind(); Label2.Text = ""; Label4.Text = bettingPerson.Balance.ToString(); } else { Label2.Text = "You do not have enough funds."; } }
protected void Button1_Click(object sender, EventArgs e) { //first checks if there is anything selected in the grid if (GridView1.SelectedDataKey.Value != null) { int id = Convert.ToInt32(GridView1.SelectedDataKey.Value.ToString()); //grabs the game using the id Sports_Table game = (from x in dbcon.Sports_Tables where x.Match_ID == id select x).First(); //if the admin clicks the button when the dropdown is on home if (DropDownList1.SelectedValue.Equals("Home")) { //sets the values of the winner game.Home_Winner = 1; game.Away_Winner = 0; //goes through each bet foreach (Bet x in dbcon.Bets) { //if the bet has the same match id as the match that is selected if (x.MatchId == game.Match_ID) { //grabs the person that made the bet User_Admin_Table person = (from y in dbcon.User_Admin_Tables where y.Id == x.UserId select y).First(); //if the bet is correct, assigns the correct amount to winnings and adds to the persons balance if (x.HomeAway.Equals("Home")) { x.Winnings = x.BetAmount * game.H__win; person.Balance = person.Balance + Convert.ToDecimal(x.Winnings); } //if not right, simply sets winnings to 0 else { x.Winnings = 0; } } } } //when the admin clicks the button when the dropdown is on away //same as above except for if away wins else { game.Home_Winner = 0; game.Away_Winner = 1; foreach (Bet x in dbcon.Bets) { if (x.MatchId == game.Match_ID) { User_Admin_Table person = (from y in dbcon.User_Admin_Tables where y.Id == x.UserId select y).First(); if (x.HomeAway.Equals("Away")) { x.Winnings = x.BetAmount * game.A__win; person.Balance = person.Balance + Convert.ToDecimal(x.Winnings); } else { x.Winnings = 0; } } } } //saves changes and updates the grids dbcon.SaveChanges(); GridView1.DataBind(); GridView2.DataBind(); GridView3.DataBind(); } else { } }