Exemplo n.º 1
0
        private async void txtCep_Unfocused(object sender, FocusEventArgs e)
        {
            // Verificar a quantidade de caracteres do cep
            if (txtCep.Text.Length < 8)
            {
                return;
            }

            // Instanciar o serviço de endereco
            var es = new EnderecoService();

            var endereco = await es.Pesquisar(txtCep.Text);

            // Verificar se retornou com sucesso
            if (es.Resultado.Sucesso == true)
            {
                txtEndereco.Text = endereco.Logradouro;
                txtBairro.Text   = endereco.Bairro;
                txtCidade.Text   = endereco.Localidade;
                txtUf.Text       = endereco.Uf;
            }
            else
            {
                // Exibir mensagem de erro
                await DisplayAlert("Erro", es.Resultado.Mensagem, "Fechar");
            }
        }
        public ClienteController()
        {
            var context = new ContextMercadOn();

            service         = new ConsumidorService(context);
            enderecoService = new EnderecoService(context);
        }
Exemplo n.º 3
0
        public ActionResult Grid(int? page)
        {
            page = page ?? 1;

            if (User.Identity.IsAuthenticated && UserAuthenticated != null && UserAuthenticated.IdCliente.HasValue)
            {
                var enderecos = new EnderecoService().GetAddressesByClientId(page.Value, UserAuthenticated.IdCliente.Value);

                var list = new MvcList<Ecommerce_Cliente_Endereco>(enderecos.Item1, page.Value, enderecos.Item2, 5);
                return PartialView(list);
            }
            return null;
        }
Exemplo n.º 4
0
        public ActionResult Details()
        {
            CarrinhoModel carrinho = GetCurrentCart();
            if(carrinho.ShippingMethod == null)
            {
                new CarrinhoService().UpdateShippingMethod(carrinho.Cookie, "UPS");
                carrinho = GetCurrentCart();
            }


            ViewBag.Title = Resources.Resource.Carrinho_Titulo;
            ViewBag.FormasEnvio = new EntregaService().GetRecords(m => m.IsAtivo);
            ViewBag.TipoEntrega = carrinho.ShippingMethod;

            var peso = carrinho.Items.Sum(x => x.Quantidade * x.Produto.Peso) / 1000;
            var comprimento = carrinho.Items.Sum(x => x.Quantidade * (GetDimensao(x.Produto.Dimensoes, 0) / 10));
            var altura = carrinho.Items.Sum(x => x.Quantidade * (GetDimensao(x.Produto.Dimensoes, 1) / 10));
            var largura = carrinho.Items.Sum(x => x.Quantidade * (GetDimensao(x.Produto.Dimensoes, 2) / 10));
            var diametro = carrinho.Items.Sum(x => x.Quantidade * (GetDimensao(x.Produto.Dimensoes, 3) / 10));

            //if (carrinho.ShippingMethod != null)
            //{
                carrinho.ValorFrete = (carrinho.ShippingMethod ?? "UPS").Equals("UPS")
                                          ? GetShippingPriceUPS(carrinho.ZipCode, peso)
                                          : GetShippingPriceCorreios(carrinho.ZipCode, peso, carrinho.ShippingMethod,
                                                                     comprimento, altura, largura, diametro,
                                                                     ref carrinho);
            //}
            //Atualiza o valor das taxas para o estado
            if (User.Identity.IsAuthenticated && UserAuthenticated != null && UserAuthenticated.IdCliente.HasValue)
            {
                var endereco = new EnderecoService().GetShippingAddressesByClientId(UserAuthenticated.IdCliente.Value);
                if (endereco.IdEstado.HasValue)
                {
                    var tax = new TaxaService().GetByEstadoId(endereco.IdEstado.Value);
                    if (tax != null && tax.Taxa.HasValue && carrinho.ValorSubtotal > 0)
                        carrinho.ValorTaxas = Decimal.Round(((carrinho.ValorSubtotal / 100) * tax.Taxa.Value), 2);
                }
            }

            return View(carrinho);
        }
