public IHttpActionResult Put(ViewNivel dados)
        {
            if (dados == null)
            {
                return(BadRequest("Dados inválidos."));
            }

            using (ctx = new JogoMasterEntities())
            {
                var NivelAtual = ctx.Niveis.Where(t => t.Id == dados.Id)
                                 .FirstOrDefault <Nivel>();

                if (NivelAtual != null)
                {
                    NivelAtual.Nivel1 = dados.Nivel;
                    ctx.SaveChanges();
                }
                else
                {
                    return(NotFound());
                }
            }

            return(Ok());
        }
        private void ValidaNivel(ViewNivel dados)
        {
            Refute(string.IsNullOrEmpty(dados.Nivel), "Informe o Nível");
            Nivel nivel = null;

            using (ctx = new JogoMasterEntities())
            {
                nivel = ctx.Niveis.FirstOrDefault(x => x.Nivel1.ToLower() == dados.Nivel.ToLower());
                Refute(nivel != null, "Nível existente.");
            }
        }
        public IHttpActionResult Get(int id)
        {
            ViewNivel nivel = null;

            using (ctx = new JogoMasterEntities())
            {
                nivel = ctx.Niveis.Where(x => x.Id == id).Select(s => new ViewNivel()
                {
                    Id    = s.Id,
                    Nivel = s.Nivel1
                }).FirstOrDefault();
            }

            if (nivel == null)
            {
                return(NotFound());
            }

            return(Ok(nivel));
        }
        public IHttpActionResult Post(ViewNivel dados)
        {
            if (dados == null)
            {
                return(BadRequest("Dados inválidos."));
            }

            ValidaNivel(dados);

            using (ctx = new JogoMasterEntities())
            {
                ctx.Niveis.Add(new Nivel()
                {
                    Nivel1 = dados.Nivel
                });

                ctx.SaveChanges();
            }

            return(Ok());
        }