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