Esempio n. 1
0
        public static int Inserir(string nome)
        {
            int idNovo = -1;

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

            using (BDRpgEntities context = new BDRpgEntities())
            {
                Habilidades c = new Habilidades();
                c.Nome = nome;
                context.HabilidadesS.Add(c);
                context.SaveChanges();
                idNovo = c.Id;
            }
            return(idNovo);
        }
Esempio n. 2
0
        public static Habilidades Consultar(int id)
        {
            Habilidades habilidades = null;

            using (BDRpgEntities context = new BDRpgEntities())
            {
                var habilidades_ = from Habilidades h in context.HabilidadesS
                                   where h.Id == id
                                   select h;
                if (habilidades_.Count() > 0)
                {
                    habilidades = habilidades_.First();
                }
                else
                {
                    throw new RpgException(RpgExceptionCode.HABILIDADESIDINEXISTENTE, id.ToString());
                }
            }
            return(habilidades);
        }
Esempio n. 3
0
        public static void Atualizar(int id, string nome)
        {
            if (nome == null || nome.Length == 0)
            {
                throw new RpgException(RpgExceptionCode.HABILIDADESNOMEVAZIO, "");
            }

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