Beispiel #1
0
        public async Task <IActionResult> Create([Bind("Id,Nome,Email,Telefone")] Professor professor)
        {
            if (!ModelState.IsValid)
            {
                return(View(professor));
            }

            await _contextProfessor.InsertAsync(professor);

            return(RedirectToAction(nameof(Index)));
        }
        [ValidateAntiForgeryToken] //To prevent cross-site request forgery
        public async Task <IActionResult> Create(Professor professor)
        {
            if (!ModelState.IsValid)
            {
                var departments = await _departmentService.FindAllAsync();

                var viewModel = new ProfessorFormViewModel {
                    professor = professor, Departments = departments
                };
                return(View(viewModel));
            }
            await _professorService.InsertAsync(professor);

            return(RedirectToAction(nameof(Index)));
        }
        public async Task <IActionResult> Create(Professor professor)
        {
            if (!ModelState.IsValid)
            {
                var cursos = await _cursoService.FindAllAsync();

                var viewModel = new ProfessorFormViewModel {
                    Professor = professor, Cursos = cursos
                };
                return(View(viewModel));
            }

            await _ProfessorService.InsertAsync(professor);

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