public async Task <IActionResult> Create
            ([Bind("EmprestimoID,DataEmprestimo,DataDevolucaoPrevista,AmigoID")] Emprestimo emprestimo
            , string[] selectedJogos)
        {
            if (selectedJogos != null)
            {
                emprestimo.EmprestimoJogo = new List <EmprestimoJogo>();

                foreach (var id in selectedJogos)
                {
                    emprestimo.EmprestimoJogo.Add(new EmprestimoJogo
                    {
                        Emprestimo = emprestimo,
                        JogoID     = Convert.ToInt32(id)
                    });
                }
            }

            if (ModelState.IsValid)
            {
                _context.Add(emprestimo);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["Amigo"] = new SelectList(_context.Amigos, "AmigoID", "Nome", emprestimo.AmigoID);
            ViewBag.Jogos     = new Listagens(_context).JogosCheckBox();

            return(View(emprestimo));
        }
Пример #2
0
        public async Task <IActionResult> Create([Bind("AmigoID,Nome,Telefone,Email")] Amigo amigo)
        {
            if (ModelState.IsValid)
            {
                _context.Add(amigo);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(amigo));
        }
        public async Task <IActionResult> Create([Bind("JogoID,Titulo,Quantidade,Foto")] Jogo jogo, List <IFormFile> files)
        {
            if (ModelState.IsValid)
            {
                _context.Add(jogo);
                await _context.SaveChangesAsync();

                jogo.Foto = await RealizarUploadImagens(files, jogo.JogoID);

                _context.Update(jogo);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(jogo));
        }