Пример #1
0
        private void Mannschaft1_Load(object sender, EventArgs e)
        {
            if (DesignMode)
            {
                return;
            }

            //Your code to run on load goes here
            var teamsModel = new TeamsModel();

            teamsModel.Teams.Load();
            _me = teamsModel.Teams.Where(item => item.Me == 1).FirstOrDefault();

            var _playerModel = new PlayerModel();

            _playerModel.Players.Load();
            _bindingList = new BindingList <Player>(_playerModel.Players.Where(item => item.TeamId == _me.Id).ToList());


            this.bindingSource1.DataSource            = _bindingList;
            dataGridView1.Columns[0].DataPropertyName = "Nachname";
            dataGridView1.Columns[1].DataPropertyName = "Vorname";
            dataGridView1.Columns[2].DataPropertyName = "Att";
            dataGridView1.Columns[3].DataPropertyName = "Deff";
            dataGridView1.AutoGenerateColumns         = false;
        }
Пример #2
0
 public bool Update(TeamsModel team)
 {
     if (team is null)
     {
         return(false);
     }
     try
     {
         using (SqlConnection connection = new SqlConnection(ConnectionString))
         {
             string queryString = $"UPDATE {TeamsTable} " +
                                  $"SET Name = '{team.Name}' " +
                                  $" WHERE {TeamsTable}.Id = {team.Id}";;
             connection.Open();
             SqlCommand command = new SqlCommand(queryString, connection);
             command.Prepare();
             int number = command.ExecuteNonQuery();
             return(number > 0 ? true : false);
         }
     }
     catch (Exception)
     {
         return(false);
     }
 }
