Beispiel #1
0
        async public Task <ActionResult> Yield()
        {
            string userId = User.Identity.GetUserId();
            Match  match  = await GladiatorHandler.GetActiveMatch(userId);

            if (match == null)
            {
                Response.StatusCode = (int)HttpStatusCode.BadRequest;
                return(Json(new string[] { "Tried to yield when there's no match." }));
            }
            if (match.NextAttacker.Owner.Id != userId)
            {
                Response.StatusCode = (int)HttpStatusCode.BadRequest;
                return(Json(new string[] { "Not user's turn." }));
            }
            await GladiatorHandler.YieldTurn(match);

            //If npc didnt accept the yield, attack
            if (match.Winner == null && match.NextAttacker.IsNPC)
            {
                await GladiatorHandler.AttackTurn(match);
            }

            return(PartialView("Index", match));
        }
Beispiel #2
0
        async public Task <ActionResult> Index()
        {
            ViewBag.Title = "Home Page";
            if (!Request.IsAuthenticated)
            {
                if (Request.IsAjaxRequest())
                {
                    return(PartialView("Login"));
                }
                if (!Request.IsAjaxRequest())
                {
                    return(View("Login"));
                }
            }

            string            userId = User.Identity.GetUserId();
            HomePageViewModel model  = new HomePageViewModel
            {
                User               = await UserHandler.GetUser(userId),
                Gladiators         = await GladiatorHandler.GetCurrentGladiators(userId),
                AllUserScores      = (await UserHandler.GetAllUsers()).Select(u => u.Score).Where(s => s != null).ToList(),
                AllGladiatorScores = (await GladiatorHandler.GetAllGladiators()).Select(g => g.Score).Where(s => s != null).ToList()
            };

            if (Request.IsAjaxRequest())
            {
                return(PartialView(model));
            }
            return(View(model));
        }
Beispiel #3
0
        async public Task <ActionResult> CreateMatch()
        {
            string userId = User.Identity.GetUserId();
            GladiatorOpponentsViewModel model = new GladiatorOpponentsViewModel
            {
                Gladiators = await GladiatorHandler.GetCurrentGladiators(userId),
                Opponents  = await GladiatorHandler.GetRandomOpponents()
            };

            return(PartialView("_NewMatch", model));
        }
Beispiel #4
0
        async public Task <ActionResult> Index()
        {
            string userId = User.Identity.GetUserId();
            Match  match  = await GladiatorHandler.GetActiveMatch(userId);

            if (match == null)
            {
                return(RedirectToAction("CreateMatch"));
            }

            return(PartialView(match));
        }
Beispiel #5
0
        async public Task <ActionResult> Index()
        {
            string userId = User.Identity.GetUserId();
            GladiatorOpponentsViewModel model = new GladiatorOpponentsViewModel
            {
                Gladiators = await GladiatorHandler.GetCurrentGladiators(userId)
            };

            if (User.IsInRole("Admin"))
            {
                model.Opponents = await GladiatorHandler.GetOpponents(userId);
            }
            return(PartialView(model));
        }
Beispiel #6
0
        async public Task <ActionResult> CreateOpponent([Bind] OpponentBindingModel model)
        {
            if (!ModelState.IsValid)
            {
                var errorList = ModelState.Values.SelectMany(m => m.Errors)
                                .Select(e => e.ErrorMessage)
                                .ToList();

                Response.StatusCode = (int)HttpStatusCode.BadRequest;
                return(Json(errorList));
            }

            string userId = User.Identity.GetUserId();

            return(await GladiatorHandler.CreateOpponent(model, userId));
        }
Beispiel #7
0
        async public Task <ActionResult> CreateMatch([Bind(Include = "GladiatorID, OpponentID")] MatchBindingModel model)
        {
            if (!ModelState.IsValid)
            {
                var errorList = ModelState.Values.SelectMany(m => m.Errors)
                                .Select(e => e.ErrorMessage)
                                .ToList();

                Response.StatusCode = (int)HttpStatusCode.BadRequest;
                return(Json(errorList));
            }

            string userId = User.Identity.GetUserId();
            await GladiatorHandler.CreateMatch(model, userId);

            return(RedirectToAction("Index"));
        }
Beispiel #8
0
        async public Task <ActionResult> Edit([Bind(Include = "Id, Name, IsNPC")] GladiatorBindingModel model)
        {
            if (!ModelState.IsValid)
            {
                var errorList = ModelState.Values.SelectMany(m => m.Errors)
                                .Select(e => e.ErrorMessage)
                                .ToList();

                Response.StatusCode = (int)HttpStatusCode.BadRequest;
                return(Json(errorList));
            }

            bool   isAdmin = User.IsInRole("Admin");
            string userId  = User.Identity.GetUserId();

            return(await GladiatorHandler.EditGladiator(model, userId, isAdmin));
        }
Beispiel #9
0
        async public Task <ActionResult> EditOpponent(int id)
        {
            Gladiator opponent = await GladiatorHandler.GetGladiator(id);

            if (opponent == null)
            {
                return(RedirectToAction("Opponents"));
            }
            OpponentBindingModel model = new OpponentBindingModel
            {
                Id         = id,
                Name       = opponent.Name,
                Level      = opponent.Level,
                Experience = opponent.Experience,
                MaxHealth  = opponent.MaxHealth
            };

            return(PartialView(model));
        }
Beispiel #10
0
        async public Task <ActionResult> EditOpponent([Bind] OpponentBindingModel model)
        {
            if (!ModelState.IsValid)
            {
                var errorList = ModelState.Values.SelectMany(m => m.Errors)
                                .Select(e => e.ErrorMessage)
                                .ToList();

                Response.StatusCode = (int)HttpStatusCode.BadRequest;
                return(Json(errorList));
            }

            (HttpStatusCodeResult result, Gladiator opponent) = await GladiatorHandler.EditOpponent(model);

            if (result.StatusCode == 200)
            {
                return(PartialView("_OpponentRow", opponent));
            }
            else
            {
                return(result);
            }
        }
Beispiel #11
0
 async public Task <ActionResult> Opponents()
 {
     return(PartialView(await GladiatorHandler.GetOpponents()));
 }