Esempio n. 1
0
    protected void GridUsers_RowCommand(object sender, GridViewCommandEventArgs e)
    {
        if (e.CommandName == "Challenge")
        {
            User user = Session["User"] as User;

            GridUsers.SelectedIndex = int.Parse(e.CommandArgument.ToString());
            GridUsers.DataBind();

            int enemyId = (int)GridUsers.SelectedDataKey.Value;

            if (enemyId != user.Id)
            {
                using (var db = new JaipurEntities())
                {
                    var enemy = db.User.FirstOrDefault((u) => u.Id == enemyId);

                    var gameData = JaipurSocial.Core.GameData.CreateNewGame(user, enemy);
                    var saved    = db.Game.Add(gameData.ToGame());
                    db.SaveChanges();
                    Response.Redirect("Game.aspx?GameId=" + saved.Id);
                }
            }
            else
            {
                ShowMessage(Resources.Localization.CantChallengeYourself);
            }
        }
    }
Esempio n. 2
0
    protected void Page_Load(object sender, EventArgs e)
    {
        using (var db = new JaipurEntities())
        {
            User logged = (Session["User"] as User);

            if (logged != null)
            {
                Random      rng   = new Random(DateTime.Now.Millisecond);
                List <User> users = db.User.OrderByDescending((u) => u.Coins).ToList <User>();
                GridUsers.DataSource = users;
                GridUsers.DataBind();

                try
                {
                    var dbGames = from game in db.Game.Where(g => g.EnemyId == logged.Id || g.ChallengerId == logged.Id).ToList()
                                  select new GameData(game);

                    var games = from game in dbGames
                                let enemy = game.GetEnemyData(logged)
                                            where !game.IsDeleted(logged)
                                            select new RunningGameInfo
                    {
                        GameId     = game.Id,
                        EnemyLogin = enemy.User.Name,
                        EnemyEmail = enemy.User.Email,
                        GameStatus = game.GetStatus(logged)
                    };
                    GridGames.DataSource = games.ToList();
                    GridGames.DataBind();
                }
                catch { }
            }
        }
    }
        protected void btnConsultar_Click(object sender, EventArgs e)
        {
            msnMessage.HideMessage();

            data = Users.GetUsersByName(txtNombre.Text.Trim());
            if (data.Tables[0].Rows.Count > 0)
            {
                GridUsers.DataSource = data;

                Session[DSUsers] = data;
                GridUsers.DataBind();
            }
            else
            {
                msnMessage.LoadMessage("Nombe no encontrado", UserControl.ucMessage.MessageType.Information);
                GridUsers.DataSource = null;
                GridUsers.DataBind();
            }
        }
 protected void GridUsers_PageIndexChanging(object sender, GridViewPageEventArgs e)
 {
     GridUsers.PageIndex  = e.NewPageIndex;
     GridUsers.DataSource = (DataSet)Session[DSUsers];
     GridUsers.DataBind();
 }