Beispiel #1
0
        public async Task <IActionResult> Save(CreateMatchViewModel model)
        {
            if (!ModelState.IsValid)
            {
                List <TeamDTO> teams = await _teamService.GetAll();

                ViewBag.HostTeams  = CreateViewBagTeams(teams);
                ViewBag.GuestTeams = CreateViewBagTeams(teams);
                return(View("Create", model));
            }

            MatchDTO addedMatch = await SaveMatch(model);

            if (addedMatch.MatchId != 0)
            {
                List <MatchTeamPlayerDTO> playersInMatch = new List <MatchTeamPlayerDTO>();
                Status addingHostPlayersStatus           = await SavePlayers(model.HostPlayerList, model.HostTeamId, addedMatch.MatchId);

                Status addingGuestPlayersStatus = await SavePlayers(model.GuestPlayerList, model.GuestTeamId, addedMatch.MatchId);

                return(RedirectToAction("Index"));
            }
            //already exists so adding resulted in null
            return(View("Create", model));
        }
Beispiel #2
0
        public async Task <IActionResult> Create(CreateMatchViewModel model)
        {
            if (ModelState.IsValid)
            {
                Match match = new Match();
                match.name        = model.name;
                match.team1       = model.team1;
                match.team2       = model.team2;
                match.scoresTeam1 = Convert.ToSByte(model.scoresTeam1);
                match.scoresTeam2 = Convert.ToSByte(model.scoresTeam2);
                match.img         = model.img.FileName;
                match.date        = DateTime.Now;
                // путь к папке Files
                string path = "/img/" + model.img.FileName;
                // сохраняем файл в папку Files в каталоге wwwroot
                using (var fileStream = new FileStream(_appEnvironment.WebRootPath + path, FileMode.Create))
                {
                    await model.img.CopyToAsync(fileStream);
                }
                db.Match.Add(match);
                await db.SaveChangesAsync();

                return(RedirectToAction("Index", "Home"));
            }
            return(View(model));
        }
        // GET: Matches/Edit/5
        public async Task <IActionResult> Edit(int id)
        {
            var match = await _context.Matches.FindAsync(id);

            if (match == null)
            {
                return(NotFound());
            }

            var league = _leaguesService.GetLeague(match.LeagueId);

            if (!league.LeagueAdminEmails.Contains(User.Identity.Name))
            {
                return(NotFound());
            }

            var model = new CreateMatchViewModel();

            model.TeamsSelectList = new SelectList(_context.Leagues.Include(x => x.Teams).SingleOrDefault(x => x.Id == match.LeagueId)?.Teams, "Id", "Name");

            model.LeagueId       = match.LeagueId;
            model.LeagueName     = _context.Leagues.SingleOrDefault(x => x.Id == match.LeagueId)?.Name;
            model.Time           = DateTime.Now.Date;
            model.HomeTeamId     = match.HomeTeamId;
            model.HomeGoalsCount = match.HomeGoalsCount;
            model.AwayGoalsCount = match.AwayGoalsCount;
            model.AwayTeamId     = match.AwayTeamId;
            return(View(model));
        }
Beispiel #4
0
        //Sets BindingContext ViewModel and a image
        private void Init(Func <CreateMatchViewModel> ctor)
        {
            InitializeComponent();

            _vm             = ctor();
            BindingContext  = _vm;
            _vm.Navigation  = Navigation;
            SaveIcon.Source = ImageSource.FromResource("application.Images.saveicon.png");
        }
Beispiel #5
0
        public async Task <IActionResult> Create()
        {
            CreateMatchViewModel model = new CreateMatchViewModel();
            List <TeamDTO>       teams = await _teamService.GetAll();

            ViewBag.HostTeams  = CreateViewBagTeams(teams);
            ViewBag.GuestTeams = CreateViewBagTeams(teams);
            return(View(model));
        }
        public ActionResult CreateMatch(int stadiumId, DateTime dateTime)
        {
            var model = new CreateMatchViewModel()
            {
                DateTime  = dateTime,
                StadiumId = stadiumId
            };

            return(View(model));
        }
