public ActionResult Edit(Tender_ModelCustomer2 tender_modelcustomer2)
 {
     if (ModelState.IsValid)
     {
         db.Entry(tender_modelcustomer2).State = EntityState.Modified;
         db.SaveChanges();
         return RedirectToAction("Index");
     }
     ViewBag.EmpGonggaoID = new SelectList(db.Bemp_GongGaos, "BGid", "BGid", tender_modelcustomer2.EmpGonggaoID);
     return View(tender_modelcustomer2);
 }
        public ActionResult Index(int id=0)
        {
            var tender_mcust = db.Tender_ModelCustomer2.Include(t => t.bemp_Gonggao).Where(mc => mc.bemp_Gonggao.GongGaoId == id);
            isSmall = isSmallByid(id);
            //第一次加载 生成客户初始数据
            if (tender_mcust.Count() <= 0)
            {
                List<Bemp_GongGao> list = db.Bemp_GongGaos.Include(b => b.bemplyees).Where(m => m.GongGaoId == id&&m.IsPassShen!=null&&m.IsPassShen==true).ToList();
                if (list.Count > 0)
                {
                    lock (this)
                    {
                        foreach (Bemp_GongGao bemp in list)
                        {
                            Tender_ModelCustomer2 cust = new Tender_ModelCustomer2();
                            cust.UserName = bemp.bemplyees.NumberEmp;
                            cust.LinkMan = bemp.bemplyees.LinkMan;
                            cust.LinkType = bemp.bemplyees.LinkType;
                            cust.EmpGonggaoID = bemp.BGid;
                            cust.PriceLost = 0;

                            db.Tender_ModelCustomer2.Add(cust);
                            //li.Add(cust);
                            db.Configuration.ValidateOnSaveEnabled = false;
                            db.SaveChanges();
                            db.Configuration.ValidateOnSaveEnabled = true;
                        }
                    }

                }
            }

            //找每轮最低价
            tender_mcust = db.Tender_ModelCustomer2.Include(t => t.bemp_Gonggao).Where(mc => mc.bemp_Gonggao.GongGaoId == id);
            ViewBag.PriceD = 0;

            tender_mcust = db.Tender_ModelCustomer2.Include(t => t.bemp_Gonggao).Where(mc => mc.bemp_Gonggao.GongGaoId == id && mc.PriceLost > 0);
            if (tender_mcust.Count() > 0)
            {
                if(isSmall)
                {
                    ViewBag.PriceD = tender_mcust.Min(m => m.PriceLost);
                }else
                {
                    ViewBag.PriceD = tender_mcust.Max(m => m.PriceLost);
                }

            }

            if(isSmall)
            {
                foreach (Tender_ModelCustomer2 custVar in tender_mcust.ToList<Tender_ModelCustomer2>())
                {
                    Bemp_GongGao bgong = db.Bemp_GongGaos.Find(custVar.EmpGonggaoID);
                    if (bgong.LostPrice == null || (custVar.PriceLost != 0 && bgong.LostPrice > custVar.PriceLost))
                    {
                        bgong.LostPrice = custVar.PriceLost;
                        db.Entry(bgong).State = EntityState.Modified;

                        db.SaveChanges();
                    }

                }
            }else
            {
                foreach (Tender_ModelCustomer2 custVar in tender_mcust.ToList<Tender_ModelCustomer2>())
                {
                    Bemp_GongGao bgong = db.Bemp_GongGaos.Find(custVar.EmpGonggaoID);
                    if (bgong.LostPrice == null || (custVar.PriceLost != 0 && bgong.LostPrice < custVar.PriceLost))
                    {
                        bgong.LostPrice = custVar.PriceLost;
                        db.Entry(bgong).State = EntityState.Modified;

                        db.SaveChanges();
                    }

                }
            }
            ViewBag.IsSmall = isSmall;
            tender_mcust = db.Tender_ModelCustomer2.Include(t => t.bemp_Gonggao).Where(mc => mc.bemp_Gonggao.GongGaoId == id);
            return View(tender_mcust.ToList());
        }
        public ActionResult Create(Tender_ModelCustomer2 tender_modelcustomer21)
        {
            if (ModelState.IsValid)
            {
                int ttid = db.Bemp_GongGaos.Single(n => n.BGid == tender_modelcustomer21.EmpGonggaoID).GongGaoId;
                isSmall = isSmallByid(ttid);

                Tender_ModelManage2 modelM = db.Tender_ModelManage2.Single(m => m.Tid == ttid);
                Tender_ModelCustomer2 tender_modelcustomer2 = db.Tender_ModelCustomer2.Single(m => m.EmpGonggaoID == tender_modelcustomer21.EmpGonggaoID);

                if(TimeSpan.Parse(modelM.BeginTime)<=System.DateTime.Now.TimeOfDay&&TimeSpan.Parse(modelM.EndTime)>=System.DateTime.Now.TimeOfDay)
                {
                    if(isSmall)
                    {
                        if (tender_modelcustomer2.PriceLost!=0&&tender_modelcustomer2.PriceLost <= tender_modelcustomer21.PriceLost)
                        {
                            return Content("价格必须小于上次报价~!");
                        }
                    }
                    else
                    {
                        if (tender_modelcustomer2.PriceLost != 0 && tender_modelcustomer2.PriceLost >= tender_modelcustomer21.PriceLost)
                        {
                            return Content("价格必须大于上次报价~!");
                        }
                    }

                        tender_modelcustomer2.PriceLost = tender_modelcustomer21.PriceLost;
                        tender_modelcustomer2.bemp_Gonggao.PayType = tender_modelcustomer21.bemp_Gonggao.PayType;
                        tender_modelcustomer2.bemp_Gonggao.HandDate = tender_modelcustomer21.bemp_Gonggao.HandDate;
                        Bemp_GongGao bemp = tender_modelcustomer2.bemp_Gonggao;

                        db.Entry(tender_modelcustomer2).State = EntityState.Modified;
                        db.Configuration.ValidateOnSaveEnabled = false;
                        db.SaveChanges();
                        db.Configuration.ValidateOnSaveEnabled = true;
                        return Content("投标完成!");

                }else if(TimeSpan.Parse(modelM.BeginTime)>System.DateTime.Now.TimeOfDay)
                {
                    return Content("投标未开始");
                }else
                { return Content("投标已结束"); }
            }

            return Content("投标未开始");
        }