Пример #1
0
    public Footballer getFootballer(int id)
    {
        Footballer footballer = null;
        var        t          = footballers.TryGetValue(id, out footballer) ? footballer : null;

        return(footballer);
    }
Пример #2
0
        public ActionResult DeleteConfirmed(int id)
        {
            Footballer footballer = footballerManager.Find(x => x.Id == id);

            footballerManager.Delete(footballer);
            return(RedirectToAction("Index"));
        }
Пример #3
0
        public ActionResult <Footballer> UpdateBook([FromBody] Footballer footballer)
        {
            context.Footballers.Update(footballer);
            context.SaveChanges();

            return(Created("", footballer));
        }
Пример #4
0
 public static Footballer GetFootballer(int footballerId)
 {
     Footballer footballer = new Footballer();
     SqlConnection dbConnection = null;
     try {
         dbConnection = new SqlConnection(DB_CONNECTION_STRING);
         dbConnection.Open();
         string commandText = "select * from Footballers where id = @footballerId";
         SqlCommand cmd = new SqlCommand(commandText, dbConnection);
         cmd.Parameters.Add(new SqlParameter("@footballerId", footballerId));
         SqlDataReader reader = cmd.ExecuteReader();
         if (reader.HasRows) {
             reader.Read();
             footballer.Id = reader.GetInt32(0);
             footballer.name = reader.GetString(1);
             footballer.age = reader.GetString(2);
             footballer.nationality = reader.GetString(3);
             footballer.datеOfBirth = reader.GetDateTime(4);
             footballer.height = reader.GetInt16(5);
             footballer.weight = reader.GetInt16(6);
             footballer.number = reader.GetInt16(7);
             footballer.position = reader.GetString(8);
             footballer.Team = new Team();
             footballer.Team.Id = reader.GetInt32(9);
         }
     } finally {
         if (dbConnection != null) {
             dbConnection.Close();
         }
     }
     return footballer;
 }
Пример #5
0
        /// <summary>
        /// Funkcja obsługująca przycisk odpowiedzialny za dodanie piłkarza do bazy
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void buttonAddNewFootballer_Click(object sender, EventArgs e)
        {
            var firstNameFootballer = textBoxFootballerFirstName.Text;
            var lastNameFootballer  = textBoxFootballerLastName.Text;
            var birthdateFootballer = dateTimePickerFootballer.Text;
            var clubIdFootballer    = textBoxFootballerClubId.Text;
            var countryIdFootballer = textBoxFootballerCountryId.Text;

            if ((firstNameFootballer != "") && (lastNameFootballer != "") && (birthdateFootballer != "") &&
                (clubIdFootballer != "") && (countryIdFootballer != ""))
            {
                Footballer footballer = new Footballer
                {
                    FirstName = firstNameFootballer,
                    LastName  = lastNameFootballer,
                    Birthdate = Convert.ToDateTime(birthdateFootballer),
                    ClubId    = Int32.Parse(clubIdFootballer),
                    CountryId = Int32.Parse(countryIdFootballer)
                };
                _footballers.Create(footballer);
                _footballers.Save();
                LoadFootballers();
                textBoxFootballerFirstName.Text = textBoxFootballerLastName.Text = dateTimePickerFootballer.Text
                                                                                       = textBoxFootballerClubId.Text = textBoxFootballerCountryId.Text = "";
            }
            else
            {
                MessageBox.Show("Niepoprawne dane!");
            }
        }
Пример #6
0
        public async Task <IActionResult> Edit(Footballer footballer)
        {
            db.Players.Update(footballer);
            await db.SaveChangesAsync();

            return(RedirectToAction("Players"));
        }