Beispiel #7
0
        private async Task <MatchDTO> SaveMatch(CreateMatchViewModel model)
        {
            MatchDTO matchBasic        = Mapping.Mapper.Map <MatchDTO>(model);
            Status   addingMatchStatus = await _matchService.Add(matchBasic);

            if (addingMatchStatus == Status.Success)
            {
                matchBasic = await _matchService.GetByUniqueIdentifiers(model.HostTeamId, model.GuestTeamId, model.StartTime);
            }
            return(matchBasic);
        }
Beispiel #8
0
        private void Match(CreateMatchViewModel hold, int s1, int s2)
        {
            _unitOfWork.SaveChanges();
            var match = _fussballRepository.CreateMatch(hold.PlayerOneId, hold.PlayerTwoId, hold.PlayerThreeId, hold.PlayerFourId);

            _unitOfWork.SaveChanges();
            var dbmatch      = _fussballRepository.GetMatch(match.Id);
            var dbMatchsaved = new MatchCon().SetResult(dbmatch, s1, s2);

            _unitOfWork.SaveChanges();
        }
Beispiel #9
0
        private CreateMatchViewModel SetTeam(string et, string to, string tre, string fire)
        {
            var players = _playerRepository.AsQueryable();
            var model   = new CreateMatchViewModel();

            model.PlayerOneId   = players.First(p => p.Initials == et).Id;
            model.PlayerTwoId   = players.First(p => p.Initials == to).Id;
            model.PlayerThreeId = players.First(p => p.Initials == tre).Id;
            model.PlayerFourId  = players.First(p => p.Initials == fire).Id;
            var hold1team1 = _fussballRepository.CreateOrGetTeam(model.PlayerOneId, model.PlayerTwoId);
            var hold1team2 = _fussballRepository.CreateOrGetTeam(model.PlayerThreeId, model.PlayerFourId);

            return(model);
        }
Beispiel #10
0
        public ActionResult CreateMatch()
        {
            var TestModel = new CreateMatchViewModel();

            //TODO Remove test data
            {
                {
                    TestModel.PlayerOne   = "MIB";
                    TestModel.PlayerTwo   = "BOS";
                    TestModel.PlayerThree = "MRA";
                    TestModel.PlayerFour  = "ANJ";
                }
            }
            return(View(TestModel));
        }
Beispiel #11
0
        public ActionResult Match(CreateMatchViewModel vm)
        {
            Match model;

            if (RedOrBlueTeam())
            {
                model = _fussballRepository.CreateMatch(vm.PlayerOneId, vm.PlayerTwoId, vm.PlayerThreeId, vm.PlayerFourId);
            }
            else
            {
                model = _fussballRepository.CreateMatch(vm.PlayerThreeId, vm.PlayerFourId, vm.PlayerOneId, vm.PlayerTwoId);
            }
            _unitOfWork.Save();
            return(RedirectToAction("MatchByGuid", new { id = model.Id }));
        }
Beispiel #12
0
        public ActionResult CreateMatch(CreateMatchViewModel vm)
        {
            var strList = new List <string> {
                vm.PlayerOne, vm.PlayerTwo, vm.PlayerThree, vm.PlayerFour
            };
            var players       = _fussballRepository.GetPlayers().ToList();
            var playerToMatch = players.Where(item => strList.Contains(item.Initials)).OrderBy(p => p.Score).ThenBy(i => Guid.NewGuid()).ToList();

            if (playerToMatch.Distinct().Count() != 4) // Fail first
            {
                return(View(vm));
            }
            var model = new MatchCon().CreateMatchViewModel(vm, playerToMatch);

            _fussballRepository.CreateOrGetTeam(model.PlayerOneId, model.PlayerTwoId);
            _fussballRepository.CreateOrGetTeam(model.PlayerThreeId, model.PlayerFourId);
            _unitOfWork.Save();

            return(RedirectToAction("Match", model));
        }
        // GET: Leagues/CreateMatch
        public IActionResult CreateMatch(int leagueId)
        {
            var league = _leaguesService.GetLeague(leagueId);

            if (!league.LeagueAdminEmails.Contains(User.Identity.Name))
            {
                return(NotFound());
            }

            if (league != null)
            {
                var model = new CreateMatchViewModel();
                model.TeamsSelectList = new SelectList(league.Teams, "Id", "Name");
                model.LeagueId        = leagueId;
                model.LeagueName      = league.Name;
                model.Time            = DateTime.Now.Date;
                return(View(model));
            }

            return(NoContent());
        }
