Beispiel #1
0
        public ActionResult Create(int id)
        {
            var cookie = Request.Cookies[".AspNet.ApplicationCookie"].Value;
            var cp     = new CartProcess();
            var cart   = cp.Cookie(cookie);

            if (cart == null)
            {
                cp.Insert(new Cart()
                {
                    CartDate = DateTime.Now,
                    Cookie   = cookie
                });
                cart = cp.Cookie(cookie);
            }
            var pp  = new ProductProcess();
            var prd = pp.Find(id);

            ViewBag.Descripcion = prd.Description;
            ViewBag.Nombre      = prd.Title;
            ViewBag.Imagen      = prd.Image;
            ViewBag.Precio      = prd.Price;
            ViewBag.ProductId   = id;

            var item = new CartItem();

            item.CartId    = cart.Id;
            item.ProductId = id;
            item.Price     = prd.Price;
            item.Quantity  = 1;


            return(View(item));
        }
Beispiel #2
0
        public ActionResult Index()
        {
            var cookie = Request.Cookies[".AspNet.ApplicationCookie"].Value;
            var cp     = new CartProcess();
            var cart   = cp.Cookie(cookie);

            if (cart == null)
            {
                //VER QUE HACER CUANDO EL CARRITO NO EXISTE
                cart    = new Cart();
                cart.Id = 0;
            }


            var cip           = new CartItemProcess();
            var lista         = cip.FindByCartId(cart.Id);
            var total         = 0.0;
            var parcial       = 0.0;
            var CantidadTotal = 0;

            foreach (CartItem item in lista)
            {
                parcial       = item.Price * item.Quantity;
                total         = total + parcial;
                CantidadTotal = CantidadTotal + item.Quantity;
            }
            ViewBag.Cantidad = CantidadTotal;
            ViewBag.total    = total;
            ViewBag.cartid   = cart.Id;
            return(View(lista));
        }
Beispiel #3
0
        //// GET: Products/Product
        //[Authorize]
        public ActionResult ProductList(int Category = -1)
        {
            if (User.Identity.IsAuthenticated == true)
            {
                var cookie = Request.Cookies[".AspNet.ApplicationCookie"].Value;
                var cp     = new CartProcess();
                var cart   = cp.Cookie(cookie);
                if (cart == null)
                {
                    ViewBag.Cantidad = 0;
                }

                else
                {
                    var cip           = new CartItemProcess();
                    var listaItems    = cip.FindByCartId(cart.Id);
                    var CantidadTotal = 0;
                    foreach (CartItem item in listaItems)
                    {
                        CantidadTotal = CantidadTotal + item.Quantity;
                    }
                    ViewBag.Cantidad = CantidadTotal;
                }
            }
            else
            {
                ViewBag.Cantidad = 0;
            }

            var cp2 = new CategoryProcess();
            var pp  = new ProductProcess();

            ViewData["Category"] = cp2.SelectList();
            var lista = new List <Product>();


            if (Category > -1)
            {
                lista = pp.SelectByCat(Category);
            }

            return(View(lista));
        }