Exemple #1
0
        public static int Inserir(string nome)
        {
            int idNovo = -1;

            if (nome == null || nome.Length == 0)
            {
                throw new RpgException(RpgExceptionCode.PERSONAGEMNOMEVAZIO, "");
            }

            using (BDRpgEntities context = new BDRpgEntities())
            {
                Personagens c = new Personagens();
                c.Nome = nome;
                context.PersonagensS.Add(c);
                context.SaveChanges();
                idNovo = c.Id;
            }
            return(idNovo);
        }
Exemple #2
0
        public static Personagens Consultar(int id)
        {
            Personagens categoria = null;

            using (BDRpgEntities context = new BDRpgEntities())
            {
                var categoria_ = from Personagens p in context.PersonagensS
                                 where p.Id == id
                                 select p;
                if (categoria_.Count() > 0)
                {
                    categoria = categoria_.First();
                }
                else
                {
                    throw new RpgException(RpgExceptionCode.PERSONAGEMIDINEXISTENTE, id.ToString());
                }
            }
            return(categoria);
        }
Exemple #3
0
        public static void Atualizar(int id, string nome)
        {
            if (nome == null || nome.Length == 0)
            {
                throw new RpgException(RpgExceptionCode.PERSONAGEMNOMEVAZIO, "");
            }

            using (BDRpgEntities context = new BDRpgEntities())
            {
                var categoria_ = from Personagens c in context.PersonagensS
                                 where c.Id == id
                                 select c;
                if (categoria_.Count() > 0)
                {
                    Personagens c = categoria_.First();
                    c.Nome = nome;
                    context.SaveChanges();
                }
                else
                {
                    throw new RpgException(RpgExceptionCode.PERSONAGEMIDINEXISTENTE, id.ToString());
                }
            }
        }