Exemplo n.º 1
0
        public static async Task gerarMeuPedido()
        {
            UserDialogs.Instance.ShowLoading("Carregando...");
            try
            {
                var regraUsuario = UsuarioFactory.create();
                var usuarioAtual = regraUsuario.pegarAtual();

                var regraPedido = PedidoFactory.create();
                var pedidos     = await regraPedido.listar(usuarioAtual.Id);

                var pedidoListaPage = new PedidoListaPage
                {
                    Title   = "Meus Pedidos",
                    Pedidos = pedidos
                };
                pedidoListaPage.AoSelecionar += (sender, pedido) => {
                    var pedidoPage = new PedidoPage
                    {
                        Pedido = pedido
                    };
                    ((Page)sender).Navigation.PushAsync(pedidoPage);
                };
                UserDialogs.Instance.HideLoading();
                //((RootPage)App.Current.MainPage).PaginaAtual = pedidoListaPage;
                ((RootPage)App.Current.MainPage).PushAsync(pedidoListaPage);
            }
            catch (Exception erro)
            {
                UserDialogs.Instance.HideLoading();
                UserDialogs.Instance.Alert(erro.Message, "Erro", "Fechar");
            }
        }
        public void RemoverItem_AtualizarValorPedido()
        {
            // Arrange
            var pedido = PedidoFactory.CriarNovoPedidoRascunho(Guid.NewGuid());

            var item1 = new Item(Guid.NewGuid(), "Item 1", 2, 5);

            pedido.AdicionarItem(item1);

            var idItem2 = Guid.NewGuid();
            var item2   = new Item(idItem2, "Item 1", 2, 5);

            pedido.AdicionarItem(item2);

            pedido.Itens.Should().HaveCount(2);
            pedido.ValorTotal.Should().Be(20, "Existem 2 itens com 2 quantidades e valor de R$5,00.");

            // Act
            pedido.RemoverItem(item2);

            // Assert
            pedido.Itens.Should().HaveCount(1, "Foi removido um item.");
            pedido.ValorTotal.Should().Be(10, "Existe somente o item 1 com 2 quantidades no valor de R$5,00.");
            pedido.Itens.First().Id.Should().NotBe(idItem2, "O item foi removido.");
        }
Exemplo n.º 3
0
        public void NovoPedido_StatusDeveSerRascunho()
        {
            // Arrange
            var pedido = PedidoFactory.CriarNovoPedidoRascunho(Guid.NewGuid());

            // Act & Assert
            pedido.Status.Should().Be(PedidoStatus.Rascunho, "Todo novo pedido deve ser iniciado como rascunho");
        }
Exemplo n.º 4
0
        public void NovoPedido_ValorDeveSerZero()
        {
            // Arrange
            var pedido = PedidoFactory.CriarNovoPedidoRascunho(Guid.NewGuid());

            // Act & Assert
            pedido.ValorTotal.Should().Be(0, "O pedido não possui itens.");
        }
Exemplo n.º 5
0
        public void FecharPedido(Pedido pedido, Inflacao inflacao)
        {
            promocaoCalculadora.Registrar(pedido);
            pedido.Aplicar(inflacao);
            pedido.Calcular();

            PedidoFactory.Inserir(pedido);
        }
        public static async void finalizarAcompanhamento()
        {
            var regraPedido = PedidoFactory.create();
            await regraPedido.limparAtual();

            AcompanhaPageAtual = null;
            GPSUtils.Current.aoAtualizarPosicao -= atualizarPosicao;
            await GPSUtils.Current.finalizar();
        }
Exemplo n.º 7
0
        protected async override Task atualizandoDado()
        {
            await base.atualizandoDado();

            var regraUsuario = UsuarioFactory.create();
            var usuario      = regraUsuario.pegarAtual();

            var regraPedido = PedidoFactory.create();

            _avaliacaoPage.Pedidos = await regraPedido.listarAvaliacao(0, usuario.Id);
        }
