Esempio n. 1
0
        public IActionResult Edit(TLeaveApplicationCreateViewModel T)
        {
            var errors = ModelState.Values.SelectMany(v => v.Errors);

            if (ModelState.IsValid)
            {
                if (T != null)
                {
                    TLeaveApplication _revised = MyHr.TLeaveApplications.FirstOrDefault(i => i.CApplyNumber == T.CApplyNumber);

                    if (_revised != null)
                    {
                        _revised.CApplyDate      = T.CApplyDate;
                        _revised.CLeaveCategory  = T.CLeaveCategory;
                        _revised.CLeaveStartTime = T.CLeaveStartTime;
                        _revised.CLeaveEndTime   = T.CLeaveEndTime;
                        _revised.CReason         = T.CReason;
                        _revised.CLeaveHours     = T.CLeaveHours;

                        MyHr.SaveChanges();
                    }
                }

                return(RedirectToAction("LeaveList"));
            }
            else
            {
                List <TLeave> listLeave = GetLeaveList();
                ViewBag.LeaveCate = listLeave;
                return(View());
            }
        }
Esempio n. 2
0
        public IActionResult LeaveCreate(TLeaveApplicationCreateViewModel T)
        {
            var errors = ModelState.Values.SelectMany(v => v.Errors);

            if (ModelState.IsValid) //[Reurired]在CORE可以成功使用
            {
                MyHr.TLeaveApplications.Add(T.Leave);
                //await MyHr.SaveChangesAsync();
                MyHr.SaveChanges();
                return(RedirectToAction("LeaveList"));
            }
            else
            {
                //ModelState.AddModelError("CReason", "幹這個錯誤訊息跳出來,就算輸入資料了,也不會驗證過,不懂存在的意義");

                List <TLeave> listLeave = GetLeaveList();  //★我怎麼這抹巧!!!★
                ViewBag.LeaveCate = listLeave;
                return(View());
            }


            //return RedirectToAction("LeaveCreate");
        }