public ActionResult UpdateBill(ICollection<Senef> Seneflist)
        {

            int BillID = Convert.ToInt16(TempData["BillID"]);
            int id = 0;
            string type = "";
            int companyId = 0;
            bool checke = false;
            decimal total = 0;
            List<Senef> Temp = new List<Senef>();
            foreach (Senef se in Seneflist)
            {
                Senef tempee = new Senef();
                checke = se.needthis;
                if (checke == true)
                {
                    Senef Senoof = db.Senef.Where(s => s.FirstName.Equals(se.FirstName)).FirstOrDefault();
                    if (Senoof == null)
                    {
                        return new HttpStatusCodeResult(HttpStatusCode.BadRequest);

                    }
                    tempee.SenefId = Senoof.SenefId;
                    tempee.FirstName = se.FirstName;
                    tempee.Quantity = se.Quantity;
                    if (se.ChangePrice == true)
                    {
                        tempee.Price = se.NewPrice;
                        total = total + (se.NewPrice * se.Quantity);
                    }
                    else
                    {


                        tempee.Price = Senoof.Price;
                        total = total + (Senoof.Price * se.Quantity);
                    }
                    id = id + 1;
                    type = se.BillType;
                    Temp.Add(tempee);
                    

                }

            }
            companyId = db.BillCompany.Where(p => p.BillCompanyId == BillID).FirstOrDefault().CompanyId;

            if (companyId == null)
            {
                return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
            }

            var company2 = db.Company.Find(companyId);
            if (company2 == null)
            {
                return HttpNotFound();
            }


            var order = db.BillCompany.Find(BillID);
            if (order == null)
                return HttpNotFound();
            TryUpdateModel(order);
            try
            {



                order.Total = order.Total + total;
                ////Save Order
                db.Entry(order).State = EntityState.Modified;
                db.SaveChanges();
                ////Process the order


                int idds = CreateOrder(Temp, order);

                return RedirectToAction("Index", "OrderDetailsCompanies", new { Id = order.BillCompanyId, ClientId = order.CompanyId });

            }
            catch
            {
                //Invalid - redisplay with errors
                return View(order);
            }



        }
        public ActionResult Create(ICollection<Senef> Seneflist)
        {
              
            int CompanyId = 0;
       
            bool checke = false;
            decimal total = 0;
            List<Senef> Temp = new List<Senef>();
            foreach (Senef se in Seneflist)
            {
           
                Senef tempee = new Senef();
                checke = se.needthis;
                if (checke == true)
                {
                    Senef Senoof = db.Senef.Where(s => s.FirstName.Equals(se.FirstName)).FirstOrDefault();
                    if (Senoof == null)
                    {
                        return new HttpStatusCodeResult(HttpStatusCode.BadRequest);

                    }
                    tempee.SenefId = Senoof.SenefId;
                    tempee.FirstName = se.FirstName;
                    tempee.Quantity = se.Quantity;
                    if (se.ChangePrice == true)
                    {
                        tempee.Price = se.NewPrice;
                        total = total + (se.NewPrice * se.Quantity);
                    }
                    else
                    {


                        tempee.Price = Senoof.Price;
                        total = total + (Senoof.Price * se.Quantity);
                    }
                    
              
                    Temp.Add(tempee);
                    CompanyId = se.ClientID;

                }

            }


            if (CompanyId == null)
            {
                return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
            }

            var company = db.Company.Find(CompanyId);
            if (company == null)
            {
                return HttpNotFound();
            }


            var order = new BillCompany();
            TryUpdateModel(order);

            try
            {

                order.MoneyType = Seneflist.FirstOrDefault().MoneyType;
                order.cashtype = Seneflist.FirstOrDefault().cashtype;
                order.BillType = Seneflist.FirstOrDefault().BillType;
                order.FirstName = company.FirstName;
                

                order.Phone = company.Phone;
                

                order.CompanyId = company.CompanyId;
                order.OrderDate = DateTime.Now.AddHours(10);

                order.Total = total;
                ////Save Order
                db.BillCompany.Add(order);
                db.SaveChanges();
                ////Process the order


                int idds = CreateOrder(Temp, order);

                return RedirectToAction("Index", "OrderDetailsCompanies", new { Id = order.BillCompanyId, ClientId = CompanyId });

            }
            catch
            {
                //Invalid - redisplay with errors
                return View(order);
            }








            //if (ModelState.IsValid)
            //{

            //    db.BillClient.Add(billClient);
            //    db.SaveChanges();
            //    return RedirectToAction("Index");
            //}

            //ViewBag.ClientId = new SelectList(db.Client, "ClientId", "Title", billClient.ClientId);
            //return View();
        }
        public ActionResult CreatEysal(Senef Seneflist)
        {
            int clientId = 0;
            decimal total = 0;
            List<Senef> Temp = new List<Senef>();
            Senef tempee = new Senef();

            Senef Senoof = db.Senef.Where(s => s.FirstName.Equals(Seneflist.FirstName)).FirstOrDefault();
            if (Senoof == null)
            {
                return new HttpStatusCodeResult(HttpStatusCode.BadRequest);

            }
            tempee.SenefId = Senoof.SenefId;
            tempee.FirstName = Seneflist.BillType;
            tempee.Quantity = Seneflist.Quantity;
            tempee.Price = Senoof.Price;
            total = Seneflist.Quantity;

            Temp.Add(tempee);
            clientId = Seneflist.ClientID;


            if (clientId == null)
            {
                return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
            }

            var client = db.Company.Find(clientId);
            if (client == null)
            {
                return HttpNotFound();
            }


            var order = new BillCompany();
            TryUpdateModel(order);

            try
            {

                order.MoneyType = Seneflist.MoneyType;
                order.cashtype = "منه / مدين";
                order.BillType = "ايصال";
                order.FirstName = client.FirstName;
               

                order.Phone = client.Phone;


                order.CompanyId = client.CompanyId;
                order.OrderDate = DateTime.Now.AddHours(10);

                order.Total = total;
                ////Save Order
                db.BillCompany.Add(order);
                db.SaveChanges();
                ////Process the order


                int idds = CreateOrder(Temp, order);

                return RedirectToAction("Index", "OrderDetailsCompanies", new { Id = order.BillCompanyId, ClientId = client.CompanyId });

            }
            catch
            {
                //Invalid - redisplay with errors
                return View(order);
            }
        }