public ActionResult Edit()
        {
            Manpower_apply _manpower_apply = manpowerapplyRepository.GetByid(Convert.ToInt32(Request.Form["Apply_ID"]));

            _manpower_apply.Applicant       = Request.Form["Applicant"];                               //申請人
            _manpower_apply.Applicant_phone = Request.Form["Applicant_phone"];                         //申請人電話
            //_manpower_apply.Work_place = Request.Form["Work_place"];  //值班地點]
            _manpower_apply.Apply_description           = Request.Form["Apply_description"];           //工作項目與流程
            _manpower_apply.Application_unit_Supervisor = Request.Form["Application_unit_Supervisor"]; //單位主管
            //_manpower_apply.Application_unit_heads = Request.Form["Application_unit_heads"];  //部門主管
            _manpower_apply.Application_number = Convert.ToInt32(Request.Form["Application_number"]);  //申請人數
            _manpower_apply.Remarks            = Request.Form["Remarks"];                              //備註

            var q = from s in dbContext.Stages                                                         //申請階段
                    where s.Stage1 == "新申請"
                    select s.Stage_ID;

            _manpower_apply.Apply_state = q.ToList().First();

            manpowerapplyRepository.Update(_manpower_apply);
            //呼叫靜態方法
            string morning     = Request.Cookies["morning"].Value;
            string afternoon   = Request.Cookies["afternoon"].Value;
            string night       = Request.Cookies["night"].Value;
            string assistance  = Request.Cookies["assistance"].Value;
            int    totalPeople = Convert.ToInt32(Request.Cookies["countPeple"].Value);

            ManpowerDataContext.ModifiedPeriod(Convert.ToInt32(Request.Form["Apply_ID"]), morning, afternoon, night, assistance, totalPeople);

            return(RedirectToAction("Index"));
        }
        public ActionResult Edit(int id = 0)//這個ID是applyId
        {
            try
            {
                var q = from m in dbContext.Manpower_apply
                        join s in dbContext.Stages on m.Apply_state equals s.Stage_ID
                        where m.Apply_ID == id && (s.Stage1 == "新申請" || s.Stage1 == "申請駁回")
                        select new Manpower_applyStageVM {
                    manpower_apply = m, stage = s,
                };

                //宣告一個ViewBag 把值用來存放DB裡面的 根據applyID 找到每個applyId的volunteerNumber
                ViewBag.PeriodDictionary = ManpowerDataContext.ReturnDictionary(id);

                return(View(q.First()));
            }
            catch
            {
                return(RedirectToAction("Index"));
            }
        }
        public ActionResult Insert()
        {
            if (Request.Form.Count > 0)
            {
                int countPeple = Convert.ToInt32(Request.Cookies["countPeple"].Value);

                _manpower_apply.Application_unit_no = Convert.ToInt32(Session["UserID"]);                  //運用單位編號
                _manpower_apply.Applicant           = Request.Form["Applicant"];                           //申請人
                _manpower_apply.Apply_date          = DateTime.Now;                                        //申請日期
                _manpower_apply.Applicant_phone     = Request.Form["Applicant_phone"];                     //申請人電話
                //_manpower_apply.Work_place = Request.Form["Work_place"];  //值班地點]
                _manpower_apply.Apply_description           = Request.Form["Apply_description"];           //工作項目與流程
                _manpower_apply.Application_unit_Supervisor = Request.Form["Application_unit_Supervisor"]; //單位主管
                _manpower_apply.Application_unit_heads      = Request.Form["Application_unit_heads"];      //部門主管
                _manpower_apply.Apply_type = "年度申請";                                                       //申請類別
                //_manpower_apply.Application_number = Convert.ToInt32(Request.Form["Application_number"]);  //申請人數
                _manpower_apply.Application_number = countPeple;
                _manpower_apply.Remarks            = Request.Form["Remarks"]; //備註

                var q = from s in dbContext.Stages
                        where s.Stage1 == "新申請"
                        select s.Stage_ID;
                _manpower_apply.Apply_state = q.ToList().First(); //申請階段

                manpowerapplyRepository.Create(_manpower_apply);

                int    applyID    = _manpower_apply.Apply_ID; //新增過後得到新增的applyID
                string morning    = Request.Cookies["morning"].Value;
                string afternoon  = Request.Cookies["afternoon"].Value;
                string night      = Request.Cookies["night"].Value;
                string assistance = Request.Cookies["assistance"].Value; //寫一個靜態方法在model裡面 用來將cookie資料轉型
                ManpowerDataContext.ConvertAndInsert(applyID, morning, afternoon, night, assistance);

                return(RedirectToAction("Index"));
            }
            return(View());
        }