Exemplo n.º 5
0
        public ActionResult ShippingMethodByAddress(String address, String shippingType)
        {
            var carrinho = GetCurrentCart();
            new CarrinhoService().UpdateShippingMethod(carrinho.Cookie, shippingType);
            carrinho = GetCurrentCart();

            var idCliente = FormsAuthenticationUtil.UserAuthenticated.IdCliente;

            if (idCliente != null)
            {
                var endEntregaAntigo = new EnderecoService().GetDefaultShippingAddress(idCliente.Value);
                if (endEntregaAntigo != null)
                {
                    new EnderecoService().ChangeShippingAddress(endEntregaAntigo, false);
                }
                
                var end = new EnderecoService().GetById(int.Parse(address));
                if (end != null)
                {
                    new EnderecoService().ChangeShippingAddress(end, true);
                }
                carrinho.ZipCode = end.Cep;//Change zipcode
            }

            var peso = carrinho.Items.Sum(x => x.Quantidade * x.Produto.Peso) / 1000;
            var comprimento = carrinho.Items.Sum(x => x.Quantidade * (GetDimensao(x.Produto.Dimensoes, 0) / 10));
            var altura = carrinho.Items.Sum(x => x.Quantidade * (GetDimensao(x.Produto.Dimensoes, 1) / 10));
            var largura = carrinho.Items.Sum(x => x.Quantidade * (GetDimensao(x.Produto.Dimensoes, 2) / 10));
            var diametro = carrinho.Items.Sum(x => x.Quantidade * (GetDimensao(x.Produto.Dimensoes, 3) / 10));

            carrinho.ValorFrete = shippingType.Equals("UPS") ? GetShippingPriceUPS(carrinho.ZipCode, peso) : GetShippingPriceCorreios(carrinho.ZipCode, peso, shippingType, comprimento, altura, largura, diametro, ref carrinho);
            //Atualiza o valor das taxas para o estado
            if (User.Identity.IsAuthenticated && UserAuthenticated != null && UserAuthenticated.IdCliente.HasValue)
            {
                var endereco = new EnderecoService().GetShippingAddressesByClientId(UserAuthenticated.IdCliente.Value);
                if (endereco.IdEstado.HasValue)
                {
                    var tax = new TaxaService().GetByEstadoId(endereco.IdEstado.Value);
                    if (tax != null && tax.Taxa.HasValue && carrinho.ValorSubtotal > 0)
                        carrinho.ValorTaxas = Decimal.Round(((carrinho.ValorSubtotal / 100) * tax.Taxa.Value), 2);
                }
            }

            ViewBag.TipoEntrega = carrinho.ShippingMethod;
            ViewBag.FormasEnvio = new EntregaService().GetRecords(m => m.IsAtivo);

            return PartialView("Summary", carrinho);
        }
Exemplo n.º 6
0
        public ActionResult ShippingMethod(CarrinhoModel carrinho)
        {
            Decimal peso = carrinho.Items.Sum(x => x.Quantidade * x.Produto.Peso) / 1000;
            carrinho.ValorFrete = GetShippingPriceUPS(carrinho.ZipCode, peso);
            //Atualiza o valor das taxas para o estado
            if (UserAuthenticated != null && UserAuthenticated.IdCliente.HasValue)
            {
                var endereco = new EnderecoService().GetShippingAddressesByClientId(UserAuthenticated.IdCliente.Value);
                if (endereco.IdEstado.HasValue)
                {
                    var tax = new TaxaService().GetByEstadoId(endereco.IdEstado.Value);
                    if (tax != null && tax.Taxa.HasValue && carrinho.ValorSubtotal > 0)
                        carrinho.ValorTaxas = Decimal.Round(((carrinho.ValorSubtotal / 100) * tax.Taxa.Value), 2);
                }
            }

            return PartialView(carrinho);
        }
Exemplo n.º 7
0
 public EnderecoUnitTest()
 {
     service = new EnderecoService();
 }
