Пример #1
0
 public Usuarios GetUsuarioPorLogin(string login)
 {
     using (var db = new DBInvilliaDesafioContext())
     {
         return(db.Usuarios.Where(x => x.Username.Trim().Equals(login.Trim())).FirstOrDefault());
     }
 }
Пример #2
0
 public Emprestimos GetEmprestimoPorIdAmigoJogo(int idAmigo, int idJogo)
 {
     using (var db = new DBInvilliaDesafioContext())
     {
         return(db.Emprestimos.ToList().Where(x => x.IdAmigo == idAmigo && x.IdJogo == idJogo).FirstOrDefault());
     }
 }
Пример #3
0
 public IEnumerable <Usuarios> GetTodos()
 {
     using (var db = new DBInvilliaDesafioContext())
     {
         return(db.Usuarios.ToList());
     }
 }
Пример #4
0
 public IEnumerable <Amigos> GetAmigoPorId(int id)
 {
     using (var db = new DBInvilliaDesafioContext())
     {
         return(db.Amigos.ToList().Where(x => x.Id == id).ToList());
     }
 }
Пример #5
0
 public IEnumerable <Emprestimos> GetEmprestimoPorIdAmigo(int idAmigo)
 {
     using (var db = new DBInvilliaDesafioContext())
     {
         return(db.Emprestimos.ToList().Where(x => x.IdAmigo == idAmigo).ToList());
     }
 }
Пример #6
0
 public Usuarios Login([FromBody] Usuarios entity)
 {
     using (var db = new DBInvilliaDesafioContext())
     {
         return(db.Usuarios.ToList().Where(x => x.Username.Trim().Equals(entity.Username.Trim()) &&
                                           x.Usersenha.Trim().Equals(entity.Usersenha.Trim())).FirstOrDefault());
     }
 }
Пример #7
0
 public IEnumerable <Amigos> GetTodos()
 {
     using (var db = new DBInvilliaDesafioContext())
     {
         var x = db.Amigos.ToList();
         return(db.Amigos.ToList());
     }
 }
Пример #8
0
 public async Task Put([FromBody] Amigos entity)
 {
     try
     {
         using (var db = new DBInvilliaDesafioContext())
         {
             db.Entry(entity).State = EntityState.Modified;
             await db.SaveChangesAsync();
         }
     }
     catch (Exception ex)
     {
         throw new Exception(ex.StackTrace);
     }
 }
Пример #9
0
 public async Task Delete(int id)
 {
     try
     {
         Emprestimos entity;
         using (var db = new DBInvilliaDesafioContext())
         {
             entity = db.Emprestimos.ToList().Where(x => x.Id == id).FirstOrDefault();
             if (entity != null && entity.Id > 0)
             {
                 db.Entry(entity).State = EntityState.Deleted;
                 await db.SaveChangesAsync();
             }
         }
     }
     catch (Exception ex)
     {
         throw new Exception(ex.StackTrace);
     }
 }
Пример #10
0
        public IEnumerable <Jogos> GetJogosLivres(string livre)
        {
            using (var db = new DBInvilliaDesafioContext())
            {
                List <Emprestimos> lstEmprestimos = db.Emprestimos.ToList();
                List <Jogos>       lstJogosLivres = new List <Jogos>();

                foreach (var jogo in db.Jogos.ToList())
                {
                    if (lstEmprestimos != null)
                    {
                        if (lstEmprestimos.Any(x => x.IdJogo == jogo.Id))
                        {
                            continue;
                        }
                    }
                    lstJogosLivres.Add(jogo);
                }
                return(lstJogosLivres);
            }
        }
Пример #11
0
 public async Task Put([FromBody] EmprestimoOrigem entity)
 {
     try
     {
         Emprestimos emp = new Emprestimos();
         emp.Id                = entity.Id;
         emp.IdAmigo           = entity.IdAmigo;
         emp.IdJogo            = entity.IdJogo;
         emp.DataEmprestimo    = entity.DataEmprestimo;
         emp.IdAmigoNavigation = new Amigos();
         emp.IdJogoNavigation  = new Jogos();
         using (var db = new DBInvilliaDesafioContext())
         {
             //db.Entry(entity).State = EntityState.Modified;
             db.Entry(emp).State = EntityState.Modified;
             await db.SaveChangesAsync();
         }
     }
     catch (Exception ex)
     {
         throw new Exception(ex.StackTrace);
     }
 }