Beispiel #1
0
        public static List <Pedido> GetTodosPedidos()
        {
            using var db = new MercadoDb();

            return(db.Pedidos.Include(a => a.PedidoDetalhamentos)
                   .ThenInclude(a => a.Produto)
                   .Include(a => a.TipoPagamento)
                   .Include(a => a.Cliente)
                   .OrderBy(a => a.DataPedido)
                   .ToList());
        }
Beispiel #2
0
 public static List <Cliente> GetTodosClientes()
 {
     try
     {
         using var db = new MercadoDb();
         return(db.Clientes.OrderBy(a => a.Nome).ToList());
     }
     catch (Exception)
     {
         throw;
     }
 }
Beispiel #3
0
 public static List <Produto> GetProdutoComNome(string produtoName)
 {
     try
     {
         using var db = new MercadoDb();
         return(db.Produtos.Where(a => a.Nome.Contains(produtoName)).OrderBy(a => a.Nome).ToList());
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
Beispiel #4
0
 public static List <Produto> GetTodosProdutos()
 {
     try
     {
         using var db = new MercadoDb();
         return(db.Produtos.OrderBy(a => a.Nome).ToList());
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
Beispiel #5
0
 public static TipoPagamento GetTipoPagamentoComId(int tipoPagamentoId)
 {
     try
     {
         using var db = new MercadoDb();
         return(db.TipoPagamentos.FirstOrDefault(a => a.TipoPagamentoId == tipoPagamentoId));
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
Beispiel #6
0
 public static List <Cliente> GetClienteComNome(string nome)
 {
     try
     {
         using var db = new MercadoDb();
         return(db.Clientes.Where(a => a.Nome.Contains(nome)).ToList());
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
Beispiel #7
0
        public static List <Pedido> GetPedidosPorNomeCliente(string nomeCliente)
        {
            using var db = new MercadoDb();

            return(db.Pedidos.Include(a => a.PedidoDetalhamentos)
                   .ThenInclude(a => a.Produto)
                   .Include(a => a.TipoPagamento)
                   .Include(a => a.Cliente)
                   .OrderBy(a => a.DataPedido)
                   .Where(a => a.Cliente.Nome.Contains(nomeCliente))
                   .ToList());
        }
Beispiel #8
0
        public static Cliente GetClienteComId(int id)
        {
            try
            {
                using var db = new MercadoDb();

                return(db.Clientes.FirstOrDefault(a => a.ClienteId == id));
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        public static ClienteEndereco GetClienteEnderecoComClienteEnderecoId(int clienteEnderecoId)
        {
            try
            {
                using var db = new MercadoDb();

                return(db.ClienteEnderecos.FirstOrDefault(a => a.ClienteEnderecoId == clienteEnderecoId));
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        public static List <ClienteEndereco> GetClienteEnderecoComClienteId(int clienteId)
        {
            try
            {
                using var db = new MercadoDb();

                return(db.Clientes.Where(a => a.ClienteId == clienteId).SelectMany(a => a.ClienteEnderecos).ToList());
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Beispiel #11
0
        public static Pedido GetPedidoComId(int id)
        {
            try
            {
                using var db = new MercadoDb();

                return(db.Pedidos.FirstOrDefault(a => a.PedidoId == id));
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Beispiel #12
0
        public static void DeleteCliente(Cliente cliente)
        {
            try
            {
                using var db = new MercadoDb();

                db.Remove <Cliente>(cliente);
                db.SaveChanges();
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        public static void DeleteClienteEndereco(List <ClienteEndereco> clienteEndereco)
        {
            try
            {
                using var db = new MercadoDb();

                db.ClienteEnderecos.RemoveRange(clienteEndereco);
                db.SaveChanges();
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Beispiel #14
0
        public static void DeleteProduto(Produto produto)
        {
            try
            {
                using var db = new MercadoDb();

                db.Remove <Produto>(produto);
                db.SaveChanges();
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Beispiel #15
0
        public static void InsertProduto(Produto produto)
        {
            try
            {
                using var db = new MercadoDb();

                db.Add <Produto>(produto);
                db.SaveChanges();
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Beispiel #16
0
        public static void InsertCliente(Cliente cliente)
        {
            try
            {
                using var db = new MercadoDb();

                db.Add <Cliente>(cliente);
                db.SaveChanges();
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        public static void UpdateClienteEndereco(ClienteEndereco clienteEndereco)
        {
            try
            {
                using var db = new MercadoDb();

                db.Update <ClienteEndereco>(clienteEndereco);
                db.SaveChanges();
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Beispiel #18
0
        public static void DeletePedido(Pedido pedido)
        {
            try
            {
                using var db = new MercadoDb();

                db.Remove <Pedido>(pedido);
                db.SaveChanges();
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        public static List <ClienteEndereco> GetTodosClienteEnderecos()
        {
            try
            {
                using var db = new MercadoDb();

                var result = db.ClienteEnderecos.ToList();

                return(result);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        public static List <ClienteEndereco> GetClienteEnderecoComNomeCliente(string nomeCliente)
        {
            try
            {
                using var db = new MercadoDb();

                var clientes = db.Clientes.Where(a => a.Nome.Contains(nomeCliente)).ToList();

                return(clientes.SelectMany(a => a.ClienteEnderecos).ToList());
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Beispiel #21
0
        public static Pedido InsertPedido(Pedido pedido)
        {
            try
            {
                using var db = new MercadoDb();

                db.Add <Pedido>(pedido);
                db.SaveChanges();

                return(pedido);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        public static bool InsertPedidoDetalhamento(List <PedidoDetalhamento> pedidoDetalhamento)
        {
            try
            {
                using var db = new MercadoDb();

                db.AddRange(pedidoDetalhamento);
                db.SaveChanges();

                return(true);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }