public ActionResult _Insert_Edit(hr_pam_department item) { hr_pam_department departmentDAL = new hr_pam_department(); //验证是否重复 string name = item.departmentname; int nameget = _departmentRepository.GetName(name, item.id); if (nameget > 0) { Response.StatusCode = 403; return(Content(string.Join("提示", "部门名称不能相同~"))); } else { if (TryUpdateModel(departmentDAL)) { if (item.id == 0) { _departmentBLL.Create(ref validationErrors, departmentDAL); } else { _departmentBLL.Edit(ref validationErrors, departmentDAL); } } } NameValueCollection collection = new NameValueCollection(Request.QueryString); IEnumerable <hr_pam_department> department = _departmentBLL.Binddepartment(collection); return(View(new GridModel(department))); }
/// <summary> /// 创建一个hr_pam_department /// </summary> /// <param name="validationErrors">返回的错误信息</param> /// <param name="db">数据库上下文</param> /// <param name="entity">一个hr_pam_department</param> /// <returns></returns> public bool Create(ref ValidationErrors validationErrors, hr_pam_department entity) { try { repository.Create(entity); return(true); } catch (Exception ex) { validationErrors.Add(ex.Message); ExceptionsHander.WriteExceptions(ex); } return(false); }
/// <summary> /// 绑定dropdownlist /// </summary> /// <param name="type">绑定类型</param> /// <returns>选项</returns> public static SelectList bindDpl(string type) { List <SelectListItem> lista = new List <SelectListItem>(); switch (type) { case "职工性别": lista.Add(new SelectListItem { Text = "---请选择---", Value = "-1" }); lista.Add(new SelectListItem { Text = "女", Value = "1" }); lista.Add(new SelectListItem { Text = "男", Value = "0" }); break; case "出行状态": lista.Add(new SelectListItem { Text = "---请选择---", Value = "-1" }); lista.Add(new SelectListItem { Text = "返回", Value = "0" }); lista.Add(new SelectListItem { Text = "出行", Value = "1" }); break; case "部门名称": using (SysEntities db = new SysEntities()) { List <hr_pam_department> list = (from o in db.hr_pam_department.AsEnumerable() select new hr_pam_department { id = o.id, departmentname = o.departmentname }).ToList(); hr_pam_department department = new hr_pam_department(); department.id = -1; department.departmentname = "---请选择---"; list.Add(department); var list2 = list.OrderBy(a => a.id); return(new SelectList(list2.ToList(), "id", "departmentname")); } case "职工姓名": using (SysEntities db = new SysEntities()) { List <hr_pam_employee> list = (from o in db.hr_pam_employee.AsEnumerable() select new hr_pam_employee { id = o.id, employeename = o.employeename }).ToList(); hr_pam_employee employee = new hr_pam_employee(); employee.id = -1; employee.employeename = "---请选择---"; list.Add(employee); var list2 = list.OrderBy(a => a.id); return(new SelectList(list2.ToList(), "id", "employeename")); } case "职工学历": lista.Add(new SelectListItem { Text = "---请选择---", Value = "-1" }); lista.Add(new SelectListItem { Text = "本科", Value = "1" }); lista.Add(new SelectListItem { Text = "大专", Value = "0" }); lista.Add(new SelectListItem { Text = "专科", Value = "2" }); break; } SelectList items = new SelectList(lista, "Value", "Text"); return(items); }