/// <summary> /// 检测邮箱是否被使用 /// </summary> /// <returns></returns> public bool CheckForEmail() { return(UsersAccessor.EmailExists(Email)); }
/// <summary> /// 修改资料 /// </summary> /// <param name = "state" > 用户名 </param> /// <returns> </returns> public bool ModifyTo(UserModifyState state) { ThrowExceptionIfValidateFailure(() => { //编辑的内容为NULl if (state == null) { AddBrokenRule(UserAccountFailureRules.MODIFYSTATE_CANNOT_NULL); } else { // 用户名不能为空 if (string.IsNullOrWhiteSpace(state.UserName)) { AddBrokenRule(UserAccountFailureRules.USERNAME_REQUIRE); } // 姓名不能为空 else if (string.IsNullOrWhiteSpace(state.Name)) { AddBrokenRule(UserAccountFailureRules.NAME_REQUIRE); } // Email不能为空且格式要正确 else if (!state.Email.IsEmail()) { AddBrokenRule(UserAccountFailureRules.EMAIL_ERROR); } // 手机号不能为空且格式要正确 else if (!state.Mobile.IsCnPhone()) { AddBrokenRule(UserAccountFailureRules.MOBILE_ERROR); } // 用户名被使用 else if (UsersAccessor.UsernameExists(state.UserName, ID)) { AddBrokenRule(UserAccountFailureRules.USERNAME_EXISTS); } // 邮箱被使用 else if (UsersAccessor.EmailExists(state.Email, ID)) { AddBrokenRule(UserAccountFailureRules.EMAIL_EXISTS); } // 手机号被使用 else if (UsersAccessor.MobileExists(state.Mobile, ID)) { AddBrokenRule(UserAccountFailureRules.MOBILE_EXISTS); } } }); //权限编号序列组 string permissionCodes = string.Empty; if (state.Permissions != null) { permissionCodes = string.Join(",", state.Permissions); } bool success = false; if (state.IsModifyBySelf) { success = UsersAccessor.UpdateFor(ID, state.UserName, state.Email, state.Mobile, state.Title, state.Name); } else if (string.IsNullOrWhiteSpace(state.Password)) { success = UsersAccessor.UpdateFor(ID, state.UserName, state.Email, state.Mobile, state.Title, state.Name, permissionCodes); } else { success = UsersAccessor.UpdateFor(ID, state.UserName, state.Email, state.Mobile, state.Title, state.Name, state.EncryptPassword, permissionCodes); } return(success); }