public async Task <ActionResult> Create(SpellFormViewModel spell) { try { using (SqlConnection conn = Connection) { conn.Open(); using (SqlCommand cmd = conn.CreateCommand()) { cmd.CommandText = @"INSERT INTO Spell(Name) OUTPUT INSERTED.Id VALUES (@Name)"; cmd.Parameters.Add(new SqlParameter("@Name", spell.Name)); var Id = (int)cmd.ExecuteScalar(); spell.Id = Id; if (spell.SpellTypeId != 0) { UpdateSpell(spell.Id, spell.SpellTypeId); } return(RedirectToAction(nameof(Index))); } } } catch (Exception ex) { return(View()); } }
// GET: Spells/Create public ActionResult Create() { var spellTypes = GetSpellType(); var viewModel = new SpellFormViewModel() { SpellTypeOptions = spellTypes }; return(View(viewModel)); }