Пример #1
0
        public async Task <IActionResult> Create([Bind("AlunoID,Nome,Sobrenome,Data")] Aluno aluno)
        {
            /*if (ModelState.IsValid)
             * {
             *  _context.Add(aluno);
             *  await _context.SaveChangesAsync();
             *  return RedirectToAction(nameof(Index));
             * }
             * return View(aluno);*/

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

                    return(RedirectToAction(nameof(Index)));
                }
            }
            catch (DbUpdateException e)
            {
                ModelState.AddModelError("", "Não foi possível salvar. Tente novamente mais tarde.");
            }

            return(View(aluno));
        }
Пример #2
0
        public async Task <IActionResult> Create([Bind("Nome,Sobrenome,Contratacao, Escritorio")] Instrutor instrutor, string[] cursosSelecionados)
        {
            if (cursosSelecionados != null)
            {
                instrutor.CursosInstrutor = new List <CursoInstrutor>();
                foreach (var curso in cursosSelecionados)
                {
                    var cursoToAdd = new CursoInstrutor {
                        InstrutorID = instrutor.InstrutorID, CursoID = int.Parse(curso)
                    };
                    instrutor.CursosInstrutor.Add(cursoToAdd);
                }
            }

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

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

            CarregarCursosAtribuidos(instrutor);

            return(View(instrutor));
        }
Пример #3
0
        public async Task <IActionResult> Create([Bind("AlunoID,Nome,Sobrenome,Data")] Aluno aluno)
        {
            if (ModelState.IsValid)
            {
                _context.Add(aluno);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(aluno));
        }
Пример #4
0
        public async Task <IActionResult> Create([Bind("InstrutorID,Nome,Sobrenome,Contratacao")] Instrutor instrutor)
        {
            if (ModelState.IsValid)
            {
                _context.Add(instrutor);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(instrutor));
        }
Пример #5
0
        public async Task <IActionResult> Create([Bind("CursoID,Titulo,Credito,DepartamentoID")] Curso curso)
        {
            if (ModelState.IsValid)
            {
                _context.Add(curso);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["DepartamentoID"] = new SelectList(_context.Departamento, "DepartamentoID", "DepartamentoID", curso.DepartamentoID);
            return(View(curso));
        }
Пример #6
0
        // To protect from overposting attacks, enable the specific properties you want to bind to, for
        // more details, see https://aka.ms/RazorPagesCRUD.
        public async Task <IActionResult> OnPostAsync()
        {
            if (!ModelState.IsValid)
            {
                return(Page());
            }

            _context.Attach(Aluno).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!AlunoExists(Aluno.AlunoID))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(RedirectToPage("./Index"));
        }
Пример #7
0
        // To protect from overposting attacks, enable the specific properties you want to bind to, for
        // more details, see https://aka.ms/RazorPagesCRUD.
        public async Task <IActionResult> OnPostAsync()
        {
            if (!ModelState.IsValid)
            {
                return(Page());
            }

            _context.Aluno.Add(Aluno);
            await _context.SaveChangesAsync();

            return(RedirectToPage("./Index"));
        }
Пример #8
0
        public async Task <IActionResult> OnPostAsync(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            Aluno = await _context.Aluno.FindAsync(id);

            if (Aluno != null)
            {
                _context.Aluno.Remove(Aluno);
                await _context.SaveChangesAsync();
            }

            return(RedirectToPage("./Index"));
        }