Пример #1
0
        public ActionResult Index()
        {
            if (_loginState.IsLogin())
            {
                User user = _loginState.IsLoginUser();
                //GirisSepetControl();
                var model = db.UserAddresses.Where(x => x.UserId == user.Id).ToList();
                List <UserAddress> addresses = model;
                ViewBag.AddressList = addresses;
            }

            return(View((BasketClass)HttpContext.Session["AktifSepet"]));
        }
        // GET: UserAddresses
        public ActionResult Index()
        {
            List <UserAddress> userAddresses = null;

            if (_loginState.IsLogin())
            {
                User user = _loginState.IsLoginUser();
                userAddresses = db.UserAddresses.Where(x => x.UserId == user.Id).ToList();
            }

            return(View(userAddresses));
        }
Пример #3
0
        public void GirisSepetControl()
        {
            Basket basket = new Basket();

            BasketClass basketClass = (BasketClass)HttpContext.Current.Session["AktifSepet"];

            if (_loginState.IsLogin())
            {
                int id = _loginState.IsLoginUser().Id;
                basket = db.Baskets.FirstOrDefault(x => x.UserId == id && x.StatusId == 1);
            }
            else
            {
                basket = db.Baskets.FirstOrDefault(x => x.BasketKey == basketClass.BasketKey);
            }
            if (basketClass != null)
            {
                if (basket == null)
                {
                    basket          = new Basket();
                    basket.StatusId = 1;
                    if (_loginState.IsLogin())
                    {
                        basket.UserId       = _loginState.IsLoginUser().Id;
                        basket.CreateUserId = _loginState.IsLoginUser().Id;
                    }
                    else
                    {
                        basket.UserId       = -1;
                        basket.CreateUserId = -1;
                    }
                    basket.CreateDateTime = DateTime.Now;
                    basket.Amount         = basketClass.TotalAmount;
                    basket.BasketKey      = basketClass.BasketKey;
                    db.Baskets.Add(basket);
                    db.SaveChanges();
                }
                else
                {
                    List <OrderProduct> dbOrderProduct = db.OrderProducts
                                                         .Where(x => x.BasketId == basket.Id).ToList();
                    if (dbOrderProduct.Count != 0)
                    {
                        foreach (var item in dbOrderProduct)
                        {
                            Product product = db.Products.Find(item.ProductId);
                            BasketClass.BasketItem basketItem = new BasketClass.BasketItem();
                            basketItem.Product  = product;
                            basketItem.Quantity = item.Quantity;
                            basketItem.Tax      = 0;
                            basketClass.SepeteEkle(basketItem);
                            db.OrderProducts.Remove(item);
                            OrderProductProperty orderProductProperty = new OrderProductProperty();
                            orderProductProperty =
                                db.OrderProductProperties.FirstOrDefault(x => x.OrderProductId == item.Id);
                            if (orderProductProperty != null)
                            {
                                db.OrderProductProperties.Remove(orderProductProperty);
                            }
                            db.SaveChanges();
                        }
                    }
                    if (_loginState.IsLogin())
                    {
                        basket.UserId       = _loginState.IsLoginUser().Id;
                        basket.CreateUserId = _loginState.IsLoginUser().Id;
                    }
                    basketClass            = (BasketClass)HttpContext.Current.Session["AktifSepet"];
                    basket.Amount          = basketClass.TotalAmount;
                    db.Entry(basket).State = EntityState.Modified;
                    db.SaveChanges();
                }
                OrderProductControl(basket, basketClass);
            }
            else
            {
                if (basket != null)
                {
                    List <OrderProduct> dbOrderProduct = db.OrderProducts
                                                         .Where(x => x.BasketId == basket.Id).ToList();
                    if (dbOrderProduct.Count != 0)
                    {
                        basketClass = new BasketClass();
                        foreach (var item in dbOrderProduct)
                        {
                            BasketClass.BasketItem basketItem = new BasketClass.BasketItem();
                            Product product = db.Products.FirstOrDefault(x => x.Id == item.ProductId);
                            basketItem.Product  = product;
                            basketItem.Quantity = item.Quantity;
                            basketItem.Tax      = 0;
                            //var productPropertyList = db.prod.Include(x=>x.PropertyPropertyValues).Where(x => x.OrderProductId == item.Id).ToList();
                            //basketItem.PropertyPropertyValueses = productPropertyList;
                            //foreach (var productProperty in productPropertyList)
                            //{
                            //    basketItem.PropertyPropertyValueses.Add(productProperty.PropertyPropertyValues);

                            //}
                            //todo:Ürün özellikleri veri tabanından sepete aktarılacak
                            basketClass.SepeteEkle(basketItem);
                        }
                    }
                    basketClass = (BasketClass)HttpContext.Current.Session["AktifSepet"];
                    //basketClass = (BasketClass)HttpContext.Current.Session["AktifSepet"];
                    //basketClass = new BasketClass();
                    if (basketClass == null)
                    {
                        basketClass = new BasketClass();
                    }
                    basketClass.BasketId  = basket.Id;
                    basketClass.BasketKey = basket.BasketKey;
                    basketClass.UserId    = basket.UserId;
                    HttpContext.Current.Session["AktifSepet"] = basketClass;
                }
            }
        }