Пример #7
0
        public List <Footballer> ReadAll()
        {
            List <Footballer> footballers = new List <Footballer>();

            using (SqlConnection connection = new SqlConnection(_connectionString))
            {
                connection.Open();
                using (SqlCommand command = new SqlCommand())
                {
                    command.Connection  = connection;
                    command.CommandType = System.Data.CommandType.Text;
                    command.CommandText = FOOTBALLER_READ_ALL;
                    using (SqlDataReader dataReader = command.ExecuteReader())
                    {
                        while (dataReader.Read())
                        {
                            Footballer footballer = new Footballer();
                            footballer = ConvertToModel(dataReader);
                            footballers.Add(footballer);
                        }
                    }
                }
            }

            return(footballers);
        }
Пример #8
0
        /// <summary>
        /// Проходит процесс боя. Мы сравниваем характеристики футболистов, а потом исходя из них
        /// решаем, как пойдет дальше игра. Либо будет пенальти из 4 голов, либо передается ход,
        /// либо победа обеспечена при достижении 4 победы подряд. Также мы обновляем постоянно лог.
        /// Мы передаем игроков, чтобы вытаскивать имена для корректного отображения в логе.
        /// </summary>
        /// <param name="footballer1">Атакующий футболист.</param>
        /// <param name="footballer2">Обороняющий футболист.</param>
        /// <param name="player1">Атакующий игрок.</param>
        /// <param name="player2">Обороняющий игрок.</param>
        private void ProcessFight2(Footballer footballer1, Footballer footballer2, Player player1,
                                   Player player2)
        {
            if ((new Player()).Fight(footballer1, footballer2) && stepRound <= 4)
            {
                logGameBox.Text += $"Round: {round}. {player1.Name} win in step: {stepRound}.\n" +
                                   $"Attack stats: {footballer1.Stats}\nDefend stats: {footballer2.Stats}\n";
                stepRound++;
            }
            else if (!(new Player()).Fight(footballer1, footballer2))
            {
                stepRound        = 1;
                logGameBox.Text += $"Round: {round++}. {player2.Name} win!\n" +
                                   $"Attack stats: {footballer1.Stats}\nDefend stats: {footballer2.Stats}\n";
            }

            if (stepRound == 5)
            {
                stepRound        = 1;
                win              = true;
                logGameBox.Text += $"Round: {round++}. {player1.Name} win!\n";
            }

            // Автоматическая прокрутка лога до конца.
            logGameBox.SelectionStart = logGameBox.Text.Length;
            logGameBox.ScrollToCaret();

            // После успешного хода будет еще раз проверяться, кто ходит в этот раз.
            WhoseMove();
        }
Пример #9
0
        public Footballer ReadByUid(Footballer footballer)
        {
            Footballer newFootballer = new Footballer();

            using (SqlConnection connection = new SqlConnection(_connectionString))
            {
                connection.Open();
                using (SqlCommand command = new SqlCommand())
                {
                    command.Connection  = connection;
                    command.CommandType = System.Data.CommandType.StoredProcedure;
                    command.CommandText = FOOTBALLER_READ_BY_GUID;
                    command.Parameters.Add(new SqlParameter("@Footballer_ID", footballer.ID));
                    using (SqlDataReader dataReader = command.ExecuteReader())
                    {
                        if (dataReader.Read())
                        {
                            newFootballer = ConvertToModel(dataReader);
                        }
                    }
                }
            }

            return(newFootballer);
        }
        public async Task PostNewFootballer(string addedFootballerCurrentClub, Footballer newFootballer)
        {
            var policy = Policy.Handle <SqlException>().WaitAndRetryAsync(new[]
            {
                TimeSpan.FromSeconds(5),
                TimeSpan.FromSeconds(10),
                TimeSpan.FromSeconds(15),
            }, (ext, timeSpan, retryCount, context) =>
            {
                _logger.LogError(ext, $"Error - try retry (count: {retryCount}, timeSpan: {timeSpan})");
            });

            var existingClub = await policy.ExecuteAsync(() =>
                                                         _context.Clubs.FirstOrDefaultAsync(c => c.ClubName == addedFootballerCurrentClub));

            if (existingClub == null)
            {
                _logger.LogInformation($"Club with name {addedFootballerCurrentClub} doesn't exists.");
                // TODO return error object with proper error code.
                throw new Exception("Entity not founded.");
            }

            newFootballer.Club = existingClub;
            _context.Footballers.Add(newFootballer);
            await _context.SaveChangesAsync();
        }
        public async Task <bool> deleteFootballer(Footballer footballer)
        {
            footballerContext.Footballers.Remove(footballer);
            await saveAll();

            return(true);
        }
