public async Task <List <FornecedorDTO> > GetFornecedores()
 {
     using (var context = new SSContext())
     {
         return(await context.Fornecedores.ToListAsync());
     }
 }
Exemple #2
0
 public async Task Create(FornecedorDTO fornecedor)
 {
     using (var context = new SSContext())
     {
         context.Fornecedor.Add(fornecedor);
         await context.SaveChangesAsync();
     }
 }
Exemple #3
0
 public async Task Create(UsuarioDTO usuario)
 {
     using (var context = new SSContext())
     {
         context.Usuarios.Add(usuario);
         await context.SaveChangesAsync();
     }
 }
Exemple #4
0
        public async Task <UsuarioDTO> Authenticate(string email, string password)
        {
            using (var ctx = new SSContext())
            {
                UsuarioDTO user = await ctx.Usuarios.FirstOrDefaultAsync(u => u.Email == email && u.Senha == password); //Tio Celo flw sobre o ConfigureAwait(false);

                if (user == null)
                {
                    throw new Exception("Email e/ou senha inválidos");
                }
                return(user);
            }
        }
Exemple #5
0
 public async Task Create(UsuarioDTO usuario)
 {
     try
     {
         using (var context = new SSContext())
         {
             context.Usuarios.Add(usuario);
             await context.SaveChangesAsync();
         }
     }
     catch (Exception ex)
     {
         if (ex.InnerException != null && ex.InnerException.InnerException.Message.Contains("EMAIL"))
         {
             throw new Exception("O email já foi cadastrado.");
         }
         //Logar
         //File.WriteAllText(BLABLABLA);
         throw new Exception("Erro no banco de dados");
     }
 }