protected override ValidationResult IsValid(object value, ValidationContext validationContext) { employee = validationContext.ObjectInstance as EmployeeCM; if (employee.ID == 0 && string.IsNullOrWhiteSpace(employee.Password)) { return(new ValidationResult("密码不能为空")); } return(ValidationResult.Success); }
public ActionResult Create(EmployeeCM m) { BindData(); var entity = iEmployeeService.Get(m.ID) ?? new Employee(); try { if (ModelState.IsValid) { var empInfo = iEmployeeService.Get(currentUser.ID); entity.MerchantID = empInfo.MerchantID; entity.Code = m.Code; entity.Name = m.Name; entity.Email = m.Email; entity.Mobile = m.Mobile; entity.EmployeeDepartmentID = m.EmployeeDepartmentID; entity.EmployeeRoleID = m.EmployeeRoleID; entity.IsMore = m.IsMore; entity.AuthDepartmentIDs = m.AuthDepartmentIDArray == null ? null : string.Join(",", m.AuthDepartmentIDArray); entity.Status = m.Status; if (entity.ID == 0) { entity.Password = Framework.Security.Crypt.MD5(m.Password); } iEmployeeService.Save(entity); iEmployeeService.Commit(); this.ShowTip(); return(RedirectToAction("Create", new { ID = entity.ID })); } else { AddError(); } } catch (Exception ex) { this.AddError(ErrorCode.Exception, ex.Message); } return(View(m)); }