示例#1
0
 internal List <TipoPergunta> Obter()
 {
     try
     {
         using (surveyprofContext contexto = new surveyprofContext())
         {
             var dados = (from xx in contexto.TipoPergunta
                          orderby xx descending
                          select xx).ToList();
             return(dados);
         }
     }
     catch
     {
         return(null);
     }
 }
示例#2
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);
            }
        }
示例#3
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);
     }
 }
示例#4
0
        internal TipoPergunta Obter(int id, bool lazyloading)
        {
            try
            {
                using (surveyprofContext contexto = new surveyprofContext())
                {
                    if (lazyloading)
                    {
                        var dados = contexto.TipoPergunta.Where(x => x.Id == id).FirstOrDefault();
                        return(dados);
                    }
                    else
                    {
                        var abc = contexto.TipoPergunta.Where(aa => aa.Id == id).Include("IdPerguntaNavigation").FirstOrDefault();

                        return(abc);
                    }
                }
            }
            catch
            {
                return(null);
            }
        }