Beispiel #1
0
        public void ManterAnuncio(Anuncio _anuncio)
        {
            try
            {
                using (var contexto = new Context.EcommerceContext())
                {
                    if (_anuncio.ID == 0)
                    {
                        contexto.Anuncio.Add(new Anuncio()
                        {
                            Valor         = _anuncio.Valor,
                            Descricao     = _anuncio.Descricao,
                            TituloAnuncio = _anuncio.TituloAnuncio,
                            UsuarioId     = _anuncio.Usuario.ID
                        });
                    }
                    else
                    {
                        contexto.Anuncio.Update(_anuncio);
                    }

                    contexto.SaveChanges();
                }
            }
            catch (Exception Ex)
            {
                throw new Exception("Não foi possível executar o comando no banco de Dados");
            }
        }
Beispiel #2
0
 private Usuario BuscaUsuario(Usuario _usuario)
 {
     try
     {
         using (var contexto = new Context.EcommerceContext())
         {
             if (String.IsNullOrEmpty(_usuario.Username))
             {
                 return((from us in contexto.Usuario
                         where us.Email == _usuario.Email
                         select us).FirstOrDefault());
             }
             else if (String.IsNullOrEmpty(_usuario.Email))
             {
                 return((from us in contexto.Usuario
                         where us.Username == _usuario.Username
                         select us).FirstOrDefault());
             }
             else
             {
                 return(null);
             }
         }
     }
     catch (Exception ex)
     {
         throw new Exception("Não foi possível executar o comando no banco de Dados");
     }
 }
Beispiel #3
0
        public Usuario BuscaUsuario(int _id)
        {
            if (_id <= 0)
            {
                return(null);
            }

            try
            {
                Usuario usuario;
                using (var contexto = new Context.EcommerceContext())
                {
                    usuario = (from us in contexto.Usuario
                               where us.ID == _id
                               select us).FirstOrDefault();

                    usuario.Contato = new Contato().BuscaContato(usuario.ID);

                    usuario.Senha = null;
                }
                return(usuario);
            }
            catch (Exception ex)
            {
                throw new Exception("Não foi possível executar o comando no banco de Dados");
            }
        }
Beispiel #4
0
 public void ManterCadastro(Usuario _usuario)
 {
     using (var contexto = new Context.EcommerceContext())
     {
         contexto.Add(_usuario);
         contexto.SaveChanges();
     }
 }
Beispiel #5
0
 public Usuario RetornarUsuario(string _username)
 {
     using (var contexto = new Context.EcommerceContext())
     {
         return((from us in contexto.Usuario
                 where us.Username == _username
                 select us).FirstOrDefault());
     }
 }
Beispiel #6
0
 public void DeletarAnuncio(int _anuncioID)
 {
     try
     {
         using (var contexto = new Context.EcommerceContext())
         {
             contexto.Anuncio.Remove(contexto.Anuncio.Find(_anuncioID));
             contexto.SaveChanges();
         }
     }
     catch (Exception ex)
     {
         throw new Exception("Não foi possível executar o comando no banco de Dados");
     }
 }
Beispiel #7
0
 public List <Anuncio> BuscarTodosAnuncios()
 {
     try
     {
         using (var contexto = new Context.EcommerceContext())
         {
             return((from an in contexto.Anuncio
                     select an).ToList());
         }
     }
     catch (Exception e)
     {
         throw new Exception("Não foi possível executar o comando no banco de Dados ", e);
     }
 }
Beispiel #8
0
 public void ManterContato(Contato _contato)
 {
     try
     {
         using (var contexto = new Context.EcommerceContext())
         {
             contexto.Contato.Add(_contato);
             contexto.SaveChanges();
         }
     }
     catch (Exception ex)
     {
         throw new Exception("Não foi possível executar o comando no banco de Dados");
     }
 }
Beispiel #9
0
 public IEnumerable <Anuncio> BuscarTodosAnuncios(int idUsuario)
 {
     try
     {
         using (var contexto = new Context.EcommerceContext())
         {
             return((from an in contexto.Anuncio
                     where an.UsuarioId == idUsuario
                     select an).ToList());
         }
     }
     catch (Exception ex)
     {
         throw new Exception("Não foi possível executar o comando no banco de Dados");
     }
 }
Beispiel #10
0
 public Anuncio BuscarAnuncio(int idAnuncio)
 {
     try
     {
         using (var contexto = new Context.EcommerceContext())
         {
             return((from us in contexto.Anuncio
                     where us.ID == idAnuncio
                     select us).FirstOrDefault());
         }
     }
     catch (Exception e)
     {
         throw new Exception("Não foi possível executar o comando no banco de Dados", e);
     }
 }
Beispiel #11
0
 public void ManterCadastro(Usuario _usuario)
 {
     try
     {
         using (var contexto = new Context.EcommerceContext())
         {
             contexto.Usuario.Add(_usuario);
             contexto.SaveChanges();
         }
         if (_usuario.Contato != null)
         {
             _usuario.Contato.UsuarioId = _usuario.ID;
             _usuario.Contato.ManterContato(_usuario.Contato);
         }
     }
     catch (Exception ex)
     {
         throw new Exception("Não foi possível executar o comando no banco de Dados");
     }
 }
Beispiel #12
0
        public Contato BuscaContato(int _id)
        {
            if (_id <= 0)
            {
                return(null);
            }

            try
            {
                Contato contato;
                using (var contexto = new Context.EcommerceContext())
                {
                    contato = (from cont in contexto.Contato
                               where cont.UsuarioId == _id
                               select cont).FirstOrDefault();
                }

                return(contato);
            }
            catch (Exception ex)
            {
                throw new Exception("Não foi possível executar o comando no banco de Dados");
            }
        }