Exemplo n.º 8
0
        /// <summary>
        /// Form to submit values to gateway
        /// </summary>
        /// <param name="id">idPedido</param>
        /// <returns></returns>
        public ActionResult Payment(int id)
        {
            if (User.Identity.IsAuthenticated)
            {
                ViewBag.Title = Resources.Resource.Pagamento_Titulo;

                //get order details
                var idPedido = new PedidoService().GetRecords(x => x.NumeroPedido == id).FirstOrDefault().IdPedido;
                var pedido = new PedidoService().GetById(idPedido, GetCurrentIdIdioma());

                if (pedido.Status == StatusPedido.AguardandoPagamento &&
                    FormsAuthenticationUtil.UserAuthenticated.IdCliente.HasValue &&
                    FormsAuthenticationUtil.UserAuthenticated.IdCliente.Value == pedido.IdCliente)
                {
                    //get shipping address details
                    var endereco = new EnderecoService().GetShippingAddress(pedido.IdPedido);

                    var cultureInfo = new CultureInfo("en-US");

                    var rgService = new RequestGatewayService();
                    rgService.Model = new RequestGatewayModel
                    {
                        PedidoNumero = pedido.Numero.HasValue ? pedido.Numero.Value.ToString(CultureInfo.InvariantCulture) : string.Empty,
                        PedidoValorFrete = pedido.ValorFrete.ToString(cultureInfo),
                        PedidoValorTaxas = pedido.ValorTaxa.ToString(cultureInfo),
                        PedidoValorManuseio = pedido.ValorManuseio.ToString(cultureInfo),
                        PedidoSubTotal = pedido.Subtotal.ToString(cultureInfo),
                        PedidoTotal = pedido.Total.ToString(cultureInfo),

                        ClienteId = pedido.IdCliente.ToString(CultureInfo.InvariantCulture),
                        ClienteSobrenome = pedido.NomeCliente.Trim().Split(' ').Length > 1 ? pedido.NomeCliente.Trim().Split(' ')[0] : pedido.NomeCliente.Trim(),
                        ClienteNome = pedido.NomeCliente.Trim().Split(' ').Length > 1 ? pedido.NomeCliente.Trim().Substring(pedido.NomeCliente.IndexOf(' '), pedido.NomeCliente.Trim().Length - pedido.NomeCliente.Trim().IndexOf(' ')) : string.Empty,

                        EnderecoCep = endereco.Cep,
                        EnderecoLogradouro = endereco.Logradouro,
                        EnderecoCidade = endereco.IdCidade != null ? endereco.Cidade1.Nome : endereco.Cidade,
                        EnderecoEstado = endereco.IdEstado != null ? endereco.Estado.Nome : string.Empty,
                        EnderecoEmail = endereco.EmailEntrega,
                        EnderecoTelefone = endereco.TelefoneEntrega
                    };

                    switch (pedido.FormaPagamento)
                    {
                        case FormaPagamento.Authorize:
                            var parameters = new ParametroService().GetByParameterType((int)TipoParametro.FormaDePagamento);
                            var apiLogin = parameters.Where(x => x.Nome == "Login ApI").FirstOrDefault();
                            var transKey = parameters.Where(x => x.Nome == "Transaction Key").FirstOrDefault();
                            var urlResponse = parameters.Where(x => x.Nome == "Url de retorno Authorize").FirstOrDefault();

                            if (apiLogin != null && transKey != null && urlResponse != null)
                            {
                                rgService.QueryString = Settings.AuthorizeQueryString;
                                rgService.Model.GatewayUsuario = apiLogin.Valor;
                                rgService.Model.GatewayUrlRequest = Settings.AuthorizeRequest;
                                rgService.Model.GatewayUrlResponse = urlResponse.Valor;

                                rgService.AdicionalParameters = new Dictionary<String, String>();
                                var timeStamp = ((int)(DateTime.UtcNow - new DateTime(1970, 1, 1)).TotalSeconds).ToString();
                                string fingerprint = WebHelpers.HMAC_MD5(transKey.Valor, rgService.Model.GatewayUsuario + "^" + rgService.Model.PedidoNumero + "^" + timeStamp + "^" + rgService.Model.PedidoTotal + "^");

                                rgService.AdicionalParameters.Add("timeStamp", timeStamp);
                                rgService.AdicionalParameters.Add("fingerprint", fingerprint);
                            }

                            return View(rgService);
                        case FormaPagamento.Paypal:
                            var parametros = new ParametroService().GetByParameterType((int)TipoParametro.FormaDePagamento);
                            var business = parametros.Where(x => x.Nome == "Business").FirstOrDefault().Valor;
                            var urlRetorno = parametros.Where(x => x.Nome == "Url de retorno Paypal").FirstOrDefault().Valor;
                            var urlNotificacao = parametros.Where(x => x.Nome == "Url de notificação").FirstOrDefault().Valor;
                            var urlImagem = parametros.Where(x => x.Nome == "Url da Imagem").FirstOrDefault().Valor;

                            rgService.QueryString = Settings.PaypalQueryString;
                            rgService.Model.GatewayUsuario = business;
                            rgService.Model.GatewayUrlRequest = Settings.PaypalRequest;
                            rgService.Model.GatewayUrlResponse = urlRetorno;

                            rgService.AdicionalParameters = new Dictionary<string, string>();
                            rgService.AdicionalParameters.Add("lc", "PT");// CultureInfo.CurrentUICulture.TextInfo.CultureName.Split('-')[1]
                            rgService.AdicionalParameters.Add("image_url", urlImagem);
                            rgService.AdicionalParameters.Add("notify_url", urlNotificacao);

                            return View(rgService);
                        case FormaPagamento.BoletoBradesco:
                            var paramBoleto = new ParametroService().GetByParameterType((int)TipoParametro.FormaDePagamento);
                            var urlBoleto = paramBoleto.FirstOrDefault(m => m.Nome == "Boleto Bradesco URL") ?? new Parametro();
                            var numLoja = paramBoleto.FirstOrDefault(m => m.Nome == "Boleto Bradesco Numero Loja") ?? new Parametro();

                            rgService.Model.PedidoNumero = idPedido.ToString(CultureInfo.InvariantCulture);
                            rgService.Model.GatewayUrlRequest = string.Format(urlBoleto.Valor, numLoja.Valor, id);
                            rgService.QueryString = string.Format(Settings.BoletoBradescoQueryString, numLoja.Valor, id);

                            return View("PaymentBoleto", rgService);
                        default:
                            return AccessDenied();
                    }
                }
            }
            return AccessDenied();
        }