Пример #3
0
        private TeamsModel LoadAll(int derbyId)
        {
            var model = new TeamsModel();

            using (SqlConnection con = new SqlConnection(_connectionString))
            {
                con.Open();
                try
                {
                    // Load teams
                    using (SqlCommand command = new SqlCommand(@"select t.id, t.name, t.secret_string, d.name derby_name
from sturgeonteams t
    join sturgeonderbies d on d.id = t.derby_id
where t.derby_id = @derby_id", con))
                    {
                        command.Parameters.Add(new SqlParameter("derby_id", derbyId));
                        var reader = command.ExecuteReader();
                        if (reader.HasRows)
                        {
                            while (reader.Read())
                            {
                                model.Teams.Add(new TeamModel()
                                {
                                    TeamName = reader["name"].ToString(),
                                    Password = reader["secret_string"].ToString(),
                                    TeamId   = reader.GetInt32(0)
                                });
                                model.DerbyName = reader["derby_name"].ToString();
                            }
                        }
                        reader.Close();
                    }

                    // Load scores
                    using (SqlCommand command = new SqlCommand(@"select s.team_id, s.slot, s.score 
from sturgeonscores s
	join sturgeonteams t on s.team_id = t.id
where t.derby_id = @derby_id", con))
                    {
                        command.Parameters.Add(new SqlParameter("derby_id", derbyId));
                        var reader = command.ExecuteReader();
                        if (reader.HasRows)
                        {
                            while (reader.Read())
                            {
                                var team = model.Teams.First(x => x.TeamId == reader.GetInt32(0));
                                team.SetScore(reader.GetInt32(1), reader.GetInt32(2));
                            }
                        }
                        reader.Close();
                    }
                }
                catch (Exception ex)
                {
                    throw ex;
                }
            }

            return(model);
        }
Пример #4
0
        public ActionResult SaveEdititngTeam(TeamsVm model)
        {
            if (model is null || string.IsNullOrWhiteSpace(model.Name))
            {
                TempData["error"] = $"You did not fill name. Name is required.";
                return(RedirectToAction("Edit", new { team_id = model.Id }));
            }
            TeamsModel team = new TeamsModel()
            {
                Id   = model.Id,
                Name = model.Name
            };

            try
            {
                if (!_teamService.Update(team))
                {
                    TempData["error"] = $"Problems with updating team (Service error \"Update/Edit\").";
                    return(RedirectToAction("Edit", new { team_id = model.Id }));
                }
            }
            catch (Exception e)
            {
                TempData["error"] = $"Problems with getting information from database (services). {e.Message}";
                return(RedirectToAction("Edit", new { team_id = model.Id }));
            }
            return(RedirectToAction("Index"));
        }
Пример #5
0
        public async Task <IActionResult> Edit(int id, [Bind("Id,Name")] TeamsModel teamsModel)
        {
            if (id != teamsModel.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(teamsModel);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!TeamsModelExists(teamsModel.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(teamsModel));
        }
Пример #6
0
        public ActionResult Create(TeamsVm model)
        {
            if (model is null || string.IsNullOrWhiteSpace(model.Name))
            {
                TempData["error"] = $"You did not fill name. Name is required.";
                return(RedirectToAction("Create"));
            }
            TeamsModel team = new TeamsModel()
            {
                Name = model.Name
            };

            try
            {
                if (!_teamService.Create(team))
                {
                    TempData["error"] = $"Problems with create team (Service error \"Create\").";
                    return(RedirectToAction("Create"));
                }
            }
            catch (Exception e)
            {
                TempData["error"] = $"Problems with saving information to database (services). {e.Message}";
                return(RedirectToAction("Create"));
            }
            return(RedirectToAction("Index"));
        }
Пример #7
0
        public ActionResult Edit(int team_id)
        {
            string errorMsg = String.Empty;

            if (TempData.ContainsKey("error"))
            {
                errorMsg = TempData["error"].ToString();
            }
            TeamsModel team  = new TeamsModel();
            TeamsVm    model = new TeamsVm();

            try
            {
                team = _teamService.GetTeam(team_id);
            }
            catch (Exception e)
            {
                TempData["error"] = $"Problems with getting information from database (services). {e.Message}";
                return(RedirectToAction("Index"));
            }
            model.Id   = team.Id;
            model.Name = team.Name;

            return(View("Edit", model));
        }
Пример #8
0
        public TeamsModel GetTeam(int team_id)
        {
            TeamsModel team = new TeamsModel();

            try
            {
                using (SqlConnection connection = new SqlConnection(ConnectionString))
                {
                    string queryString = $"SELECT * FROM {TeamsTable} WHERE {TeamsTable}.id = {team_id};";
                    connection.Open();
                    SqlCommand command = new SqlCommand(queryString, connection);
                    command.Prepare();
                    SqlDataReader reader = command.ExecuteReader();

                    while (reader.Read())
                    {
                        try
                        {
                            team.Id   = int.Parse(reader["Id"].ToString());
                            team.Name = reader["Name"].ToString();
                        }
                        catch (Exception)
                        {
                            return(new TeamsModel());
                        }
                    }
                }
            }
            catch (Exception)
            {
                return(new TeamsModel());
            }

            return(team);
        }
Пример #9
0
        public TeamsModel GetPlayers()
        {
            var teamsModel = new TeamsModel();

            teamsModel.BlackTeam.AddRange(File.ReadLines(_blackTeamFilename));
            teamsModel.RedTeam.AddRange(File.ReadLines(_redTeamFilename));
            return(teamsModel);
        }
Пример #10
0
 public ActionResult TeamRegister(TeamsModel _RegTeam)
 {
     if (ModelState.IsValid)
     {
         _TeamDataAccess.AddTeams(_mapper.Map(_RegTeam));
         return(RedirectToAction("Index", "Home"));
     }
     return(View());
 }
Пример #11
0
        public TeamsModel GetPlayers()
        {
            var model = new TeamsModel();

            model.RedTeam.Add("John Doe");
            model.RedTeam.Add("Jane Doe");
            model.BlackTeam.Add("Mr Smith");
            return(model);
        }
Пример #12
0
 public ActionResult TeamUpdate(TeamsModel _UpdateTeams)
 {
     if (ModelState.IsValid)
     {
         _UpdateTeams.TeamName = (string)Session["TeamName"];
         _TeamDataAccess.UpdateTeams(_mapper.Map(_UpdateTeams));
         return(RedirectToAction("Index", "Home"));
     }
     return(View());
 }
Пример #13
0
        public async Task <IActionResult> Create([Bind("Id,Name")] TeamsModel teamsModel)
        {
            if (ModelState.IsValid)
            {
                _context.Add(teamsModel);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(teamsModel));
        }
Пример #14
0
        public ActionResult AndyAdmin(int id)
        {
            TeamsModel model = new TeamsModel();

            if (id <= 0)
            {
                return(View(model));
            }
            model = LoadAll(id);
            return(View(model));
        }
Пример #15
0
        public async Task <Result> Handle(ListTeamQuery request, CancellationToken cancellationToken)
        {
            Result result;

            try
            {
                var filter      = request.Filter;
                int?skip        = request.Skip.ToNullableInt();
                int?top         = request.Top.ToNullableInt();
                var teamDomains = await _teamReadRepository.ListAsync(filter, skip, top);

                var teamModels = new List <TeamModel>();

                foreach (var teamDomain in teamDomains)
                {
                    var members = new List <MemberModel>();
                    foreach (var member in teamDomain.Members)
                    {
                        var operatorDomain = await _operatorReadRepository.GetAsync(member);

                        members.Add(_mapper.Map <MemberModel>(operatorDomain));
                    }
                    var teamModel = _mapper.Map <TeamModel>(teamDomain);
                    teamModel.Members = new List <MemberModel>(members);
                    teamModels.Add(teamModel);
                }

                var count      = teamModels.Count;
                var teamsModel = new TeamsModel {
                    Value = teamModels, Count = count, NextLink = null
                };

                result = Result.Ok(teamsModel);
            }
            catch (FilterODataException)
            {
                result = Result.Fail(new List <Failure>()
                {
                    new HandlerFault()
                    {
                        Code    = HandlerFaultCode.InvalidQueryFilter.Name,
                        Message = HandlerFailures.InvalidQueryFilter,
                        Target  = "$filter"
                    }
                });
            }
            catch
            {
                result = Result.Fail(CustomFailures.ListTeamFailure);
            }

            return(result);
        }
Пример #16
0
        private async Task <bool> apiCall()
        {
            string[] matchPaths    = { "v2/competitions/CL/matches", "v2/competitions/PL/matches", "v2/competitions/PD/matches" };
            string[] teamPaths     = { "v2/competitions/CL/teams", "v2/competitions/PL/teams", "v2/competitions/PD/teams" };
            string[] standingPaths = { "v2/competitions/CL/standings", "v2/competitions/PL/standings", "v2/competitions/PD/standings" };
            string[] scorerPaths   = { "v2/competitions/CL/scorers", "v2/competitions/PL/scorers", "v2/competitions/PD/scorers" };

            IEnumerable <MatchesModel> matches = await ApiMatchModelAsync(matchPaths);

            IEnumerable <TeamsModel> teams = await ApiTeamModelAsync(teamPaths);

            IEnumerable <StandingsModel> standings = await ApiStandingModelAsync(standingPaths);

            IEnumerable <ScorerModel> scorers = await ApiScorerModelAsync(scorerPaths);

            clMatches = matches.Where(match => match.competition.id == 2001).FirstOrDefault();
            plMatches = matches.Where(match => match.competition.id == 2021).FirstOrDefault();
            pdMatches = matches.Where(match => match.competition.id == 2014).FirstOrDefault();

            allMatch.AddRange(clMatches.matches);
            allMatch.AddRange(plMatches.matches);
            allMatch.AddRange(pdMatches.matches);

            clTeams = teams.Where(team => team.competition.id == 2001).FirstOrDefault();
            plTeams = teams.Where(team => team.competition.id == 2021).FirstOrDefault();
            pdTeams = teams.Where(team => team.competition.id == 2014).FirstOrDefault();

            allTeams.AddRange(clTeams.teams);
            allTeams.AddRange(plTeams.teams);
            allTeams.AddRange(pdTeams.teams);

            clStanding = standings.Where(standing => standing.competition.id == 2001).FirstOrDefault();
            plStanding = standings.Where(standing => standing.competition.id == 2021).FirstOrDefault();
            pdStanding = standings.Where(standing => standing.competition.id == 2014).FirstOrDefault();

            clScorers = scorers.Where(scorer => scorer.competition.id == 2001).FirstOrDefault();
            plScorers = scorers.Where(scorer => scorer.competition.id == 2021).FirstOrDefault();
            pdScorers = scorers.Where(scorer => scorer.competition.id == 2014).FirstOrDefault();

            return(true);
        }
Пример #17
0
 public bool Create(TeamsModel team)
 {
     if (team == null)
     {
         return(false);
     }
     try
     {
         using (SqlConnection connection = new SqlConnection(ConnectionString))
         {
             string queryString = $"INSERT INTO {TeamsTable} (Name) " +
                                  $"VALUES ('{team.Name}')";
             connection.Open();
             SqlCommand command = new SqlCommand(queryString, connection);
             command.Prepare();
             int number = command.ExecuteNonQuery();
             return(number > 0 ? true : false);
         }
     }
     catch (Exception)
     {
         return(false);
     }
 }
Пример #18
0
        public List <TeamsModel> GetTeams()
        {
            List <TeamsModel> teams = new List <TeamsModel>();

            try
            {
                using (SqlConnection connection = new SqlConnection(ConnectionString))
                {
                    string queryString = $"SELECT * FROM {TeamsTable};";
                    connection.Open();
                    SqlCommand command = new SqlCommand(queryString, connection);
                    command.Prepare();
                    SqlDataReader reader = command.ExecuteReader();
                    while (reader.Read())
                    {
                        try
                        {
                            TeamsModel team = new TeamsModel();
                            team.Id   = int.Parse(reader["Id"].ToString());
                            team.Name = reader["Name"].ToString();

                            teams.Add(team);
                        }
                        catch (Exception)
                        {
                            return(new List <TeamsModel>());
                        }
                    }
                }
            }
            catch (Exception)
            {
                return(new List <TeamsModel>());
            }
            return(teams);
        }
Пример #19
0
        public ActionResult TeamRegister()
        {
            TeamsModel _Teams = new TeamsModel();

            return(View(_Teams));
        }
Пример #20
0
        public ActionResult TeamUpdate()
        {
            TeamsModel _UpdateTeam = new TeamsModel();

            return(View(_UpdateTeam));
        }