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)); }
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)); }
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); } }