Пример #1
0
        private void btnAddToTeam_Click(object sender, EventArgs e)
        {
            if (dgvTeams.SelectedRows.Count < 1 || lstPlayers.Items.Count < 1)
            {
                return;
            }
            Player player = (Player)lstPlayers.SelectedItem;

            player.TeamId = (int)dgvTeams.SelectedRows[0].Cells[0].Value;
            db.SaveChanges();
            int indexPlayer = lstPlayers.SelectedIndex;

            ListFreeAgents();
            if (lstPlayers.SelectedIndex < 0)
            {
                return;
            }
            else if (indexPlayer > lstPlayers.Items.Count - 1)
            {
                lstPlayers.SelectedIndex = indexPlayer - 1;
            }
            else
            {
                lstPlayers.SelectedIndex = indexPlayer;
            }
        }
Пример #2
0
        public IActionResult Post([FromBody] Champion champion)
        {
            //Add book
            context.Champions.Add(champion);
            context.SaveChanges();

            return(Created("", champion));
        }
Пример #3
0
        private void btnPickColor_Click(object sender, EventArgs e)
        {
            if (txtColorName.Text.Trim() == "")
            {
                MessageBox.Show("You must enter color name!");
                return;
            }

            ColorDialog  cd     = new ColorDialog();
            DialogResult result = cd.ShowDialog();
            int          index;

            if (result == DialogResult.OK)
            {
                System.Drawing.Color pickedColor = cd.Color;

                if (gboColor.Text == "New Color")
                {
                    if (db.Colors.Any(x => x.ColorName == txtColorName.Text.Trim()))
                    {
                        MessageBox.Show("This name is already exists!");
                        ResetVisibles();
                        return;
                    }
                    Models.Color color = new Models.Color {
                        ColorName = txtColorName.Text.Trim(), Red = pickedColor.R, Green = pickedColor.G, Blue = pickedColor.B
                    };
                    db.Colors.Add(color);
                    index = lstColors.Items.Count;
                }
                else
                {
                    if (lstColors.SelectedItems.Count < 1)
                    {
                        return;
                    }


                    var col = (Models.Color)lstColors.SelectedItem;
                    col.ColorName = txtColorName.Text.Trim();
                    col.Red       = pickedColor.R;
                    col.Green     = pickedColor.G;
                    col.Blue      = pickedColor.B;
                    index         = lstColors.SelectedIndex;
                }
                db.SaveChanges();
                ListColors();
                lstColors.SetSelected(index, true);
            }


            gboColor.Text = "New Color";
            ResetVisibles();
        }
        private void btnNewColor_Click(object sender, EventArgs e)
        {
            if (cboColors.SelectedIndex < 0)
            {
                return;
            }
            var col = (Models.Color)cboColors.SelectedItem;

            selectedTeam.Colors.Add(col);
            db.SaveChanges();
            ListteamColors();
            lstTeamColors.SelectedIndex = lstTeamColors.Items.Count - 1;
        }
Пример #5
0
        private void btnDelete_Click(object sender, EventArgs e)
        {
            if (dgvMatches.Rows.Count < 1)
            {
                return;
            }
            DialogResult dr = MessageBox.Show("Are you sure?", "Warning", MessageBoxButtons.YesNo, MessageBoxIcon.Question);

            if (dr.ToString() == "No")
            {
                return;
            }
            var game  = (dynamic)dgvMatches.CurrentRow.DataBoundItem;
            int index = dgvMatches.CurrentRow.Index;

            db.Matches.Remove(db.Matches.Find(game.Id));
            db.SaveChanges();
            ListGames();
            if (dgvMatches.SelectedRows.Count < 1)
            {
                return;
            }
            else if (index > dgvMatches.Rows.Count - 1)
            {
                dgvMatches.Rows[index - 1].Selected = true;
            }
            else
            {
                dgvMatches.Rows[index].Selected = true;
            }
        }