Exemplo n.º 8
0
        public void AdicionarItem_ItemAcimaDoPermitido_DeveRetornarException()
        {
            // Arrange
            var pedido = PedidoFactory.CriarNovoPedidoRascunho(Guid.NewGuid());
            var item   = new Item(Guid.NewGuid(), "Item 1", Domain.Pedido.QUANTIDADE_MAXIMA_PEDIDOS + 1, 100);

            // Act & Assert
            Action act = () => pedido.AdicionarItem(item);

            act.Should().Throw <DomainException>().WithMessage($"Quantidade de acima do permitido.");
        }
        public void RemoverItemInexistente_LancarDomainException()
        {
            // Arrange
            var pedido = PedidoFactory.CriarNovoPedidoRascunho(Guid.NewGuid());

            var    item = new Item(Guid.NewGuid(), "Item 1", 1, 5);
            Action act  = () => pedido.RemoverItem(item);

            // Act & Assert
            act.Should().Throw <DomainException>().WithMessage("Item inexistente.");
        }
 private static void atualizarPosicao(object sender, GPSLocalInfo local)
 {
     Device.BeginInvokeOnMainThread(async() => {
         try
         {
             var regraPedido = PedidoFactory.create();
             var pedido      = regraPedido.pegarAtual();
             if (pedido == null)
             {
                 return;
             }
             var envio = new PedidoEnvioInfo
             {
                 IdPedido  = pedido.Id,
                 Latitude  = local.Latitude,
                 Longitude = local.Longitude
             };
             var retorno = await regraPedido.atualizar(envio);
             if (!string.IsNullOrEmpty(retorno.Polyline))
             {
                 if (AcompanhaPageAtual != null)
                 {
                     var rota = new MapaRotaInfo
                     {
                         PosicaoAtual = new LocalInfo
                         {
                             Latitude  = retorno.Latitude,
                             Longitude = retorno.Longitude
                         },
                         PolylineStr  = retorno.Polyline,
                         Distancia    = retorno.Distancia,
                         DistanciaStr = retorno.DistanciaStr,
                         Tempo        = retorno.Tempo,
                         TempoStr     = retorno.TempoStr
                     };
                     rota.Polyline = MapaUtils.decodePolyline(rota.PolylineStr);
                     if (AcompanhaPageAtual != null)
                     {
                         AcompanhaPageAtual.atualizarMapa(rota);
                     }
                 }
             }
             else if (!string.IsNullOrEmpty(retorno.Mensagem))
             {
                 UserDialogs.Instance.Alert(retorno.Mensagem, "Erro", "Entendi");
             }
         }
         catch (Exception erro)
         {
             UserDialogs.Instance.Alert(erro.Message, "Erro", "Entendi");
         }
     });
 }
Exemplo n.º 11
0
        public void AdicionarItem_NovoPedido_DeveAtualizarValor()
        {
            // Arrange
            var pedido = PedidoFactory.CriarNovoPedidoRascunho(Guid.NewGuid());
            var item   = new Item(Guid.NewGuid(), "Item 1", 2, 100);

            // Act
            pedido.AdicionarItem(item);

            // Assert
            pedido.ValorTotal.Should().Be(200, "Cada item vale R$100,00 e o pedido possui somente 1 item com 2 quantidades.");
        }
 public static void iniciarAcompanhamento(PedidoInfo pedido)
 {
     //if (await GPSUtils.Current.inicializar()) {
     if (GPSUtils.Current.estaAtivo())
     {
         var regraPedido = PedidoFactory.create();
         regraPedido.gravarAtual(pedido);
         GPSUtils.Current.aoAtualizarPosicao += atualizarPosicao;
     }
     else
     {
         UserDialogs.Instance.Alert("Ative seu GPS!", "Erro", "Entendi");
     }
 }
Exemplo n.º 13
0
        public void ItemComQuantidadeMaiorQuePermitido_LancarDomainException()
        {
            var idItemPedido = Guid.NewGuid();

            // Arrange
            var pedido = PedidoFactory.CriarNovoPedidoRascunho(Guid.NewGuid());
            var item   = new Item(idItemPedido, "Item 1", 15, 5);

            pedido.AdicionarItem(item);

            var item2 = new Item(idItemPedido, "Item 1", 16, 5);

            // Act
            Action act = () => pedido.AtualizarItem(item2);

            // Assert
            act.Should().Throw <DomainException>().WithMessage("Quantidade de acima do permitido.");
        }
