Esempio n. 1
0
        public ActionResult AcceptMatch(AcceptMatchViewModel model)
        {
            if (ModelState.IsValid)
            {
                bool notValid = false;
                var  match    = db.Match.Find(model.MatchId);
                if (!matchManager.MembersGoalsValid(model.MembersGoals, model.Team2Score))
                {
                    notValid           = true;
                    model.MembersGoals = 0;
                    ModelState.AddModelError("accepterror", "Suma strzelonych bramek przez graczy musi być równa liczbie strzelonych bramek przez drużynę");
                    return(RedirectToAction("Index", "Match", model));
                }

                if (!notValid)
                {
                    if (match.MembersGoalsSplitTeam1 == null)
                    {
                        match.MembersGoalsSplitTeam1 = model.MembersGoalsSplit;
                    }
                    else
                    {
                        match.MembersGoalsSplitTeam2 = model.MembersGoalsSplit;
                    }
                    matchManager.AcceptMatch(match);
                    return(RedirectToAction("Index", "Match"));
                }
            }
            return(RedirectToAction("Index", "Match"));
        }
Esempio n. 2
0
        public ActionResult AcceptMatch(int id)
        {
            string name  = Helpers.UserName();
            var    match = db.Match.Find(id);
            int    score;

            score = match.Team1 == name ? match.Team1Score : match.Team2Score;

            ViewBag.Members = db.Users.Where(u => u.Name == name).SingleOrDefault().Members.ToList();

            var model = new AcceptMatchViewModel()
            {
                MatchId = id, Team2 = name, Team2Score = score
            };

            if (name == "admin")
            {
                model.MembersGoals      = score;
                model.MembersGoalsSplit = "admin";
            }

            return(PartialView("_AcceptMatch", model));
        }