Ejemplo n.º 1
0
        public async Task <IActionResult> Edit(int id, [Bind("Id,CharacterId,WeaponId")] CharacterUse characterUse)
        {
            if (id != characterUse.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(characterUse);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!CharacterUseExists(characterUse.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            ViewData["CharacterId"] = new SelectList(_context.Characters, "Id", "Name", characterUse.CharacterId);
            ViewData["WeaponId"]    = new SelectList(_context.Weapons, "Id", "Model", characterUse.WeaponId);
            return(View(characterUse));
        }
Ejemplo n.º 2
0
        public async Task <IActionResult> Create(int?characId, int?weapId, [Bind("Id,CharacterId,WeaponId")] CharacterUse characterUse)
        {
            if (ModelState.IsValid)
            {
                _context.Add(characterUse);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["CharacterId"] = new SelectList(_context.Characters.Where(c => c.Id == characId), "Id", "Name", characterUse.CharacterId);
            ViewData["WeaponId"]    = new SelectList(_context.Weapons.Where(w => w.Id == weapId), "Id", "Model", characterUse.WeaponId);
            return(View(characterUse));
        }