示例#1
0
        internal int Excluir(short id)
        {
            try
            {
                using (surveyprofContext contexto = new surveyprofContext())
                {
                    var tipoPergunta = (from tp in contexto.TipoPergunta
                                        where tp.Id == id
                                        select tp).FirstOrDefault();

                    var dados = contexto.Pergunta.Where(x => x.TipoId == id).ToList();
                    if (dados.Count() > 0)
                    {
                        foreach (var y in dados)
                        {
                            if (contexto.Alternativa.Where(aa => aa.PerguntaId == y.Id).ToList().Count() > 0)
                            {
                                return(15);
                            }
                            else if (contexto.Resposta.Where(rr => rr.PerguntaId == y.Id).ToList().Count() > 0)
                            {
                                return(15);
                            }
                            else
                            {
                                contexto.Pergunta.Remove(y);
                            }
                        }

                        contexto.TipoPergunta.Remove(tipoPergunta);
                    }
                    else
                    {
                        contexto.TipoPergunta.Remove(tipoPergunta);
                    }

                    return(contexto.SaveChanges());
                }
            }
            catch
            {
                return(-1);
            }
        }
示例#2
0
 internal int Gravar(TipoPergunta tp)
 {
     try
     {
         using (surveyprofContext contexto = new surveyprofContext())
         {
             if (tp.Id > 0)
             {
                 contexto.TipoPergunta.Attach(tp);
                 contexto.Entry(tp).State = EntityState.Modified;
             }
             else
             {
                 contexto.TipoPergunta.Add(tp);
             }
             return(contexto.SaveChanges());
         }
     }
     catch
     {
         return(-1);
     }
 }