public ActionResult CreateEvent()
        {
            Setup();
            var newEvent = new Magic.Domain.Event();

            var currentRoundDropdown = GetDropdownWithSelected(4, 1);
            var roundMatchesDropdown = GetDropdownWithSelected(4, 4);

            @ViewBag.CurrentRound = currentRoundDropdown;
            @ViewBag.RoundMatches = roundMatchesDropdown;
            @ViewBag.NewEvent     = true;

            return(View("EditEvent", newEvent));
        }
        public ActionResult Details(string eventName, int round, int player1ID, int player2ID, int?player1wins, int?player2wins, int?draws)
        {
            Setup();
            Magic.Domain.Event thisEvent = _eventManager.LoadEvent(eventName);

            var match = thisEvent.Matches.FirstOrDefault(m => (m.Round == round) && ((m.Player1ID == player1ID && m.Player2ID == player2ID) || (m.Player2ID == player1ID && m.Player1ID == player2ID)));

            ViewBag.Match = match;

            if (match == null)
            {
                Session["LastError"] = new Exception($"Match {player1ID} vs {player2ID} not found in {eventName}:{round}");
                return(View("Index", new
                {
                    eventName = eventName,
                    round = round
                }));
            }


            if (player1wins.HasValue && player2wins.HasValue && draws.HasValue)
            {
                if (thisEvent.Locked(round))
                {
                    ModelState.AddModelError("CustomError", "This match is Locked");
                }
                else
                {
                    match.Player1Wins = player1wins.Value;
                    match.Player2Wins = player2wins.Value;
                    match.Draws       = draws.Value;

                    _matchManager.Update(match);

                    return(RedirectToAction("Index", new { controller = "Magic", eventName = eventName, round = round }));
                }
            }

            var p1Dropdown    = GetDropdownWithSelected(2, match.Player1Wins);
            var p2Dropdown    = GetDropdownWithSelected(2, match.Player2Wins);
            var drawsDropdown = GetDropdownWithSelected(3, match.Draws);

            ViewBag.player1wins = p1Dropdown;
            ViewBag.player2wins = p2Dropdown;
            ViewBag.draws       = drawsDropdown;

            return(View("MagicMatch"));
        }
        public ActionResult EditEvent(string eventName, bool NewEvent, string name, int?currentRound, int?roundMatches, DateTime?startDate, DateTime?roundEndDate)
        {
            Setup();
            Magic.Domain.Event thisEvent = null;
            if (NewEvent == false)
            {
                thisEvent = _eventManager.LoadEvent(eventName);
            }
            else
            {
                thisEvent = new Magic.Domain.Event();
            }

            if (currentRound.HasValue)
            {
                thisEvent.name           = name;
                thisEvent.CurrentRound   = currentRound.HasValue ? currentRound.Value : thisEvent.CurrentRound;
                thisEvent.RoundMatches   = roundMatches.HasValue ? roundMatches.Value : thisEvent.RoundMatches;
                thisEvent.EventStartDate = startDate.HasValue ? startDate.Value : thisEvent.EventStartDate;
                thisEvent.RoundEndDate   = roundEndDate.HasValue ? roundEndDate.Value : thisEvent.RoundEndDate;


                if (NewEvent == false)
                {
                    _eventManager.SaveEvent(thisEvent);
                }
                else
                {
                    _eventManager.CreateEvent(thisEvent);
                }


                return(ViewEvents());
            }


            var currentRoundDropdown = GetDropdownWithSelected(4, thisEvent.CurrentRound);
            var roundMatchesDropdown = GetDropdownWithSelected(4, thisEvent.RoundMatches);

            @ViewBag.CurrentRound = currentRoundDropdown;
            @ViewBag.RoundMatches = roundMatchesDropdown;
            @ViewBag.NewEvent     = false;

            return(View("EditEvent", thisEvent));
        }