Exemplo n.º 14
0
        private async void cancelarClicked(object sender, EventArgs e)
        {
            UserDialogs.Instance.ShowLoading("Carregando...");
            try
            {
                var regraPedido = PedidoFactory.create();
                await regraPedido.alterarSituacao(Pedido.Id, SituacaoEnum.Cancelado);

                var pedido = await regraPedido.pegar(Pedido.Id);

                Pedido = pedido;
                UserDialogs.Instance.HideLoading();
            }
            catch (Exception erro)
            {
                UserDialogs.Instance.HideLoading();
                //UserDialogs.Instance.Alert(erro.Message, "Erro", "Fechar");
                await DisplayAlert("Erro", erro.Message, "Entendi");
            }
        }
Exemplo n.º 15
0
        public void AdicionarItem_ItemExistente_AdicionarQuantidadeSomarValor()
        {
            var idItem = Guid.NewGuid();

            // Arrange
            var pedido = PedidoFactory.CriarNovoPedidoRascunho(Guid.NewGuid());
            var item   = new Item(idItem, "Item 1", 2, 100);

            pedido.AdicionarItem(item);

            var item2 = new Item(idItem, "Item 2", 3, 100);

            // Act
            pedido.AdicionarItem(item2);

            // Assert
            pedido.ValorTotal.Should().Be(500, "Cada item vale R$100,00 e o pedido possui somente 1 item com 5 quantidades.");
            pedido.Itens.Should().HaveCount(1, "Foi adicionado o mesmo item novamente.");
            pedido.Itens.FirstOrDefault(a => a.Id == idItem).Quantidade.Should().Be(5, "Foi adicionado o mesmo item novamente.");
        }
Exemplo n.º 16
0
        public void ItemComQuantidadeDiferenteDoQueAnteriormente_AtualizarValorEQUantidade()
        {
            var idItemPedido = Guid.NewGuid();

            // Arrange
            var pedido = PedidoFactory.CriarNovoPedidoRascunho(Guid.NewGuid());
            var item   = new Item(idItemPedido, "Item 1", 2, 5);

            pedido.AdicionarItem(item);

            var item2 = new Item(idItemPedido, "Item 1", 5, 5);

            // Act
            pedido.AtualizarItem(item2);

            // Assert
            pedido.Itens.Should().HaveCount(1);
            pedido.Itens.First().Quantidade.Should().Be(5);
            pedido.ValorTotal.Should().Be(25, "O item anterior foi atualizado para um novo item com 5 unidades de R$5,00.");
        }
Exemplo n.º 17
0
        private async void horarioClicked(object sender, EventArgs e)
        {
            var regraHorario = PedidoHorarioFactory.create();
            var horarios     = await regraHorario.listar(Pedido.IdLoja);

            var horarioEntregaPage = new HorarioEntregaPage()
            {
                Title    = "Selecione o horário de entrega",
                Horarios = horarios
            };

            horarioEntregaPage.AoSelecionar += async(s2, horario) =>
            {
                UserDialogs.Instance.ShowLoading("Enviando...");
                try
                {
                    Pedido.DiaEntrega     = horarioEntregaPage.DiaEntrega;
                    Pedido.HorarioEntrega = horario;
                    Pedido.Avisar         = false;

                    var regraPedido = PedidoFactory.create();
                    await regraPedido.alterar(Pedido);

                    var pedido = await regraPedido.pegar(Pedido.Id);

                    Pedido = pedido;
                    atualizarTela(Pedido);
                    UserDialogs.Instance.HideLoading();
                    await horarioEntregaPage.Navigation.PopAsync();
                }
                catch (Exception erro)
                {
                    UserDialogs.Instance.HideLoading();
                    UserDialogs.Instance.Alert(erro.Message, "Erro", "Fechar");
                }
            };
            UserDialogs.Instance.HideLoading();
            ((RootPage)App.Current.MainPage).PushAsync(horarioEntregaPage);
        }