Exemplo n.º 9
0
        /// <summary>
        /// Delete an Ecommerce_Cliente_Endereco.
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public ActionResult Remove(int id)
        {
            //Retorna o endereço a ser deletado
            var addressForDelete = new EnderecoService().GetById(id);

            //Retorna a lista de endereços de determinado cliente
            var listAddress = new EnderecoService().GetRecords(x => x.IdCliente == addressForDelete.IdCliente).ToList();

            //Retorna o endereço de entrega padrão
            var addressDefaultShipping = new EnderecoService().GetDefaultShippingAddress(addressForDelete.IdCliente);

            //Se houver mais que um endereço
            if (listAddress.Count > 1)
            {
                //Se o endereço para deletar for o mesmo que o de entrega
                if (addressForDelete.IdEndereco == addressDefaultShipping.IdEndereco)
                {
                    //Set o primeiro endereço como endereço de entrega.
                    var updateAddress = listAddress.FirstOrDefault(x => x.IsEnderecoEntrega == false);
                    new EnderecoService().ChangeShippingAddress(updateAddress, true);

                    //Delete o endereço solicitado
                    new EnderecoService().DeleteObject(id);
                    return Json(new JsonRequestResult { ResultType = JsonRequestResultType.Success, Message = Resources.Resource.Address_RemovedMessage }, JsonRequestBehavior.AllowGet);
                }

                new EnderecoService().DeleteObject(id);
                return Json(new JsonRequestResult { ResultType = JsonRequestResultType.Success, Message = Resources.Resource.Address_RemovedMessage }, JsonRequestBehavior.AllowGet);
            }

            return Json(new JsonRequestResult { ResultType = JsonRequestResultType.Alert, Message = Resources.Resource.Msg_Geral_UmEnderecoObrigatorio }, JsonRequestBehavior.AllowGet);
        }
