public ActionResult Index()
        {
            SaleWrapVM model = new SaleWrapVM();

            model.Cart             = new CartVM();
            model.Customer         = new CustomerVM();
            model.Cart.ProductList = new List <ProductVM>();
            if (Session["Sepet"] != null)
            {
                model.Cart = (CartVM)Session["Sepet"];
            }
            GetCustomersAndUsers();
            GetAllCitiesforAdding();
            return(View(model));
        }
        public ActionResult Index(string BarcodeNumber)
        {
            GetCustomersAndUsers();
            GetAllCitiesforAdding();
            SaleWrapVM model = new SaleWrapVM();

            model.Cart             = new CartVM();
            model.Customer         = new CustomerVM();
            model.Cart.ProductList = new List <ProductVM>();
            if (!string.IsNullOrEmpty(BarcodeNumber))
            {
                var product = rpproduct.FirstOrDefault(x => x.SerialNumber == BarcodeNumber && x.Count != 0);
                if (product != null)
                {
                    if (product.Count != 0)
                    {
                        product.Count -= 1;
                        rpproduct.SaveChanges();

                        bool varMi = false;

                        if (Session["Sepet"] != null)
                        {
                            model.Cart = (CartVM)Session["Sepet"];
                            foreach (var item in model.Cart.ProductList)
                            {
                                if (item.SerialNumber == BarcodeNumber)
                                {
                                    item.SaleCount++;
                                    item.Count                 = product.Count;
                                    varMi                      = true;
                                    item.UnitSalePrice         = item.UnitPrice * item.SaleCount;
                                    item.KdvPrice              = Math.Round(item.UnitSalePrice * item.KDV, 4);
                                    item.TotalPrice            = 0;
                                    model.Cart.TotalSalePrice += item.TotalPrice / item.SaleCount;
                                    if (item.CategoryID == 6 || item.CategoryID == 7)
                                    {
                                        model.Cart.PhoneCount++;
                                        model.Cart.ImeiCount = AddedImeiCount(model.Cart.ProductList);
                                    }
                                    break;
                                }
                            }
                        }

                        if (!varMi)
                        {
                            ProductVM pro = new ProductVM()
                            {
                                ID            = product.ID,
                                SerialNumber  = product.SerialNumber,
                                TradeMark     = rptrademark.Find(product.TradeMarkID).Name,
                                ProductModel  = product.ProductModelID == 0 ? "" : rpproductmodel.Find(product.ProductModelID).Name,
                                Color         = rpcolor.Find(product.ColorID).Name,
                                UnitSalePrice = product.UnitSalePrice, //satış fiyatı değişken
                                UnitPrice     = product.UnitSalePrice, //satış fiyatı
                                //UnitBuyPrice = product.UnitPrice,//alış fiyatı
                                Count      = product.Count,
                                CategoryID = product.CategoryID,
                                SaleCount  = 1,
                                KDV        = product.KDV,
                                KdvPrice   = Math.Round((product.UnitSalePrice * product.KDV), 4),
                                ImeiList   = new List <int>()
                            };

                            model.Cart.ProductList.Add(pro);
                            model.Cart.TotalSalePrice += pro.TotalPrice;
                            if (pro.CategoryID == 6 || pro.CategoryID == 7)
                            {
                                model.Cart.PhoneCount++;
                                model.Cart.ImeiCount = AddedImeiCount(model.Cart.ProductList);
                            }
                        }
                        Session["Sepet"] = model.Cart;
                    }
                    else
                    {
                        if (Session["Sepet"] != null)
                        {
                            model.Cart = (CartVM)Session["Sepet"];
                        }
                        ViewBag.IslemDurum = EnumIslemDurum.StokYetersiz;
                        return(View(model));
                    }
                }
                else
                {
                    if (Session["Sepet"] != null)
                    {
                        model.Cart = (CartVM)Session["Sepet"];
                    }
                    ViewBag.IslemDurum = EnumIslemDurum.UrunYok;
                    return(View(model));
                }
            }
            return(View(model));
        }