Exemple #1
0
        public ActionResult Create(BracketCreate model)
        {
            var svc = new BracketService();

            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            if (svc.CreateBracket(model))
            {
                TempData["SaveResult"] = "Your Bracket is set! May the best character win!";
                return(RedirectToAction("Index"));
            }
            ;

            ModelState.AddModelError("", "Bracket was unable to be created, please try again");

            return(View(model));
        }
Exemple #2
0
        public bool CreateBracket(BracketCreate model)
        {
            //Winner Generator
            var outcome             = RandomWinner(0, 100);
            var outcomeTwo          = RandomWinner(0, 100);
            var outcomeThree        = RandomWinner(0, 100);
            var outcomeFour         = RandomWinner(0, 100);
            var outcomeFinalFour    = RandomWinner(0, 100);
            var outcomeFinalFourTwo = RandomWinner(0, 100);
            var outcomeFinal        = RandomWinner(0, 100);

            //First 8
            if (outcome < 50)
            {
                model.FirstEightWinnerId = model.FirstCharacterEightId;
            }
            else
            {
                model.FirstEightWinnerId = model.SecondCharacterEightId;
            }
            //Second 8
            if (outcomeTwo < 50)
            {
                model.SecondEightWinnerId = model.ThirdCharacterEightId;
            }
            else
            {
                model.SecondEightWinnerId = model.FourthCharacterEightId;
            }
            //Third 8
            if (outcomeThree < 50)
            {
                model.ThirdEightWinnerId = model.FifthCharacterEightId;
            }
            else
            {
                model.ThirdEightWinnerId = model.SixthCharacterEightId;
            }
            //Fourth 8
            if (outcomeFour < 50)
            {
                model.FourthEightWinnerId = model.SeventhCharacterEightId;
            }
            else
            {
                model.FourthEightWinnerId = model.EighthCharacterEightId;
            }

            var entity =
                new Bracket()
            {
                Location       = model.Location,
                TournamentName = model.TournamentName,
                //Elite Eight
                FirstCharacterEightId   = model.FirstCharacterEightId,
                SecondCharacterEightId  = model.SecondCharacterEightId,
                ThirdCharacterEightId   = model.ThirdCharacterEightId,
                FourthCharacterEightId  = model.FourthCharacterEightId,
                FifthCharacterEightId   = model.FifthCharacterEightId,
                SixthCharacterEightId   = model.SixthCharacterEightId,
                SeventhCharacterEightId = model.SeventhCharacterEightId,
                EighthCharacterEightId  = model.EighthCharacterEightId,
                FirstEightWinnerId      = model.FirstEightWinnerId,
                SecondEightWinnerId     = model.SecondEightWinnerId,
                ThirdEightWinnerId      = model.ThirdEightWinnerId,
                FourthEightWinnerId     = model.FourthEightWinnerId,
                //Final Four
                FirstCharacterFourId  = model.FirstEightWinnerId,
                SecondCharacterFourId = model.SecondEightWinnerId,
                ThirdCharacterFourId  = model.ThirdEightWinnerId,
                FourthCharacterFourId = model.FourthEightWinnerId,

                FirstFourWinnerId  = model.FirstFourWinnerId,
                SecondFourWinnerId = model.SecondFourWinnerId,
                //Final
                FirstCharacterFinalId  = model.FirstFourWinnerId,
                SecondCharacterFinalId = model.SecondFourWinnerId,
                FinalWinnerId          = model.FinalWinnerId
            };


            //First 4
            if (outcomeFinalFour < 50)
            {
                entity.FirstFourWinnerId = entity.FirstCharacterFourId;
            }
            else
            {
                entity.FirstFourWinnerId = entity.SecondCharacterFourId;
            }
            //Second 4
            if (outcomeFinalFourTwo < 50)
            {
                entity.SecondFourWinnerId = entity.ThirdCharacterFourId;
            }
            else
            {
                entity.SecondFourWinnerId = entity.FourthCharacterFourId;
            }
            //Final
            if (outcomeFinal < 50)
            {
                entity.FinalWinnerId = entity.FirstFourWinnerId;
            }
            else
            {
                entity.FinalWinnerId = entity.SecondFourWinnerId;
            }

            using (var ctx = new ApplicationDbContext())
            {
                ctx.Brackets.Add(entity);
                return(ctx.SaveChanges() == 1);
            }
        }