예제 #1
0
 public void InsereAdmin(Admin admin)
 {
     if (vestContext.Admins.Where(x => x.Email == admin.Email || x.Login == admin.Login).FirstOrDefault() != null)
     {
         throw new InvalidOperationException("Email ou login já persistido");
     }
     else
     {
         vestContext.Admins.Add(admin);
         vestContext.SaveChanges();
     }
 }
예제 #2
0
        /// <summary>
        /// Insere com uma validação inicial
        /// </summary>
        /// <param name="curso"></param>
        public void InserirCurso(Curso curso)
        {
            var retorno = from c in vestContext.Cursos
                          where c.Descricao == curso.Descricao
                          select c;

            if (retorno.Count() > 0)
            {
                throw new InvalidOperationException("Curso com a mesma descrição");
            }
            else
            {
                vestContext.Cursos.Add(curso);
                vestContext.SaveChanges();
            }
        }
예제 #3
0
        public void RealizaInscricao(Candidato candidato)
        {
            var retorno = from a in Candidatos
                          where a.Cpf == candidato.Cpf || a.Email == candidato.Email
                          select a;

            if (retorno.Count() > 0)
            {
                throw new InvalidOperationException("CPF ou e-mail já inscrito");
            }
            else
            {
                vestContext.Candidatos.Add(candidato);
                vestContext.SaveChanges();
            }
        }
        public void RealizaInscricao(Candidato candidato)
        {
            var retorno = from a in Candidatos
                          where a.Cpf == candidato.Cpf || a.Email == candidato.Email
                          select a;

            if (retorno.Count() > 0)
            {
                throw new InvalidOperationException("CPF ou e-mail já inscrito");
            }
            else
            {
                try
                {
                    vestContext.Candidatos.Add(candidato);
                    vestContext.SaveChanges();
                }
                catch (DbEntityValidationException ex)
                {
                    //Estoura as validaçoes que foram feitas no model
                    StringBuilder msgErro = new StringBuilder();
                    var           erros   = vestContext.GetValidationErrors();
                    //já informa quais campos que são do tipo [Required]
                    //e que não foram preenchidos
                    foreach (var erro in erros)
                    {
                        foreach (var detalheErro in erro.ValidationErrors)
                        {
                            msgErro.Append(detalheErro.ErrorMessage);
                            msgErro.Append('\n');
                        }
                    }
                    vestContext.Entry(candidato).State = System.Data.Entity.EntityState.Detached;
                    throw new InvalidOperationException(msgErro.ToString());
                }
            }
        }
        public void Inserir(Vestibular vestibular)
        {
            var retorno = from v in Vestibulares
                          where v.Descricao == vestibular.Descricao
                          select v;

            if (retorno.Count() > 0)
            {
                throw new InvalidOperationException("Vestibular com a mesma descrição");
            }
            else
            {
                try
                {
                    vestContext.Vestibulares.Add(vestibular);
                    vestContext.SaveChanges();
                }
                catch (DbEntityValidationException ex)
                {
                    StringBuilder msgErro = new StringBuilder();
                    var           erros   = vestContext.GetValidationErrors();
                    //já informa quais campos que são do tipo [Required]
                    //e que não foram preenchidos
                    foreach (var erro in erros)
                    {
                        foreach (var detalheErro in erro.ValidationErrors)
                        {
                            msgErro.Append(detalheErro.ErrorMessage);
                            msgErro.Append('\n');
                        }
                    }
                    vestContext.Entry(vestibular).State = System.Data.Entity.EntityState.Detached;
                    throw new InvalidOperationException(msgErro.ToString());
                }
            }
        }