Beispiel #14
0
        public async Task <IActionResult> Create()
        {
            try
            {
                SERVICES.Team[] teams = await _teamService.GetTeamsAsync();

                var model = new CreateMatchViewModel
                {
                    Date          = null,
                    AwayTeamScore = null,
                    HomeTeamScore = null,
                    Teams         = teams.ToDictionary(t => t.Id, t => t.Name),
                };

                return(View(model));
            }
            catch (Exception ex)
            {
                return(this.HandleException(ex, message: ex.Message, logger: _logger));
            }
        }
Beispiel #15
0
        public async Task <IActionResult> Create(
            CreateMatchViewModel model,
            CancellationToken cancellationToken = default)
        {
            try
            {
                if (!ModelState.IsValid)
                {
                    return(View(model));
                }

                if (model.Date > DateTime.Now)
                {
                    ModelState.AddModelError(nameof(model.Date), "Match date cannot be in the future.");
                    return(View(model));
                }
                if (model.HomeTeamId == model.AwayTeamId)
                {
                    ModelState.AddModelError(nameof(model.HomeTeamId), "A team cannot have match with itself.");
                    return(View(model));
                }

                var createRequest = new SERVICES.CreateMatchRequest
                {
                    AwayTeamId    = model.AwayTeamId,
                    AwayTeamScore = model.AwayTeamScore.Value,
                    Date          = model.Date.Value,
                    HomeTeamId    = model.HomeTeamId,
                    HomeTeamScore = model.HomeTeamScore.Value
                };

                int id = await _matchService.CreateMatchAsync(createRequest, cancellationToken);

                return(RedirectToAction("Index"));
            }
            catch (Exception ex)
            {
                return(this.HandleException(ex, message: ex.Message, logger: _logger));
            }
        }
        // GET: Match/Create
        public ActionResult Create()
        {
            var model = new CreateMatchViewModel()
            {
                HostTeams  = teamRepository.GetAllWithMinSixPlayers(),
                GuestTeams = teamRepository.GetAllWithMinSixPlayers()
            };

            model.PlayersHostTeam = new List <TeamPlayersForMatch>();
            model.HostTeams.FirstOrDefault().Players.ToList().ForEach(p =>
            {
                model.PlayersHostTeam.Add(new TeamPlayersForMatch()
                {
                    Id               = p.Id,
                    Name             = p.Name,
                    TeamId           = p.TeamId,
                    SelectedForMatch = false,
                    Team             = p.Team
                });
            });
            model.PlayersGuestTeam = new List <TeamPlayersForMatch>();
            model.GuestTeams.FirstOrDefault().Players.ToList().ForEach(p =>
            {
                model.PlayersGuestTeam.Add(new TeamPlayersForMatch()
                {
                    Id               = p.Id,
                    Name             = p.Name,
                    TeamId           = p.TeamId,
                    SelectedForMatch = false,
                    Team             = p.Team
                });
            });
            if (model.HostTeams.Count != 0)
            {
                int id = model.HostTeams.FirstOrDefault().Id;
                model.DisabledDates = matchRepository.GetAllDisabledDate(id, id).ToArray();
            }
            return(View(model));
        }