Пример #6
0
        private void btnFinish_Click(object sender, EventArgs e)
        {
            if (txtEditPlayerName.Text == "")
            {
                MessageBox.Show("Player Name can't be empty", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            Player player = db.Players.Find(dgvPlayers.SelectedRows[0].Cells[0].Value);

            player.PlayerName = txtEditPlayerName.Text.Trim();
            player.TeamId     = chkEditPlayer.Checked ? (int?)null : (int)cboEditTeams.SelectedValue;
            db.SaveChanges();
            txtEditPlayerName.Clear();
            CancelChange();
            int index = dgvPlayers.SelectedRows[0].Index;

            ListPlayers();
            dgvPlayers.Rows[index].Selected = true;
        }
Пример #7
0
 public ActionResult Signup(RegisterModel model)
 {
     if (ModelState.IsValid)
     {
         using (var context = new ChampionsContext())
         {
             context.Participants.Add(model);
             context.SaveChanges();
             return(RedirectToAction("Welcome", model));
         }
     }
     return(View());
 }
Пример #8
0
 public ActionResult CreateTeam(Team model)
 {
     if (ModelState.IsValid)
     {
         Team team = null;
         using (ChampionsContext context = new ChampionsContext())
         {
             team = context.Teams.FirstOrDefault(club => club.Name == model.Name);
         }
         if (team == null)
         {
             using (ChampionsContext context = new ChampionsContext())
             {
                 context.Teams.Add(model);
                 context.SaveChanges();
                 return(RedirectToAction("Home", model));
             }
         }
     }
     return(View(model));
 }
Пример #9
0
        private void btnSave_Click(object sender, EventArgs e)
        {
            if (chkGameStatus.Checked && (txtTeam1Score.Text == "" || txtTeam2Score.Text == ""))
            {
                MessageBox.Show("If the game was finished, you must enter scores!", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }
            if (cboTeam1.SelectedIndex < 0 || cboTeam2.SelectedIndex < 0)
            {
                MessageBox.Show("You must choose teams!", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }
            int homeScore = 0;
            int awayScore = 0;

            try
            {
                if (chkGameStatus.Checked)
                {
                    homeScore = Convert.ToInt32(txtTeam1Score.Text);
                    awayScore = Convert.ToInt32(txtTeam2Score.Text);
                }
            }
            catch (Exception)
            {
                MessageBox.Show("You must enter scores as Numeric!", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }

            DateTime dateTime = dtpDate.Value.Date + dtpTime.Value.TimeOfDay;
            Result   result;

            if (chkGameStatus.Checked)
            {
                if (homeScore > awayScore)
                {
                    result = Result.Team1Won;
                }
                else if (homeScore < awayScore)
                {
                    result = Result.Team2Won;
                }
                else
                {
                    result = Result.Draw;
                }
                if (btnSave.Text == "Save")
                {
                    Match match = db.Matches.Find(gameId);
                    match.Team1Id   = (int)cboTeam1.SelectedValue;
                    match.Team2Id   = (int)cboTeam2.SelectedValue;
                    match.MatchTime = dateTime;
                    match.Score1    = homeScore;
                    match.Score2    = awayScore;
                    match.Result    = result;
                }
                else
                {
                    Match match = new Match {
                        Team1Id = (int)cboTeam1.SelectedValue, Team2Id = (int)cboTeam2.SelectedValue, Score1 = homeScore, Score2 = awayScore, MatchTime = dateTime, Result = result
                    };
                    db.Matches.Add(match);
                }
                db.SaveChanges();
                GamesChanged(this, EventArgs.Empty);
                Close();
            }
            else
            {
                if (btnSave.Text == "Save")
                {
                    Match match = db.Matches.Find(gameId);
                    match.Team1Id   = (int)cboTeam1.SelectedValue;
                    match.Team2Id   = (int)cboTeam2.SelectedValue;
                    match.MatchTime = dateTime;
                    match.Result    = null;
                }
                else
                {
                    Match match = new Match {
                        Team1Id = (int)cboTeam1.SelectedValue, Team2Id = (int)cboTeam2.SelectedValue, MatchTime = dateTime
                    };
                    db.Matches.Add(match);
                }

                db.SaveChanges();
                GamesChanged(this, EventArgs.Empty);
                Close();
            }
        }
 public int Add(ChampionEntity entity)
 {
     context.Add(entity);
     context.SaveChanges();
     return(entity.Id);
 }
Пример #11
0
        public static void Initialize(ChampionsContext context)
        {
            context.Database.EnsureCreated();

            if (0 == context.Champions.Count())
            {
                context.Champions.Add(new Champion()
                {
                    Name = "Aatrox", Title = "The Darkin Blade", Attack = 8, Defense = 4, Magic = 3, Difficuly = 4, Role = Role.Fighter
                });
                context.Champions.Add(new Champion()
                {
                    Name = "Ahri", Title = "The Nine-Tailed Fox", Attack = 3, Defense = 4, Magic = 8, Difficuly = 5, Role = Role.Mage
                });
                context.Champions.Add(new Champion()
                {
                    Name = "Akali", Title = "The Fist of Shadow", Attack = 5, Defense = 3, Magic = 8, Difficuly = 7, Role = Role.Assassin
                });
                context.Champions.Add(new Champion()
                {
                    Name = "Alistar", Title = "The Minotaur", Attack = 6, Defense = 9, Magic = 5, Difficuly = 7, Role = Role.Tank
                });
                context.Champions.Add(new Champion()
                {
                    Name = "Amumu", Title = "The Sad Mummy", Attack = 2, Defense = 6, Magic = 8, Difficuly = 3, Role = Role.Jungler
                });
                context.Champions.Add(new Champion()
                {
                    Name = "Anivia", Title = "The Cryophoenix", Attack = 1, Defense = 4, Magic = 10, Difficuly = 10, Role = Role.Mage
                });
                context.Champions.Add(new Champion()
                {
                    Name = "Annie", Title = "The Dark Child", Attack = 2, Defense = 3, Magic = 10, Difficuly = 6, Role = Role.Mage
                });
                context.Champions.Add(new Champion()
                {
                    Name = "Ashe", Title = "The Frost Archer", Attack = 7, Defense = 3, Magic = 2, Difficuly = 4, Role = Role.Marksman
                });
                context.Champions.Add(new Champion()
                {
                    Name = "AurelionSol", Title = "The Star Forger", Attack = 2, Defense = 3, Magic = 8, Difficuly = 7, Role = Role.Mage
                });
                context.Champions.Add(new Champion()
                {
                    Name = "Azir", Title = "The Emperor of the sands", Attack = 6, Defense = 3, Magic = 8, Difficuly = 9, Role = Role.Mage
                });
                context.Champions.Add(new Champion()
                {
                    Name = "Bard", Title = "The Wandering Caretaker", Attack = 4, Defense = 4, Magic = 5, Difficuly = 9, Role = Role.Support
                });
                context.Champions.Add(new Champion()
                {
                    Name = "Blitzcrank", Title = "The Great Steam Golem", Attack = 4, Defense = 8, Magic = 5, Difficuly = 4, Role = Role.Support
                });
                context.Champions.Add(new Champion()
                {
                    Name = "Brand", Title = "The Burning Vengeance", Attack = 2, Defense = 2, Magic = 9, Difficuly = 4, Role = Role.Mage
                });
                context.Champions.Add(new Champion()
                {
                    Name = "Braum", Title = "The Heart of the Freljord", Attack = 3, Defense = 9, Magic = 4, Difficuly = 3, Role = Role.Support
                });
                context.Champions.Add(new Champion()
                {
                    Name = "Caitlyn", Title = "The Sheriff of Piltover", Attack = 8, Defense = 2, Magic = 2, Difficuly = 6, Role = Role.Marksman
                });
                context.SaveChanges();
            }
        }