Exemplo n.º 1
0
        public string AddCart(int id)
        {
            //Sepet varsa,gelen ürünün varolan sepete ekle,sepet yoksa önce aktif session için(oturum) için sepet oluştur ve sepete gelen ürünü ekle

            string    cartMessage = "";
            CartClass crt;

            if (Session["CurrentCart"] == null)
            {
                crt = new CartClass(); //yeni sepet oluşturuluyor.
            }
            else
            {
                crt = (CartClass)Session["CurrentCart"]; //eğer sepet varsa
            }

            foreach (Product p in crt.PrdList)
            {
                if (p.ProductID == id)
                {
                    cartMessage = "Eklemek istediğiniz sepette mevcut.";
                    return(cartMessage);
                }
            }
            Product prd = db.Products.FirstOrDefault(x => x.ProductID == id); //Producttan o id'li ürünü bul

            crt.PrdList.Add(prd);
            Session["CurrentCart"] = crt;
            cartMessage            = "Ürün sepete başarıyla eklendi";

            return(cartMessage);
        }
        public ActionResult PartialProductCountNav()
        {
            CartClass c = (CartClass)Session["CurrentCart"];
            int       n = c.PrdList.Count();

            return(PartialView(c.PrdList));
            //return PartialView(Session["CurrentCart"] as CartClass);
        }
Exemplo n.º 3
0
 public ActionResult PartialCartListView()
 {
     if (Session["CurrentCart"] != null)
     {
         CartClass c = (CartClass)Session["CurrentCart"];
         return(PartialView(c.PrdList));
     }
     return(PartialView());
 }
Exemplo n.º 4
0
        public RedirectToActionResult RemoveFromCart(int id, string returnUrl)
        {
            CartClass cartClass = new CartClass("Cart", repository, HttpContext);

            /* Product product = repository.Products
             *   .FirstOrDefault(g => g.Id == id);
             *
             * if (product != null)
             * {
             *   GetCart().RemoveLine(product);
             * }*/
            cartClass.RemoveFromCart(id, returnUrl);
            return(RedirectToAction("Index", "Cash"));
        }
Exemplo n.º 5
0
        public RedirectToActionResult AddToCart(int id, string returnUrl)
        {
            CartClass cartClass = new CartClass("Cart", repository, HttpContext);

            /* Product product = repository.Products
             *   .FirstOrDefault(g => g.Id == id);
             *
             * if (product != null)
             * {    Cart cart = GetCart();
             *   cart.AddItem(product, 1);
             *   HttpContext.Session.Set("Cart", cart);
             * }*/
            cartClass.AddToCart(id, returnUrl);
            return(RedirectToAction("Index", "Cash"));
        }
Exemplo n.º 6
0
        public string RemoveCart(int id)
        {
            //Sepet varsa,gelen ürünün varolan sepete ekle,sepet yoksa önce aktif session için(oturum) için sepet oluştur ve sepete gelen ürünü ekle

            string cartMessage = "";

            CartClass crt = (CartClass)Session["CurrentCart"];
            Product   prd = db.Products.FirstOrDefault(x => x.ProductID == id); //Producttan o id'li ürünü bul

            //crt.PrdList.Remove(prd);

            crt.PrdList.RemoveAll(x => x.ProductID == id);
            Session["CurrentCart"] = crt;
            cartMessage            = "Ürün sepetten çıkarılmıştır. ";
            return(cartMessage);
        }
Exemplo n.º 7
0
        public ActionResult Category(int Id)
        {
            int        IdEnterprise = int.Parse(User.Claims.ToList()[1].Value);
            Enterprise Enterprise   = _context.Enterprises.Find(IdEnterprise);
            string     NameCategory = "baseCategory." + Enterprise.Name;
            string     pointId      = HttpContext.Request.Cookies["BasePoint"];

            if (pointId == null)
            {
                User user = _context.Users.FirstOrDefault(s => s.Login == User.Identity.Name);
                if (_context.User_Roles.Where(p => p.UserId == user.Id && p.Role.Name == "admin") != null)
                {
                    ViewBag.Points = _context.PointOfSales.Where(p => p.EnterpriseId == IdEnterprise);
                }
                else
                {
                    var   user_point = _context.User_Points.Where(p => p.UserId == user.Id).ToList();
                    int[] arrP       = new int[user_point.Count];
                    for (int i = 0; i < user_point.Count; i++)
                    {
                        arrP[i] = user_point[i].PointId;
                    }
                    ViewBag.Points = _context.PointOfSales.Find(arrP);
                }
                return(View());
            }
            var cat1 = _context.Categories.Find(Id);

            if (cat1.Name == NameCategory)
            {
                return(RedirectToAction("Index", "Cash"));
            }
            var categories = _context.Categories.Where(p => p.EnterpriseId == IdEnterprise && p.ParentCategory.Name == cat1.Name).ToList();
            var products   = _context.Products.Where(p => p.ParCategory.EnterpriseId == IdEnterprise && p.ParCategory.Name == cat1.Name).ToList();

            ViewBag.categ         = categories;
            ViewBag.prod          = products;
            ViewBag.ParentCatName = cat1.Name;
            ViewBag.ParentCatId   = _context.Categories.First(p => p.Name == cat1.ParentCategory.Name).Id;
            CartClass cartClass = new CartClass("Cart", _context, HttpContext);

            ViewBag.Cart = cartClass.GetCart().Lines;
            return(View("Index"));
        }
Exemplo n.º 8
0
        public ActionResult MyCart()
        {
            //List<Product> myCartList =new List<Product>();

            CartClass crt;

            if (Session["CurrentCart"] != null)
            {
                crt = (CartClass)Session["CurrentCart"];
                //myCartList = crt;
            }
            else
            {
                crt = new CartClass();
            }

            Session["CurrentCart"] = crt;
            return(View());
        }
Exemplo n.º 9
0
        public RedirectToActionResult Buy()
        {
            CartClass cartClass = new CartClass("Cart", _context, HttpContext);
            var       carts     = cartClass.GetCart().Lines;
            int       pointId   = int.Parse(HttpContext.Request.Cookies["BasePoint"]);
            User      user      = _context.Users.FirstOrDefault(s => s.Login == User.Identity.Name);
            Sales     newSale   = new Sales {
                Date = DateTime.Now, PointOfSaleId = pointId, UserId = user.Id
            };

            _context.Sales.Add(newSale);
            _context.SaveChanges();
            foreach (var el in carts)
            {
                _context.Sales_Products.Add(new Sales_Product {
                    SaleId = newSale.Id, ProductId = el.Product.Id, Price = el.Product.SellingPrice, Count = el.Quantity
                });
                //Add(new Sales { ProductId = el.Product.Id, Quantity = el.Quantity, Price = el.Product.SellingPrice, PointOfSaleId= pointId,Date=DateTime.Now,UserId=user.Id });
            }
            cartClass.Clear();
            _context.SaveChanges();
            return(RedirectToAction("Index"));
        }