Beispiel #17
0
        public CreateMatchViewModel CreateMatchViewModel(CreateMatchViewModel vm, List <Player> playerToMatch)
        {
            var model = new CreateMatchViewModel
            {
                FixedTeam    = vm.FixedTeam,
                HandicapGame = vm.HandicapGame,
            };

            if (vm.FixedTeam)
            {
                model.PlayerOneId   = playerToMatch.First(p => p.Initials == vm.PlayerOne).Id;
                model.PlayerTwoId   = playerToMatch.First(p => p.Initials == vm.PlayerTwo).Id;
                model.PlayerThreeId = playerToMatch.First(p => p.Initials == vm.PlayerThree).Id;
                model.PlayerFourId  = playerToMatch.First(p => p.Initials == vm.PlayerFour).Id;
            }
            else
            {   // Sortede by player score
                model.PlayerOneId   = playerToMatch.ElementAt(0).Id;
                model.PlayerTwoId   = playerToMatch.ElementAt(3).Id;
                model.PlayerThreeId = playerToMatch.ElementAt(1).Id;
                model.PlayerFourId  = playerToMatch.ElementAt(2).Id;
            }
            return(model);
        }
        public async Task <IActionResult> CreateMatch([Bind("Id,HomeTeamId,AwayTeamId,Time,Venue,HomeGoalsCount,AwayGoalsCount, LeagueId")] CreateMatchViewModel model)
        {
            var league = _leaguesService.GetLeague(model.LeagueId);

            bool isUserLeaguesAdmin = league.LeagueAdminEmails.Contains(User.Identity.Name);

            if (isUserLeaguesAdmin || User.IsInRole(CustomRoles.SuperAdmin))
            {
                if (model.HomeTeamId == model.AwayTeamId)
                {
                    ModelState.AddModelError("SameTeamsError", "Tim ne može igrati sam protiv sebe.");
                }
                if (ModelState.IsValid)
                {
                    var match = new Match()
                    {
                        AwayTeamId     = model.AwayTeamId,
                        HomeTeamId     = model.HomeTeamId,
                        HomeGoalsCount = model.HomeGoalsCount.Value,
                        AwayGoalsCount = model.AwayGoalsCount.Value,
                        Time           = model.Time,
                        LeagueId       = model.LeagueId,
                        Venue          = model.Venue,
                        CreatedBy      = User.Identity.Name,
                        CreatedOn      = DateTime.Now
                    };
                    _leaguesService.AddMatch(match);

                    return(RedirectToAction(nameof(Details), new { id = model.LeagueId }));
                }
                model.TeamsSelectList = new SelectList(_leaguesService.GetLeague(model.LeagueId).Teams, "Id", "Name");
                return(View(model));
            }

            return(NotFound("You had no right to do that."));
        }
        public ActionResult Create(CreateMatchViewModel match)
        {
            string[] hostPlayersIds  = { };
            string[] guestPlayersIds = { };
            System.Diagnostics.Debug.WriteLine("Host players: " + match.SelectedHostTeamPlayers);
            System.Diagnostics.Debug.WriteLine("Guest players: " + match.SelectedGuestTeamPlayers);
            if (string.IsNullOrEmpty(match.SelectedHostTeamPlayers))
            {
                ModelState.AddModelError("PlayersHostTeam", "You must select minimum 6 players");
            }
            else
            {
                hostPlayersIds = match.SelectedHostTeamPlayers.Split(' ');
                if (hostPlayersIds.Length < 6)
                {
                    ModelState.AddModelError("PlayersHostTeam", "You must select minimum 6 players");
                }
            }
            if (string.IsNullOrEmpty(match.SelectedGuestTeamPlayers))
            {
                ModelState.AddModelError("PlayersGuestTeam", "You must select minimum 6 players");
            }
            else
            {
                guestPlayersIds = match.SelectedGuestTeamPlayers.Split(' ');
                if (guestPlayersIds.Length < 6)
                {
                    ModelState.AddModelError("PlayersGuestTeam", "You must select minimum 6 players");
                }
            }
            if (ModelState.IsValid)
            {
                var matchForInsert = new Match()
                {
                    MatchPlace  = match.MatchPlace,
                    MatchTime   = match.MatchTime,
                    Status      = "Not_started",
                    HostTeamId  = match.HostTeamId,
                    GuestTeamId = match.GuestTeamId
                };
                matchRepository.Insert(matchForInsert);
                matchRepository.Save();
                for (int i = 0; i < hostPlayersIds.Length - 1; i++)
                {
                    var playerOnMatch = new PlayerOnMatch()
                    {
                        MatchId  = matchForInsert.Id,
                        PlayerId = Int32.Parse(hostPlayersIds[i])
                    };
                    playerOnMatchRepository.Insert(playerOnMatch);
                    playerOnMatchRepository.Save();
                }
                for (int i = 0; i < guestPlayersIds.Length - 1; i++)
                {
                    var playerOnMatch = new PlayerOnMatch()
                    {
                        MatchId  = matchForInsert.Id,
                        PlayerId = Int32.Parse(guestPlayersIds[i])
                    };
                    playerOnMatchRepository.Insert(playerOnMatch);
                    playerOnMatchRepository.Save();
                }
                return(RedirectToAction("Index"));
            }
            match.HostTeams  = teamRepository.GetAllWithMinSixPlayers();
            match.GuestTeams = teamRepository.GetAllWithMinSixPlayers();

            match.PlayersHostTeam = new List <TeamPlayersForMatch>();
            match.HostTeams.Find(t => t.Id == match.HostTeamId).Players.ToList().ForEach(p =>
            {
                bool selected = false;
                if (hostPlayersIds.Contains(p.Id.ToString()))
                {
                    selected = true;
                }
                match.PlayersHostTeam.Add(new TeamPlayersForMatch()
                {
                    Id               = p.Id,
                    Name             = p.Name,
                    TeamId           = p.TeamId,
                    SelectedForMatch = selected,
                    Team             = p.Team
                });
            });
            match.PlayersGuestTeam = new List <TeamPlayersForMatch>();
            match.GuestTeams.Find(t => t.Id == match.GuestTeamId).Players.ToList().ForEach(p =>
            {
                bool selected = false;
                if (guestPlayersIds.Contains(p.Id.ToString()))
                {
                    selected = true;
                }
                match.PlayersGuestTeam.Add(new TeamPlayersForMatch()
                {
                    Id               = p.Id,
                    Name             = p.Name,
                    TeamId           = p.TeamId,
                    SelectedForMatch = selected,
                    Team             = p.Team
                });;
            });
            match.DisabledDates = matchRepository.GetAllDisabledDate(match.HostTeamId, match.GuestTeamId).ToArray();
            if (match.HostTeamId == match.GuestTeamId)
            {
                ModelState.AddModelError("HostTeamId", "The teams have to be different");
                ModelState.AddModelError("GuestTeamId", "The teams have to be different");
            }
            return(View(match));
        }
        public ActionResult CreateRedirect(int hostTeamId, int guestTeamId, string hostTeamPlayers, string guestTeamPlayers)
        {
            string[] hostPlayersIds  = { };
            string[] guestPlayersIds = { };
            if (!string.IsNullOrEmpty(hostTeamPlayers))
            {
                hostPlayersIds = hostTeamPlayers.Split(' ');
            }
            if (!string.IsNullOrEmpty(guestTeamPlayers))
            {
                guestPlayersIds = guestTeamPlayers.Split(' ');
            }
            var match = new CreateMatchViewModel()
            {
                HostTeamId  = hostTeamId,
                GuestTeamId = guestTeamId
            };

            match.HostTeams  = teamRepository.GetAllWithMinSixPlayers();
            match.GuestTeams = teamRepository.GetAllWithMinSixPlayers();

            match.PlayersHostTeam = new List <TeamPlayersForMatch>();
            match.HostTeams.Find(t => t.Id == match.HostTeamId).Players.ToList().ForEach(p =>
            {
                bool selected = false;
                if (hostPlayersIds.Contains(p.Id.ToString()))
                {
                    selected = true;
                }
                match.PlayersHostTeam.Add(new TeamPlayersForMatch()
                {
                    Id               = p.Id,
                    Name             = p.Name,
                    TeamId           = p.TeamId,
                    SelectedForMatch = selected,
                    Team             = p.Team
                });
            });
            match.PlayersGuestTeam = new List <TeamPlayersForMatch>();
            match.GuestTeams.Find(t => t.Id == match.GuestTeamId).Players.ToList().ForEach(p =>
            {
                bool selected = false;
                if (guestPlayersIds.Contains(p.Id.ToString()))
                {
                    selected = true;
                }
                match.PlayersGuestTeam.Add(new TeamPlayersForMatch()
                {
                    Id               = p.Id,
                    Name             = p.Name,
                    TeamId           = p.TeamId,
                    SelectedForMatch = selected,
                    Team             = p.Team
                });
            });
            match.DisabledDates = matchRepository.GetAllDisabledDate(hostTeamId, guestTeamId).ToArray();
            if (match.HostTeamId == match.GuestTeamId)
            {
                ModelState.AddModelError("HostTeamId", "The teams have to be different");
                ModelState.AddModelError("GuestTeamId", "The teams have to be different");
            }
            return(View("Create", match));
        }