public void SepeteEkle(BasketItem basketItem)
        {
            if (HttpContext.Current.Session["AktifSepet"] != null)
            {
                BasketClass s = (BasketClass)HttpContext.Current.Session["AktifSepet"];
                if (basketItem.Product != null)
                {
                    if (s.Products.Any(x => x.Product.Id == basketItem.Product.Id))
                    {
                        s.Products.FirstOrDefault(x => x.Product.Id == basketItem.Product.Id).Quantity = s.Products.FirstOrDefault(x => x.Product.Id == basketItem.Product.Id).Quantity + basketItem.Quantity;
                    }
                    else
                    {
                        s.Products.Add(basketItem);
                    }
                }

                else
                {
                    //tblSiparis siparisKontrol = db.tblSiparis.FirstOrDefault(x => x.MusteriId == musteriId);
                    s.Products.Add(basketItem);
                }
            }
            else
            {
                BasketClass s = new BasketClass();
                s.BasketKey = RandomBasketKey(8);
                s.Products.Add(basketItem);
                HttpContext.Current.Session["AktifSepet"] = s;
            }
        }
        public void BasketItemUpdate(int id, int adet)
        {
            BasketClass s  = (BasketClass)HttpContext.Current.Session["AktifSepet"];
            BasketItem  si = s.Products.FirstOrDefault(x => x.Product.Id == id);

            if (s.Products.Any(x => x.Product.Id == si.Product.Id))
            {
                s.Products.FirstOrDefault(x => x.Product.Id == si.Product.Id).Quantity = adet;
            }
            HttpContext.Current.Session["AktifSepet"] = s;
        }
        public void BasketItemRemove(int id)
        {
            BasketClass s = (BasketClass)HttpContext.Current.Session["AktifSepet"];

            if (s != null)
            {
                BasketItem si = s.Products.FirstOrDefault(x => x.Product.Id == id);
                s.Products.Remove(si);
                HttpContext.Current.Session["AktifSepet"] = s;
            }

            //tblSiparisDetay siparisDetay=db.tblSiparisDetay.Where(x=>x.Urun==id&&x.siparis==)
        }
        public void OrderProductControl(Basket basket, BasketClass basketClass)
        {
            int id = _loginState.IsLoginUser().Id;

            foreach (var item in basketClass.Products)
            {
                OrderProduct orderProduct = new OrderProduct();
                orderProduct.CreateDateTime = DateTime.Now;
                orderProduct.CreateUserId   = _loginState.IsLoginUser().Id;
                orderProduct.BasketId       = basket.Id;
                orderProduct.InTheBasket    = true;
                orderProduct.ProductId      = item.Product.Id;
                orderProduct.UserId         = _loginState.IsLoginUser().Id;
                orderProduct.Quantity       = item.Quantity;
                orderProduct.Amount         = (double)item.Total;
                db.OrderProducts.Add(orderProduct);
                db.SaveChanges();
                if (item.PropertyPropertyValueses != null)
                {
                    foreach (var propertyValuese in item.PropertyPropertyValueses)
                    {
                        OrderProductProperty productProperty = new OrderProductProperty();
                        productProperty.OrderProductId           = orderProduct.Id;
                        productProperty.PropertyPropertyValuesId = propertyValuese.Id;
                        productProperty.CreateDateTime           = DateTime.Now;
                        productProperty.CreateUserId             = _loginState.IsLoginUser().Id;
                        db.OrderProductProperties.Add(productProperty);
                        db.SaveChanges();
                    }
                }
            }

            //var basketItem = basketClass.BasketItems.Select(x => x.PropertyPropertyValueses);
            //foreach (var item in basketItem)
            //{
            //    if (item.Count > 0)
            //    {
            //        OrderProductProperty productProperty = new OrderProductProperty();
            //        foreach (var propertyValuese in item)
            //        {
            //            //productProperty.OrderProductId = orderProduct.Id;
            //            //productProperty.ProductPropertyId = propertyValuese.Id;
            //        }
            //        db.SaveChanges();
            //        //productProperty.OrderProductId=item.
            //    }
            //}
        }
        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;
                }
            }
        }