Ejemplo n.º 1
0
        public ActionResult SepetItemSil(int id)
        {
            BasketClass s = (BasketClass)Session["AktifSepet"];

            try
            {
                if (_loginState.IsLogin())
                {
                    Basket       basket = db.Baskets.FirstOrDefault(x => x.BasketKey == s.BasketKey);
                    OrderProduct detays = db.OrderProducts.FirstOrDefault(x => x.ProductId == id && x.BasketId == s.BasketId && x.InTheBasket);
                    if (detays != null)
                    {
                        db.OrderProducts.Remove(detays);
                        OrderProductProperty productProperty =
                            db.OrderProductProperties.FirstOrDefault(x => x.OrderProductId == detays.Id);
                        if (productProperty != null)
                        {
                            db.OrderProductProperties.Remove(productProperty);
                        }
                    }

                    db.SaveChanges();
                    s                      = (BasketClass)Session["AktifSepet"];
                    basket.Amount          = s.TotalAmount;
                    db.Entry(basket).State = EntityState.Modified;
                    db.SaveChanges();
                }
                s.BasketItemRemove(id);
            }
            catch (Exception e)
            {
                s.AllClear();
            }
            return(Redirect("/Sepetim"));
        }
Ejemplo n.º 2
0
        public ActionResult BasketComplete()
        {
            BasketClass s = (BasketClass)Session["AktifSepet"];

            if (s != null)
            {
                if (s.Products.Count != 0)
                {
                    if (_loginState.IsLogin())
                    {
                        foreach (var item in s.Products)
                        {
                            Product product = db.Products.FirstOrDefault(x => x.Id == item.Product.Id);
                            if (product.Stock == 0)
                            {
                                OrderProduct orderProduct = db.OrderProducts.FirstOrDefault(
                                    x => x.BasketId == s.BasketId && x.ProductId == item.Product.Id);
                                db.OrderProducts.Remove(orderProduct);
                                s.BasketItemRemove(product.Id);
                                db.OrderProducts.Remove(orderProduct);
                                if (s.Products.Count == 0)
                                {
                                    break;
                                }
                            }
                            else if (product != null && product.Stock < item.Quantity)
                            {
                                ViewBag.ResultType    = "danger";
                                ViewBag.ResultMessage = "Eklediğiniz ürün adeti stoklarda bulunmamaktadır. Sepetiniz Düzenlendi.";

                                s.BasketItems.FirstOrDefault(x => x.Product.Id == item.Product.Id).Quantity =
                                    product.Stock;
                                Session["AktifSepet"] = s;
                                s = (BasketClass)Session["AktifSepet"];
                                OrderProduct orderProduct = db.OrderProducts.FirstOrDefault(
                                    x => x.BasketId == s.BasketId && x.ProductId == item.Product.Id);
                                orderProduct.Quantity        = product.Stock;
                                orderProduct.Amount          = (double)(orderProduct.Quantity * product.Price);
                                db.Entry(orderProduct).State = EntityState.Modified;

                                //BasketClass.BasketItem basketItem = new BasketClass.BasketItem();
                                //basketItem = s.BasketItems.FirstOrDefault(x => x.Product.Id == item.Product.Id);
                            }
                            db.SaveChanges();
                        }

                        return(Redirect("/Sepet/Tamamla/Adres"));
                    }
                    else
                    {
                        return(Redirect("/Kullanici/Giris/Sepet"));
                    }
                }
                else
                {
                    return(Redirect("Sepetim"));
                }
            }

            return(View());
        }