public IHttpActionResult GetSobreviventes(string hashId, string login)
        {
            Sobrevivente sobrevivente = null;

            if (hashId == null && login == null || hashId.Equals(string.Empty) && login.Equals(string.Empty))
            {
                return(NotFound());
            }
            if (hashId != null && hashId.Equals(string.Empty) || hashId.Equals("0") && login != null)
            {
                sobrevivente = _db.Sobreviventes
                               .Where(s => s.LoginName == login).FirstOrDefault <Sobrevivente>();
            }
            else
            {
                sobrevivente = _db.Sobreviventes
                               .Where(s => s.LoginName == login && s.HashSeguranca == hashId).FirstOrDefault <Sobrevivente>();
            }

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

            return(Ok(sobrevivente));
        }
        private Sobrevivente ObterDadosLogin(string hashId)
        {
            Sobrevivente sobrevivente = _db.Sobreviventes
                                        .Where(s => s.HashSeguranca == hashId.ToString()).FirstOrDefault <Sobrevivente>();

            return(sobrevivente);
        }
        public IHttpActionResult GetSobreviventes(string nome)
        {
            Sobrevivente sobrevivente = _db.Sobreviventes
                                        .Where(s => s.HashSeguranca == nome).FirstOrDefault <Sobrevivente>();

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

            return(Ok(sobrevivente));
        }
        public HttpResponseMessage PutRecursos(int id, [FromBody] object rec, int idUser, int qtd)
        {
            Recursos newRecurso;

            if (!ModelState.IsValid)
            {
                return(Request.CreateErrorResponse(HttpStatusCode.NotImplemented, " Recurso não implementado"));
            }

            Recursos     recurso      = _db.Recursos.SingleOrDefault(r => r.Id == id);
            Sobrevivente sobrevivente = _db.Sobreviventes.SingleOrDefault(r => r.Id == idUser);

            if (recurso == null || sobrevivente == null)
            {
                return(Request.CreateErrorResponse(HttpStatusCode.NotFound, " Dados não encontrados"));
            }

            newRecurso = JsonConvert.DeserializeObject <Recursos>(Convert.ToString(rec));

            if (recurso.Quantidade == newRecurso.Quantidade)
            {
                recurso.Observacao = newRecurso.Observacao;
                recurso.Quantidade = newRecurso.Quantidade;
                recurso.Descricao  = newRecurso.Descricao;
            }
            else
            {
                recurso.Observacao = newRecurso.Observacao;
                recurso.Quantidade = newRecurso.Quantidade;
                recurso.Descricao  = newRecurso.Descricao;

                Inventario inv = new Inventario();
                inv.RecursoId      = recurso.Id;
                inv.SobreviventeId = sobrevivente.Id;
                inv.QtdRetirada    = qtd;
                _db.Inventario.Add(inv);
            }

            _db.Entry(recurso).State = EntityState.Modified;

            try
            {
                _db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                throw;
            }

            return(Request.CreateResponse <Recursos>(HttpStatusCode.OK, recurso));
        }
        public IHttpActionResult DeleteSobreviventes(int id)
        {
            Sobrevivente sobreviventes = _db.Sobreviventes.Find(id);

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

            _db.Sobreviventes.Remove(sobreviventes);
            _db.SaveChanges();

            return(Ok(sobreviventes));
        }
        public HttpResponseMessage PostSobreviventes([FromBody] Sobrevivente sobreviventes)
        {
            if (!ModelState.IsValid)
            {
                return(Request.CreateErrorResponse(HttpStatusCode.NotImplemented, " Recurso não encontado"));
            }
            if (sobreviventes.Genero == null)
            {
                return(Request.CreateErrorResponse(HttpStatusCode.NotAcceptable, " Valores não aceitaveis"));
            }
            if (sobreviventes.HashSeguranca == null || sobreviventes.HashSeguranca.Equals(""))
            {
                Random randHash = new Random();
                sobreviventes.HashSeguranca = randHash.Next().ToString();
            }
            else
            {
                //sobreviventes.HashSeguranca = HashPassword(sobreviventes.HashSeguranca);
            }
            _db.Sobreviventes.Add(sobreviventes);
            _db.SaveChanges();

            return(Request.CreateResponse <Sobrevivente>(HttpStatusCode.OK, sobreviventes));
        }