Exemplo n.º 10
0
        /// <summary>
        /// Returns a view with the Details of a client
        /// </summary>
        /// <param name="idCliente"></param>
        /// <returns></returns>
        public ActionResult Detalhes(int id)
        {
            ClientePedidoModel cPedModel = new ClientePedidoModel();

            Ecommerce_Cliente cliente = new ClienteService().GetById(id);

            if (cliente != null)
            {
                cPedModel.Cliente = cliente;

                Ecommerce_Cliente_Endereco clienteEndereco = new EnderecoService().GetDefaultShippingAddress(id);

                List<Ecommerce_Pedido> listaPedidos = new PedidoService().GetOrdersByIdCliente(cliente.IdCliente);

                if (clienteEndereco != null)
                {
                    cPedModel.ClienteEndereco = clienteEndereco;
                }

                if (listaPedidos != null)
                {
                    cPedModel.Pedidos = listaPedidos;
                }
            }
            else
            {
                cPedModel.Cliente = new Ecommerce_Cliente();
                cPedModel.ClienteEndereco = new Ecommerce_Cliente_Endereco();
                cPedModel.Pedidos = new List<Ecommerce_Pedido>();
            }

            return View(cPedModel);
        }
Exemplo n.º 11
0
 public JsonResult AutoComplete(String term, Int32 idEstado)
 {
     var listaCidades = new EnderecoService().GetCitiesByPartName(0, 10, term, idEstado);
     var pRetorno = from item in listaCidades.Item1
                    select new Dictionary<String, String>
                             { 
                                 { "value", item.IdCidade.ToString() },
                                 { "label", item.Nome } 
                             };
     return Json(pRetorno, JsonRequestBehavior.AllowGet);
 }
Exemplo n.º 12
0
 public ActionResult DetailsAddressDelivery()
 {
     if (User.Identity.IsAuthenticated && UserAuthenticated != null && UserAuthenticated.IdCliente.HasValue)
     {
         var endereco = new EnderecoService().GetShippingAddressesByClientId(UserAuthenticated.IdCliente.Value);
         return endereco == null ? null : PartialView(endereco);
     }
     return null;
 }
Exemplo n.º 13
0
        /// <summary>
        /// Populate a Modal window with an Ecommerce_Cliente_Endereco object
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public ActionResult Edit(int id)
        {
            var endereco = new EnderecoService().GetById(id);

            ViewBag.States = GetStateSelectedListItem(new EnderecoService().GetStates());

            return PartialView("Edit", endereco);

        }
Exemplo n.º 14
0
        /// <summary>
        /// Modify the default Shipping Address from a client
        /// </summary>
        /// <param name="idCliente"></param>
        /// <param name="idNewAddress"></param>
        /// <returns></returns>
        public ActionResult UpdateDelivery(int idNewAddress)
        {
            int? idCliente = FormsAuthenticationUtil.UserAuthenticated.IdCliente;

            var endEntregaAntigo = new EnderecoService().GetDefaultShippingAddress(idCliente.Value);

            if (endEntregaAntigo != null)
            {
                new EnderecoService().ChangeShippingAddress(endEntregaAntigo, false);
            }

            var endEntregaNovo = new EnderecoService().GetById(idNewAddress);

            if (endEntregaNovo != null)
            {
                new EnderecoService().ChangeShippingAddress(endEntregaNovo, true);
            }

            return Json(new JsonRequestResult { ResultType = JsonRequestResultType.Success, Message = Resources.Resource.Address_ChangeShippingAddressSuccess }, JsonRequestBehavior.AllowGet);
        }