Пример #12
0
        public async Task <IActionResult> Edit(int id, [Bind("Id,FootballerName,FootballerClub")] Footballer footballer)
        {
            if (id != footballer.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(footballer);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!FootballerExists(footballer.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(footballer));
        }
Пример #13
0
 public void Delete(int id)
 {
     if (id > 0)
     {
         Footballer footballer = footballersRepository.GetById(id);
         footballersRepository.Delete(footballer);
     }
 }
Пример #14
0
        public void AddFootballer(string name, string surname, uint age, uint weight, uint height)
        {
            var id  = Footballers.Count() + 1;
            var fbl = new Footballer(id, name, surname, age, weight, height);

            Footballers.Add(fbl);
            WriteToFile();
        }
Пример #15
0
        public ActionResult DeleteConfirmed(int id)
        {
            Footballer footballer = db.Footballers.Find(id);

            db.Footballers.Remove(footballer);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
Пример #16
0
        public void TryAccessToFootballerOnIllegallPositionThrowException()
        {
            Footballers footballers = new Footballers();

            Assert.Throws <IndexOutOfRangeException>(() =>
            {
                Footballer temp = footballers[0];
            });
        }
Пример #17
0
        public void MakeFootballerChange(int takeOffNumber, int enterNumber)
        {
            Footballer takeOffFootballer = new Footballer(takeOffNumber);
            Footballer enterFootballer   = new Footballer(enterNumber);

            _warmupTrainer.WarmUpPlayer(enterFootballer);
            _tacticTrainer.ExplainTactic(enterFootballer);
            _secondManager.ReportChangeToTechnicalReferee(takeOffFootballer, enterFootballer);
        }
Пример #18
0
        public Footballer addFootballer(string name, string surname, uint age, uint weight)
        {
            var id         = footballers.Count() + 1;
            var footballer = new Footballer(id, name, surname, age, weight);

            footballers.Add(footballer);
            WriteToFile();
            return(footballer);
        }
Пример #19
0
    public SinglePlayerProcessorV3(ProcessedPlayerProviderV3 playerProvider, int gameweek, Footballer footballer, List <FootballerScoreDetailElement> explains, Live liveData)
    {
        _footballer      = footballer;
        _currentExplains = explains;
        _currentLiveData = liveData;
        _gameweek        = gameweek;

        _playerProvider = playerProvider;
    }
Пример #20
0
        public async Task <IActionResult> Create([Bind("Id,FootballerName,FootballerClub")] Footballer footballer)
        {
            if (ModelState.IsValid)
            {
                _context.Add(footballer);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(footballer));
        }
Пример #21
0
 private bool PlayersExists(Footballer footballer)
 {
     return(db.Players.Any(
                p =>
                p.Name == footballer.Name &&
                p.Surname == footballer.Surname &&
                p.Sex == footballer.Sex &&
                p.BirthDate == footballer.BirthDate &&
                p.TeamName == footballer.TeamName &&
                p.Country == footballer.Country));
 }
 public ProcessedPlayer(Footballer footballer, List <FootballerScoreDetailElement> explains, ProcessedPlayer oldData)
 {
     rawData.footballer = footballer;
     rawData.explain    = explains;
     if (oldData != null)
     {
         isCurrentlyPlaying = oldData.isCurrentlyPlaying;
         isDonePlaying      = oldData.isDonePlaying;
         oldData.events.ForEach(e => events.Add(e));
     }
 }
Пример #23
0
        public IActionResult AddFootballer(Footballer model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            FootballerRepository.Add(model);
            FootballerRepository.SaveChanges();
            context.Clients.All.SendAsync("refreshFootballers");
            return(RedirectToAction("index"));
        }
    private ExplainElement GetAverage(Footballer element)
    {
        var ppgStr = element.points_per_game;
        var ppg    = double.Parse(ppgStr);

        return(new ExplainElement()
        {
            identifier = "avg",
            points = (int)Math.Round(ppg),
            value = 1
        });
    }
Пример #25
0
        public ActionResult <Footballer> AddFootballer([FromBody] Footballer footballer)
        {
            var tempFootballer = context.Footballers.FirstOrDefault(o => o.Name == footballer.Name);

            if (tempFootballer != null)
            {
                return(NoContent());
            }
            context.Footballers.Add(footballer);
            context.SaveChanges();
            return(Created("", footballer));
        }
Пример #26
0
        public ActionResult ByFootballer(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }


            Footballer footballer = footballerManager.ListQueryable().Where(x => x.Id == id).First();

            return(View("FootballerProfileInformations", footballer));
        }
        public async Task <IActionResult> AddFootballer(AddFootballerViewModel model)
        {
            model.Teams = await database.SelectedTeams();

            if (ModelState.IsValid)
            {
                var footballer = new Footballer
                {
                    FirstName = model.FirstName,
                    LastName  = model.LastName,
                    Birthday  = model.Birthday,
                    Country   = model.Country,
                    Gender    = model.Gender
                };

                if (String.IsNullOrEmpty(model.TeamName))
                {
                    if (!String.IsNullOrEmpty(model.SelectTeam) &&
                        !model.Teams.Contains(new SelectListItem {
                        Text = model.SelectTeam, Value = model.SelectTeam
                    }))
                    {
                        footballer.TeamId = Int32.Parse(model.SelectTeam);
                    }
                    else
                    {
                        ModelState.AddModelError("", "Ошибка в выборе команды");
                        return(View(model));
                    }
                }
                else
                {
                    var team = new Team {
                        Name = model.TeamName
                    };
                    await database.AddAsync(team);

                    await database.SaveChangesAsync();

                    footballer.TeamId = team.Id;
                }

                await database.AddAsync(footballer);

                await database.SaveChangesAsync();

                return(RedirectToAction("AllFootballers"));
            }


            return(View(model));
        }
Пример #28
0
        private Footballer ConvertToModel(SqlDataReader dataReader)
        {
            Footballer footballer = new Footballer();

            footballer.ID          = dataReader.GetGuid(dataReader.GetOrdinal("Footballer_ID"));
            footballer.firstName   = dataReader.GetString(dataReader.GetOrdinal("First_Name"));
            footballer.lastName    = dataReader.GetString(dataReader.GetOrdinal("Last_Name"));
            footballer.birthDay    = dataReader.GetDateTime(dataReader.GetOrdinal("Birth_Day"));
            footballer.nationality = dataReader.GetString(dataReader.GetOrdinal("Nationality"));
            footballer.team        = dataReader.GetGuid(dataReader.GetOrdinal("Team"));

            return(footballer);
        }
Пример #29
0
    /**
     *   Set up for all the players in the team
     */
    public void SetUpPlayers(List <GameObject> NewPlayers)
    {
        foreach (GameObject Footballer in NewPlayers)
        {
            Player Guy = Footballer.GetComponent <Player>();

            Guy.SetTeam(this);

            Players.Add(Guy);
        }

        ControllingPlayer = Players[0];
    }
Пример #30
0
        public IActionResult Post([FromBody] Footballer footballer)
        {
            var post = _footballerService.Post(footballer);

            if (post)
            {
                return(Ok());
            }
            else
            {
                return(Conflict("Nie można podać takiej pozycji!"));
            }
        }
Пример #31
0
        public string FootballerGetUsername()
        {
            Footballer footballer = CurrentSession.footballer;

            if (footballer != null)
            {
                return(footballer.Username);
            }
            else
            {
                return("system");
            }
        }