Example #1
0
        public async Task <IActionResult> Create([Bind("Nome,RegistroCbj,DataVencimentoCBJ,Telefone1,Telefone2,Email,CPF,Observacoes,DataNascimento,Numero,OrgaoExpedidor,Rua,NumeroResidencia,Bairro,Cidade,Estado,CEP,Faixa")] Aluno aluno)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    _context.Add(aluno);
                    await _context.SaveChangesAsync();

                    return(RedirectToAction(nameof(Index)));
                }
            }
            catch (DbUpdateException)
            {
                ModelState.AddModelError("", "Não foi possivel salvar. " +
                                         "Tente novamente, se o problema persistir" +
                                         "procure o administrador do sistema.");
            }
            return(View(aluno));
        }
Example #2
0
        public async Task <IActionResult> Create([Bind("Id,Nome,CNPJ,Telefone1,Telefone2,Rua,Numero,Bairro,Cidade,Estado,CEP")] Entidade entidade, string[] selectedProfessores)
        {
            if (selectedProfessores != null)
            {
                entidade.ProfessorEntidade = new List <ProfessorEntidade>();
                foreach (var professor in selectedProfessores)
                {
                    var professorToAdd = new ProfessorEntidade {
                        EntidadeID = entidade.Id, ProfessorID = int.Parse(professor)
                    };
                    entidade.ProfessorEntidade.Add(professorToAdd);
                }
            }
            if (ModelState.IsValid)
            {
                _context.Add(entidade);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            PopulateAssignedProfessorData(entidade);
            return(View(entidade));
        }