Exemplo n.º 15
0
        /// <summary>
        /// Update the quantities for a list of items of the cart
        /// </summary>
        /// <param name="list"></param>
        /// <returns></returns>
        public ActionResult UpdateCartItems(List<CarrinhoItemModel> list, String shippingType)
        {
            var cService = new CarrinhoService();
            CarrinhoModel carrinho = GetCurrentCart();
            cService.UpdateQuantityCartItem(carrinho.Cookie, list);

            carrinho = GetCurrentCart();

            decimal peso = carrinho.Items.Sum(x => x.Quantidade * x.Produto.Peso) / 1000;
            carrinho.ValorFrete = GetShippingPriceUPS(carrinho.ZipCode, peso);
            carrinho.ValorFrete = carrinho.ValorFrete > 0 ? carrinho.ValorFrete : 0;

            //Atualiza o valor das taxas para o estado
            if (User.Identity.IsAuthenticated && UserAuthenticated != null && UserAuthenticated.IdCliente.HasValue)
            {
                var endereco = new EnderecoService().GetShippingAddressesByClientId(UserAuthenticated.IdCliente.Value);
                if (endereco.IdEstado.HasValue)
                {
                    var tax = new TaxaService().GetByEstadoId(endereco.IdEstado.Value);
                    if (tax != null && tax.Taxa.HasValue && carrinho.ValorSubtotal > 0)
                        carrinho.ValorTaxas = Decimal.Round(((carrinho.ValorSubtotal / 100) * tax.Taxa.Value), 2);
                }
            }
            ViewBag.TipoEntrega = carrinho.ShippingMethod;
            ViewBag.FormasEnvio = new EntregaService().GetRecords(m => m.IsAtivo);
            return PartialView("Details", carrinho);
        }
Exemplo n.º 16
0
        public ActionResult Payment()
        {
            if (User.Identity.IsAuthenticated)
            {
                ViewBag.Title = Resources.Resource.Pagamento_Titulo;
                CarrinhoModel carrinho = GetCurrentCart();

                var peso = carrinho.Items.Sum(x => x.Quantidade * x.Produto.Peso) / 1000;
                var comprimento = carrinho.Items.Sum(x => x.Quantidade * (GetDimensao(x.Produto.Dimensoes, 0) / 10));
                var altura = carrinho.Items.Sum(x => x.Quantidade * (GetDimensao(x.Produto.Dimensoes, 1) / 10));
                var largura = carrinho.Items.Sum(x => x.Quantidade * (GetDimensao(x.Produto.Dimensoes, 2) / 10));
                var diametro = carrinho.Items.Sum(x => x.Quantidade * (GetDimensao(x.Produto.Dimensoes, 3) / 10));

                //if (carrinho.ShippingMethod != null)
                //{
                    carrinho.ValorFrete = (carrinho.ShippingMethod ?? "UPS" ).Equals("UPS")
                                              ? GetShippingPriceUPS(carrinho.ZipCode, peso)
                                              : GetShippingPriceCorreios(carrinho.ZipCode, peso, carrinho.ShippingMethod,
                                                                         comprimento, altura, largura, diametro,
                                                                         ref carrinho);
                //}
                //Atualiza o valor das taxas para o estado
                if (UserAuthenticated != null && UserAuthenticated.IdCliente.HasValue)
                {
                    var endereco = new EnderecoService().GetShippingAddressesByClientId(UserAuthenticated.IdCliente.Value);
                    if (endereco.IdEstado.HasValue)
                    {
                        var tax = new TaxaService().GetByEstadoId(endereco.IdEstado.Value);
                        if (tax != null && tax.Taxa.HasValue && carrinho.ValorSubtotal > 0)
                            carrinho.ValorTaxas = Decimal.Round(((carrinho.ValorSubtotal / 100) * tax.Taxa.Value), 2);
                    }
                }

                return View(carrinho);
            }
            else
            {
                return RedirectToAction("Index", "Account");
            }
        }
Exemplo n.º 17
0
 public ActionResult OrderAddress(int idPedido)
 {
     var enderecoPedido = new EnderecoService().GetShippingAddress(idPedido);
     return PartialView(enderecoPedido);
 }