예제 #1
0
        public void CadastrarUsuario(CadastrarUsuarioViewModel usuario)
        {
            Usuarios usuarioTemp;

            // Defini os valores do objeto Usuario
            usuarioTemp = new Usuarios
            {
                Nome              = usuario.Nome,
                Email             = usuario.Email,
                Senha             = usuario.Senha,
                DataCriacao       = DateTime.Now,
                Telefone          = usuario.Telefone,
                IdTipoUsuario     = usuario.IdTipoUsuario,
                IdEstabelecimento = usuario.IdEstabelecimento
            };


            usuarioTemp = new Usuarios
            {
                Nome              = usuario.Nome,
                Email             = usuario.Email,
                Senha             = usuario.Senha,
                Telefone          = usuario.Telefone,
                DataCriacao       = DateTime.Now,
                IdTipoUsuario     = usuario.IdTipoUsuario,
                IdEstabelecimento = usuario.IdEstabelecimento
            };


            using (DesafioPluftContext ctx = new DesafioPluftContext())
            {
                ctx.Usuarios.Add(usuarioTemp);
                ctx.SaveChanges();
            }
        }
예제 #2
0
 public List <Clientes> ListarTodos()
 {
     using (DesafioPluftContext ctx = new DesafioPluftContext())
     {
         return(ctx.Clientes.Include(x => x.IdUsuarioNavigation).ToList());
     }
 }
예제 #3
0
 public Usuarios BuscarPorId(int Id)
 {
     using (DesafioPluftContext ctx = new DesafioPluftContext())
     {
         return(ctx.Usuarios.Find(Id));
     }
 }
예제 #4
0
 public List <Estabelecimentos> ListarTodas()
 {
     using (DesafioPluftContext ctx = new DesafioPluftContext())
     {
         return(ctx.Estabelecimentos.Include(x => x.IdTipoEstabelecNavigation).ToList());
     }
 }
예제 #5
0
 public List <ProdutoAgendamentos> ListarProdutoComAgendamento()
 {
     using (DesafioPluftContext ctx = new DesafioPluftContext())
     {
         return(ctx.ProdutoAgendamentos.Include(x => x.IdProdutosNavigation).Include(x => x.IdAgendamentoNavigation).ToList());
     }
 }
예제 #6
0
 public Estabelecimentos BuscarEstabelecimentosPorId(int IdEstabelecimento)
 {
     using (DesafioPluftContext ctx = new DesafioPluftContext())
     {
         return(ctx.Estabelecimentos.Find(IdEstabelecimento));
     }
 }
예제 #7
0
        public void AtualizarDados(Produtos produtoCadastrado, Produtos produtoNovo)
        {
            if (produtoNovo.Preco != 0)
            {
                produtoCadastrado.Preco = produtoNovo.Preco;
            }

            if (produtoNovo.Titulo != null)
            {
                produtoCadastrado.Titulo = produtoNovo.Titulo;
            }
            if (produtoNovo.QtdEstoque != 0)
            {
                produtoCadastrado.QtdEstoque = produtoNovo.QtdEstoque;
            }
            if (produtoNovo.Descricao != null)
            {
                produtoCadastrado.Descricao = produtoNovo.Descricao;
            }

            using (DesafioPluftContext ctx = new DesafioPluftContext())
            {
                ctx.Produtos.Update(produtoCadastrado);
                ctx.SaveChanges();
            }
        }
예제 #8
0
 public Clientes BuscarClientePorIdUsuario(int idUsuario)
 {
     using (DesafioPluftContext ctx = new DesafioPluftContext())
     {
         return(ctx.Clientes.Find(idUsuario));
     }
 }
예제 #9
0
 public Produtos BuscarPorId(int id)
 {
     using (DesafioPluftContext ctx = new DesafioPluftContext())
     {
         return(ctx.Produtos.Find(id));
     }
 }
예제 #10
0
 public List <Produtos> ListarTodos()
 {
     using (DesafioPluftContext ctx = new DesafioPluftContext())
     {
         return(ctx.Produtos.Include(x => x.IdEstabelecNavigation).ToList());
     }
 }
예제 #11
0
 public List <Lojistas> ListarLojistas()
 {
     using (DesafioPluftContext ctx = new DesafioPluftContext())
     {
         return(ctx.Lojistas.Include(x => x.IdUsuarioNavigation).Include(y => y.IdUsuarioNavigation.IdEstabelecimentoNavigation).Where(x => x.IdUsuarioNavigation.IdTipoUsuario == 3).ToList());
     }
 }
예제 #12
0
 public Lojistas BuscarPorLojistaPorIdUsuario(int Idusuario)
 {
     using (DesafioPluftContext ctx = new DesafioPluftContext())
     {
         return(ctx.Lojistas.Find(Idusuario));
     }
 }
예제 #13
0
 public Agendamentos BuscarPorId(int id)
 {
     using (DesafioPluftContext ctx = new DesafioPluftContext())
     {
         return(ctx.Agendamentos.Find(id));
     }
 }
예제 #14
0
 public void CadastrarDados(Estabelecimentos estabelecimnetos)
 {
     using (DesafioPluftContext ctx = new DesafioPluftContext())
     {
         ctx.Estabelecimentos.Add(estabelecimnetos);
         ctx.SaveChanges();
     }
 }
예제 #15
0
 public void CadastrarProduto(Produtos produto)
 {
     using (DesafioPluftContext ctx = new DesafioPluftContext())
     {
         ctx.Produtos.Add(produto);
         ctx.SaveChanges();
     }
 }
