public async Task OnPostAddBillsProducts(string productid)
        {
            ProductBills p = new ProductBills();

            p.ProductCode = Convert.ToInt32(productid);
            p.UserId      = _UserManager.GetUserId(HttpContext.User);
            p.code        = "";
            DbContext.Add(p);
            await DbContext.SaveChangesAsync();
        }
        public async Task <IActionResult> Addproducttobill(string code)
        {
            ProductBills p = new ProductBills();

            p.ProductCode = Convert.ToInt32(code);
            p.UserId      = _UserManager.GetUserId(HttpContext.User);
            p.code        = "";
            //   p.Id = 457;
            await DbContext.ProductBills.AddAsync(p);

            await DbContext.SaveChangesAsync();

            return(Json(p));
        }
        public ActionResult Edit_bill(EditBillViewModel model)
        {
            //  var b = DbContext.ProductBills.Where(x => x.code == _UserManager.GetUserId(HttpContext.User) && x.code == "").ToList();
            string ids       = "";
            float  totalcost = 0;
            int    id        = model.products_ids[0];
            Bills  bill      = new Bills();

            bill.date     = model.bill.date;
            bill.Discount = model.bill.Discount;
            bill.Taxes    = model.bill.Taxes;
            bill.Id       = model.bill.Id;
            bill.user     = model.bill.user;


            // bill.cost = totalcost;
            bill.date  = DateTime.UtcNow.ToString();
            bill.Taxes = Convert.ToInt32(model.bill.Taxes);
            string UserId          = DbContext.ProductBills.Where(u => u.ProductCode == id).FirstOrDefault().UserId;
            var    removed_product = DbContext.ProductBills.Where(u => u.code == bill.Id.ToString()).ToList();

            foreach (var p in removed_product)
            {
                DbContext.ProductBills.Remove(p);
            }
            DbContext.SaveChanges();
            int j = 0;

            foreach (var p in model.products_ids)
            {
                for (int i = 0; i < model.products[j].Quantity; i++)
                {
                    ids += p + " ";
                    ProductBills pr = new ProductBills();
                    pr.code        = model.bill.Id.ToString();
                    pr.UserId      = UserId;
                    pr.ProductCode = p;
                    DbContext.ProductBills.Add(pr);
                }
                DbContext.SaveChanges();
                j++;
            }
            bill.products_ids = ids;
            string[] b = ids.Split(' ');
            foreach (var p in b)
            {
                if (p == "")
                {
                    continue;
                }


                Product p1 = DbContext.Store.Where(x => x.Id.ToString() == p).ToList()[0];

                totalcost += p1.SellingPrice;
            }
            float z  = 100;
            float tt = totalcost;
            int   y1 = (Convert.ToInt32(model.bill.Discount));
            float t  = y1 / z;
            float m  = (totalcost * t);

            totalcost -= m;
            y1         = Convert.ToInt32(model.bill.Taxes);
            t          = y1 / z;
            m          = (tt * t);
            totalcost += m;

            bill.cost = totalcost;
            DbContext.Bills.Update(bill);
            DbContext.SaveChanges();
            return(RedirectToAction("Bill", new { Bill_Id = bill.Id }));
        }