public async Task <IActionResult> Create([Bind("CharacterName,Hp,Str,Dex,Con,Int,Wis,Cha,Initiative,Maxhp")] Character character) { //Validation Logic if (character.Hp > character.MaxHp) { ModelState.AddModelError("Hp", "Current HP cannot be greater than Max HP"); } try { if (ModelState.IsValid) { _context.Add(character); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } } catch (DbUpdateException /* ex */) { //Log the error (uncomment ex variable name and wirte a log ModelState.AddModelError("", "Unable to save Changes. " + "Try again, and if the problem perists " + "see your system administrator."); } return(View(character)); }
public async Task <IActionResult> Create([Bind("Id,Name,Description")] Building building) { if (ModelState.IsValid) { _context.Add(building); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(building)); }
public async Task <IActionResult> Create([Bind("Population,Id,Name,Description")] City city) { if (ModelState.IsValid) { _context.Add(city); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(city)); }
public async Task <IActionResult> Create([Bind("Id,FeatureName,FeatureDescription,Active,Combat")] ClassFeature classFeature) { if (ModelState.IsValid) { _context.Add(classFeature); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(classFeature)); }
public async Task <IActionResult> Create([Bind("BlogId,Url")] Blog blog) { if (ModelState.IsValid) { _context.Add(blog); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(blog)); }
public async Task <IActionResult> Create([Bind("Id,ClassName,HitDice,Level,Features")] ClassLevel classLevel) { if (ModelState.IsValid) { _context.Add(classLevel); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(classLevel)); }
public async Task <IActionResult> Create([Bind("PostId,Title,Content,BlogId")] Post post) { if (ModelState.IsValid) { _context.Add(post); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } ViewData["BlogId"] = new SelectList(_context.Blogs, "BlogId", "BlogId", post.BlogId); return(View(post)); }
public async Task OnPostToggle(int id, bool inCombat) { var newCombatStatus = !inCombat; (await _context.Rooms.FindAsync(id)).InCombat = newCombatStatus; var characters = _context.Characters.Where(c => c.RoomId == id); if (!newCombatStatus) { await characters.ForEachAsync(c => { c.Initiative = 0; c.TurnNumber = 0; }); } else { await characters.ForEachAsync(c => c.Initiative = DiceRoller.RollD20(c.Dex)); } await _context.SaveChangesAsync(); }