예제 #16
0
 public Usuarios BuscarPorEmail(LoginViewModel login)
 {
     using (DesafioPluftContext ctx = new DesafioPluftContext())
     {
         // terá tanto os usuários, quanto os tipos deles.
         // Retorna um usuário que coincida com o e-mail e senha.
         return(ctx.Usuarios.Include(x => x.IdTipoUsuarioNavigation).FirstOrDefault(x => x.Email == login.Email));
     }
 }
예제 #17
0
        public List <Agendamentos> ListarporIdLojista(int idLojista)
        {
            using (DesafioPluftContext ctx = new DesafioPluftContext())
            {
                Lojistas lojistaBuscado = ctx.Lojistas.Where(p => p.IdUsuario == idLojista).FirstOrDefault();

                return(ctx.Agendamentos.Include(x => x.IdLojistaNavigation.IdUsuarioNavigation)
                       .Include(x => x.ProdutoAgendamentos)
                       .Include(c => c.IdClienteNavigation.IdUsuarioNavigation)
                       .Where(x => x.IdLojista == lojistaBuscado.Id).ToList());
            }
        }
예제 #18
0
        public void AtualizarDados(Estabelecimentos novoEstabelecimento, Estabelecimentos estabelecimentoCadastrado)
        {
            estabelecimentoCadastrado.Endereco = novoEstabelecimento.Endereco ?? estabelecimentoCadastrado.Endereco;

            estabelecimentoCadastrado.HorarioFuncionamento = novoEstabelecimento.HorarioFuncionamento ?? estabelecimentoCadastrado.HorarioFuncionamento;

            using (DesafioPluftContext ctx = new DesafioPluftContext())
            {
                ctx.Estabelecimentos.Update(novoEstabelecimento);
                ctx.SaveChanges();
            }
        }
예제 #19
0
        public void CadastrarCliente(ClienteViewModel clienteModel)
        {
            using (DesafioPluftContext ctx = new DesafioPluftContext())
            {
                CadastrarUsuario(clienteModel.UsuarioViewModel);

                Usuarios usuario = ctx.Usuarios.Last();
                usuario.IdTipoUsuario          = 2;
                clienteModel.Cliente.IdUsuario = usuario.Id;
                ctx.Clientes.Add(clienteModel.Cliente);
                ctx.SaveChanges();
            }
        }
예제 #20
0
 public List <Agendamentos> ListarTodos()
 {
     using (DesafioPluftContext ctx = new DesafioPluftContext())
     {
         return(ctx.Agendamentos
                .Include(x => x.IdLojistaNavigation.IdUsuarioNavigation)
                .Include(x => x.IdClienteNavigation)
                .Include(x => x.IdStatusNavigation)
                .Include(x => x.ProdutoAgendamentos)
                .Include(c => c.IdClienteNavigation.IdUsuarioNavigation)
                .ToList());
     }
 }
예제 #21
0
        public List <Agendamentos> ListarporIdCliente(int idCliente)
        {
            using (DesafioPluftContext ctx = new DesafioPluftContext())
            {
                Clientes clienteBuscado = ctx.Clientes.Where(p => p.IdUsuario == idCliente).FirstOrDefault();

                return(ctx.Agendamentos.Include(x => x.IdClienteNavigation.IdUsuarioNavigation)
                       .Include(x => x.IdStatusNavigation)
                       .Include(x => x.ProdutoAgendamentos)
                       .Include(x => x.IdClienteNavigation)
                       .Include(c => c.IdClienteNavigation.IdUsuarioNavigation)
                       .Where(x => x.IdCliente == clienteBuscado.Id).ToList());
            }
        }
예제 #22
0
        public void CadastrarLojista(LojistaViewModel lojistaModel)
        {
            using (DesafioPluftContext ctx = new DesafioPluftContext())
            {
                CadastrarUsuario(lojistaModel.UsuarioViewModel);

                Usuarios usuario = ctx.Usuarios.Last();
                usuario.IdTipoUsuario          = 3;
                lojistaModel.Lojista.IdUsuario = usuario.Id;
                ctx.Lojistas.Add(lojistaModel.Lojista);

                // Salva as alterações no BD.
                ctx.SaveChanges();
            }
        }
예제 #23
0
        public void Atualizar(Agendamentos novoAgendamento, Agendamentos agendamentoCadastrado)
        {
            agendamentoCadastrado.DataAgendamento = (novoAgendamento.DataAgendamento != agendamentoCadastrado.DataAgendamento ? novoAgendamento.DataAgendamento : agendamentoCadastrado.DataAgendamento);

            if (novoAgendamento.DataAgendamento != null)
            {
                agendamentoCadastrado.DataAgendamento = novoAgendamento.DataAgendamento;
            }

            if (novoAgendamento.IdStatus != 0)
            {
                agendamentoCadastrado.IdStatus = novoAgendamento.IdStatus;
            }

            using (DesafioPluftContext ctx = new DesafioPluftContext())
            {
                ctx.Agendamentos.Update(agendamentoCadastrado);
                ctx.SaveChanges();
            }
        }
예제 #24
0
        public void Cadastrar(Agendamentos agendamento, List <int> produtos)
        {
            agendamento.DataCriacao = DateTime.Now;



            using (DesafioPluftContext ctx = new DesafioPluftContext())
            {
                ctx.Agendamentos.Add(agendamento);
                ctx.SaveChanges();
                foreach (var item in produtos)
                {
                    ctx.ProdutoAgendamentos.Add(new ProdutoAgendamentos()
                    {
                        IdAgendamento = agendamento.Id,
                        IdProdutos    = item
                    });
                }
                ctx.SaveChanges();
            }
        }