Exemplo n.º 1
0
        public ActionResult RemoverItem(int id_produto = 0)
        {
            List <int?> produtos_carrinho = new List <int?>();

            produtos_carrinho.Add(id_produto);
            if (System.Web.HttpContext.Current.Session["ids_produtos_carrinho"] != null)
            {
                produtos_carrinho = System.Web.HttpContext.Current.Session["ids_produtos_carrinho"] as List <int?>;
                if (produtos_carrinho.Contains(id_produto))
                {
                    produtos_carrinho.Remove(id_produto);
                }

                if (!produtos_carrinho.Any())
                {
                    System.Web.HttpContext.Current.Session["ids_produtos_carrinho"] = null;
                }
                else
                {
                    System.Web.HttpContext.Current.Session["ids_produtos_carrinho"] = produtos_carrinho;
                }
            }

            ModelView.ModelCarrinho carrinho = new ModelView.ModelCarrinho();
            carrinho = bcarrinho.Get(produtos_carrinho);
            return(View("~/Views/Home/Carrinho.cshtml", carrinho));
        }
Exemplo n.º 2
0
        // GET: Pagamento
        public ActionResult EfetuarPagamento()
        {
            if (System.Web.HttpContext.Current.Session["nome_comprador"] == null)
            {
                return(View("~/Views/Cadastro/MinhaConta.cshtml"));
            }
            else if (System.Web.HttpContext.Current.Session["ids_produtos_carrinho"] == null)
            {
                return(View("~/Views/Home/Carrinho.cshtml"));
            }

            List <int?> produtos_carrinho = new List <int?>();

            produtos_carrinho = System.Web.HttpContext.Current.Session["ids_produtos_carrinho"] as List <int?>;

            ModelView.ModelCarrinho carrinho = new ModelView.ModelCarrinho();
            carrinho = bcarrinho.Get(produtos_carrinho);

            ModelView.ModelPagamento pagamento = new ModelView.ModelPagamento();
            pagamento.lista_produtos = carrinho.lista_produtos;
            pagamento.preco_carrinho = carrinho.preco_carrinho;
            pagamento.total          = carrinho.total;

            return(View("~/Views/Home/Pagamento.cshtml", pagamento));
        }
Exemplo n.º 3
0
        public ActionResult LimparCarrinho(int id_produto = 0)
        {
            List <int?> produtos_carrinho = new List <int?>();

            produtos_carrinho.Add(id_produto);
            if (System.Web.HttpContext.Current.Session["ids_produtos_carrinho"] != null)
            {
                System.Web.HttpContext.Current.Session["ids_produtos_carrinho"] = null;
            }

            ModelView.ModelCarrinho carrinho = new ModelView.ModelCarrinho();
            carrinho = bcarrinho.Get(produtos_carrinho);
            return(View("~/Views/Home/Carrinho.cshtml", carrinho));
        }
Exemplo n.º 4
0
 public bool Editar(ModelView.ModelCarrinho carrinho)
 {
     try
     {
         CarrinhoDAO c         = new CarrinhoDAO();
         var         _carrinho = Mapper.Map <Entities.Carrinho>(carrinho);
         return(c.Salvar(_carrinho));
     }
     catch (Exception)
     {
         throw new NotImplementedException();
         return(false);
     }
 }
Exemplo n.º 5
0
        public ActionResult FecharCompra(ModelView.ModelPagamento _pagamento)
        {
            List <int?> produtos_carrinho = new List <int?>();

            produtos_carrinho = System.Web.HttpContext.Current.Session["ids_produtos_carrinho"] as List <int?>;

            ModelView.ModelCarrinho carrinho = new ModelView.ModelCarrinho();
            carrinho = bcarrinho.Get(produtos_carrinho);

            ModelView.ModelPagamento pagamento = new ModelView.ModelPagamento();
            pagamento.lista_produtos = carrinho.lista_produtos;
            pagamento.preco_carrinho = carrinho.preco_carrinho;
            pagamento.total          = carrinho.total;
            var nome_comprador = System.Web.HttpContext.Current.Session["nome_comprador"];
            int id_comprador   = Convert.ToInt32(System.Web.HttpContext.Current.Session["id_comprador"]);

            var novo_pedido = bpedido.Builder(pagamento.preco_carrinho, pagamento.total, id_comprador, carrinho.lista_produtos);

            if (novo_pedido != null)
            {
                if (!bpedido.Criar(novo_pedido))
                {
                    ModelState.AddModelError("ErroPagamento", "Ocorreu um erro ao finalizar a compra por favor tente novamente");
                    return(View("~/Views/Home/Pagamento.cshtml", pagamento));
                }
                else
                {
                    System.Web.HttpContext.Current.Session["ids_produtos_carrinho"] = null;

                    var pedidos = bpedido.ListarPorComprador(id_comprador);
                    ModelView.ModelPedidoLoja modelPedidoLoja = new ModelView.ModelPedidoLoja(pedidos.LastOrDefault());
                    modelPedidoLoja.comprador = bcomprador.Get(id_comprador);
                    return(View("~/Views/Cadastro/MeusPedidos.cshtml", modelPedidoLoja));
                }
            }

            return(View("~/Views/Home/Index.cshtml"));
        }