Ejemplo n.º 1
0
        /// <summary>
        /// 回傳員工編輯頁所需model
        /// </summary>
        /// <returns></returns>
        public ActionResult Edit(int?id)
        {
            EmpService            service    = new EmpService();
            List <Depart>         deps       = GetDeparts();
            List <SelectListItem> depSelects = new List <SelectListItem>();
            Employee emp = new Employee();

            if (deps != null && deps.Count > 0)
            {
                depSelects.Add(new SelectListItem
                {
                    Text     = "請選擇",
                    Value    = "",
                    Selected = true,
                });
                foreach (var item in deps)
                {
                    depSelects.Add(new SelectListItem
                    {
                        Text  = item.DepName,
                        Value = item.DepId,
                    });
                }
            }

            if (id != null)
            {
                emp = service.GetEmployee(id.Value);
            }

            vmEmployee vm = new vmEmployee()
            {
                depSelectLists = depSelects,
                employee       = emp,
            };

            return(View(vm));
        }