Exemplo n.º 18
0
        private void avaliarClicked(object sender, EventArgs e)
        {
            var avaliePage = new AvaliePage
            {
                Descricao = "Que nota você daria para o seu pedido?"
            };

            avaliePage.AoAvaliar += async(s2, avaliacao) => {
                UserDialogs.Instance.ShowLoading("Carregando...");
                try
                {
                    var regraPedido = PedidoFactory.create();
                    var pedido      = await regraPedido.pegar(Pedido.Id);

                    pedido.Nota       = avaliacao.Nota;
                    pedido.Comentario = avaliacao.Comentario;
                    if (pedido.Situacao == SituacaoEnum.Entregue)
                    {
                        pedido.Situacao = SituacaoEnum.Finalizado;
                    }
                    await regraPedido.alterar(pedido);

                    pedido = await regraPedido.pegar(Pedido.Id);

                    Pedido = pedido;
                    atualizarTela(Pedido);
                    UserDialogs.Instance.HideLoading();
                }
                catch (Exception erro)
                {
                    UserDialogs.Instance.HideLoading();
                    //UserDialogs.Instance.Alert(erro.Message, "Erro", "Fechar");
                    await DisplayAlert("Erro", erro.Message, "Entendi");
                }
            };
            Navigation.PushAsync(avaliePage);
        }
Exemplo n.º 19
0
        /*
         * private StackLayout gerarNota(int nota)
         * {
         *  return new StackLayout
         *  {
         *      Orientation = StackOrientation.Horizontal,
         *      HorizontalOptions = LayoutOptions.Start,
         *      VerticalOptions = LayoutOptions.Start,
         *      Children = {
         *          new IconImage {
         *              Icon = (nota >= 1) ? "fa-star" : "fa-star-o",
         *              IconSize = 22,
         *              IconColor = Color.Gold
         *          },
         *          new IconImage {
         *              Icon = (nota >= 2) ? "fa-star" : "fa-star-o",
         *              IconSize = 22,
         *              IconColor = Color.Gold
         *          },
         *          new IconImage {
         *              Icon = (nota >= 3) ? "fa-star" : "fa-star-o",
         *              IconSize = 22,
         *              IconColor = Color.Gold
         *          },
         *          new IconImage {
         *              Icon = (nota >= 4) ? "fa-star" : "fa-star-o",
         *              IconSize = 22,
         *              IconColor = Color.Gold
         *          },
         *          new IconImage {
         *              Icon = (nota >= 5) ? "fa-star" : "fa-star-o",
         *              IconSize = 22,
         *              IconColor = Color.Gold
         *          }
         *      }
         *  };
         * }
         */

        private void inicilizarComponente()
        {
            _FotoImage = new Image {
                HorizontalOptions = LayoutOptions.Start,
                VerticalOptions   = LayoutOptions.Start,
                Aspect            = Aspect.AspectFit,
                WidthRequest      = 80,
                HeightRequest     = 80

                                    /*
                                     * WidthRequest = 120,
                                     * HeightRequest = 120
                                     */
                                    //Style = Estilo.Current[Estilo.LISTA_ITEM]
            };
            _FotoImage.SetBinding(Image.SourceProperty, new Binding("FotoUrl"));
            _NomeLabel = new Label {
                HorizontalOptions = LayoutOptions.FillAndExpand,
                VerticalOptions   = LayoutOptions.Center,
                FontAttributes    = FontAttributes.Bold,
                TextColor         = Estilo.Current.BarBackgroundColor,
                FontSize          = 18,
            };
            _NomeLabel.SetBinding(Label.TextProperty, new Binding("Nome"));
            _EnderecoLabel = new Label
            {
                HorizontalOptions = LayoutOptions.FillAndExpand,
                VerticalOptions   = LayoutOptions.Start,
                FontAttributes    = FontAttributes.Italic,
                TextColor         = Color.FromHex("#7c7c7c"),
                FontSize          = 13,
            };
            _EnderecoLabel.SetBinding(Label.TextProperty, new Binding("EnderecoCompleto"));

            _notaControl = new NotaControl {
                HorizontalOptions = LayoutOptions.Start,
                VerticalOptions   = LayoutOptions.Start,
                IconSize          = 24
            };
            _notaControl.SetBinding(NotaControl.NotaProperty, new Binding("Nota"));
            _notaControl.AoClicar += async(sender, nota) => {
                var loja = this.Loja;
                if (loja == null)
                {
                    UserDialogs.Instance.Alert("Nenhuma loja selecionada.", "Erro", "Fechar");
                    return;
                }
                UserDialogs.Instance.ShowLoading("Carregando...");
                try
                {
                    //var regraLoja = LojaFactory.create();
                    //_lojaListView.ItemsSource = await regraLoja.buscar(Local.Latitude, Local.Longitude);
                    var regraPedido = PedidoFactory.create();
                    var pedidos     = await regraPedido.listarAvaliacao(loja.Id);

                    var avaliacaoPage = new LojaAvaliacaoPage()
                    {
                        Title   = "Avaliações",
                        Pedidos = pedidos
                    };
                    UserDialogs.Instance.HideLoading();
                    if (App.Current.MainPage is RootPage)
                    {
                        ((RootPage)App.Current.MainPage).PushAsync(avaliacaoPage);
                    }
                    else
                    {
                        await App.Current.MainPage.Navigation.PushAsync(avaliacaoPage);
                    }
                }
                catch (Exception erro)
                {
                    UserDialogs.Instance.HideLoading();
                    UserDialogs.Instance.Alert(erro.Message, "Erro", "Fechar");
                }
            };

            _DistanciaLabel = new Label
            {
                HorizontalOptions = LayoutOptions.FillAndExpand,
                VerticalOptions   = LayoutOptions.Start,
                FontAttributes    = FontAttributes.Bold,
                TextColor         = Color.FromHex("#7c7c7c"),
                FontSize          = 14,
            };
            _DistanciaLabel.SetBinding(Label.TextProperty, new Binding("DistanciaStr"));
        }
Exemplo n.º 20
0
 public PedidosController(RestauranteService restauranteService, PedidoFactory pedidoFactory)
 {
     RestauranteService = restauranteService;
     PedidoFactory      = pedidoFactory;
 }
Exemplo n.º 21
0
        public static Page gerarCarrinhoParaEntrega()
        {
            var carrinhoPage = new CarrinhoPage
            {
                Title = "Meu carrinho"
            };

            carrinhoPage.AoFinalizar += (s1, produtos) =>
            {
                LoginUtils.carregarUsuario((usuario) => {
                    var metodoEntregaPage = PedidoUtils.gerarEntregaMetodo(async(pedido) => {
                        if (await UserDialogs.Instance.ConfirmAsync("Deseja fechar o pedido?", "Aviso", "Sim", "Não", null))
                        {
                            var pagamentoMetodoPage = PagamentoUtils.gerarPagamento(async(pagamento) => {
                                UserDialogs.Instance.ShowLoading("Enviando...");
                                try
                                {
                                    pedido.IdPagamento = pagamento.IdPagamento;
                                    switch (pagamento.Tipo)
                                    {
                                    case TipoPagamentoEnum.CreditoOnline:
                                        pedido.FormaPagamento = FormaPagamentoEnum.CreditoOnline;
                                        break;

                                    case TipoPagamentoEnum.DebitoOnline:
                                        pedido.FormaPagamento = FormaPagamentoEnum.DebitoOnline;
                                        break;

                                    case TipoPagamentoEnum.Boleto:
                                        pedido.FormaPagamento = FormaPagamentoEnum.Boleto;
                                        break;

                                    case TipoPagamentoEnum.Dinheiro:
                                        pedido.FormaPagamento = FormaPagamentoEnum.Dinheiro;
                                        pedido.TrocoPara      = pagamento.TrocoPara;
                                        break;

                                    case TipoPagamentoEnum.CartaoOffline:
                                        pedido.FormaPagamento = FormaPagamentoEnum.CartaoOffline;
                                        break;
                                    }
                                    switch (pagamento.Situacao)
                                    {
                                    case SituacaoPagamentoEnum.Pago:
                                        pedido.Situacao = Pedido.Model.SituacaoEnum.Preparando;
                                        break;

                                    case SituacaoPagamentoEnum.AguardandoPagamento:
                                        pedido.Situacao = Pedido.Model.SituacaoEnum.AguardandoPagamento;
                                        break;

                                    default:
                                        pedido.Situacao = Pedido.Model.SituacaoEnum.Pendente;
                                        break;
                                    }
                                    var regraPedido = PedidoFactory.create();
                                    int idPedido    = pedido.Id;
                                    if (idPedido > 0)
                                    {
                                        await regraPedido.alterar(pedido);
                                    }
                                    else
                                    {
                                        idPedido = await regraPedido.inserir(pedido);
                                    }
                                    var pedidoFechado = await regraPedido.pegar(idPedido);
                                    var regraCarrinho = CarrinhoFactory.create();
                                    regraCarrinho.limpar();

                                    if (pedidoFechado.Entrega == EntregaEnum.RetiradaMapeada)
                                    {
                                        AcompanhamentoUtils.iniciarAcompanhamento(pedidoFechado);
                                    }

                                    if (pedidoFechado.Entrega == EntregaEnum.Entrega && pedido.Situacao != Pedido.Model.SituacaoEnum.AguardandoPagamento)
                                    {
                                        var regraHorario = PedidoHorarioFactory.create();
                                        var horarios     = await regraHorario.listar(pedidoFechado.IdLoja);
                                        if (horarios.Count > 1)
                                        {
                                            var horarioEntregaPage = new HorarioEntregaPage()
                                            {
                                                Title = "Horário de Entrega",
                                                //Pedido = pedidoFechado,
                                                Horarios = horarios
                                            };
                                            horarioEntregaPage.AoSelecionar += async(s2, horario) =>
                                            {
                                                UserDialogs.Instance.ShowLoading("Enviando...");
                                                try
                                                {
                                                    pedidoFechado.DiaEntrega     = horarioEntregaPage.DiaEntrega;
                                                    pedidoFechado.HorarioEntrega = horario;
                                                    pedidoFechado.Avisar         = false;

                                                    await regraPedido.alterar(pedidoFechado);
                                                    ((RootPage)App.Current.MainPage).PaginaAtual = new PedidoPage
                                                    {
                                                        Pedido = pedidoFechado
                                                    };
                                                    UserDialogs.Instance.HideLoading();
                                                }
                                                catch (Exception erro)
                                                {
                                                    UserDialogs.Instance.HideLoading();
                                                    UserDialogs.Instance.Alert(erro.Message, "Erro", "Fechar");
                                                }
                                            };
                                            UserDialogs.Instance.HideLoading();
                                            ((RootPage)App.Current.MainPage).PushAsync(horarioEntregaPage);
                                        }
                                        else
                                        {
                                            UserDialogs.Instance.HideLoading();
                                            ((RootPage)App.Current.MainPage).PaginaAtual = new PedidoPage {
                                                Pedido = pedidoFechado
                                            };
                                        }
                                    }
                                    else
                                    {
                                        UserDialogs.Instance.HideLoading();
                                        ((RootPage)App.Current.MainPage).PaginaAtual = new PedidoPage {
                                            Pedido = pedidoFechado
                                        };
                                    }
                                }
                                catch (Exception erro)
                                {
                                    UserDialogs.Instance.HideLoading();
                                    UserDialogs.Instance.Alert(erro.Message, "Erro", "Fechar");
                                }
                            });
                            var regraLoja = LojaFactory.create();
                            var loja      = regraLoja.pegarAtual();
                            pagamentoMetodoPage.UsaCredito  = loja.AceitaCreditoOnline;
                            pagamentoMetodoPage.UsaDebito   = loja.AceitaDebitoOnline;
                            pagamentoMetodoPage.UsaDinheiro = loja.AceitaDinheiro;
                            pagamentoMetodoPage.UsaBoleto   = loja.AceitaBoleto;
                            pagamentoMetodoPage.Pagamento   = PagamentoUtils.gerar(pedido);

                            ((RootPage)App.Current.MainPage).PushAsync(pagamentoMetodoPage);
                        }
                    });
                    metodoEntregaPage.Pedido = PedidoUtils.gerar(produtos);
                    ((RootPage)App.Current.MainPage).PushAsync(metodoEntregaPage);
                });
            };
            return(carrinhoPage);
        }