public ExcuteResultEnum AddNewBcUserInfo(BcUserInfoEntity entity, string roleIds = null) { if (EntityExecution.GetEntityCount2<BcUserInfoEntity>(n => n.UserAccount == entity.UserAccount && n.DeleteFlag == false) > 0) return ExcuteResultEnum.IsExist; using (TransactionScope ts = new TransactionScope()) { entity.UserId = null; entity.DeleteFlag = false; entity.Password = Encryption.Encrypt(entity.Password); var id = EntityExecution.InsertEntityWithIdentity(entity); if (!string.IsNullOrEmpty(roleIds)) { foreach (string roleId in roleIds.Split(',')) { var userRoleEntity = new BcUserRoleEntity { UserId = (int?)id, RoleId = int.Parse(roleId) }; EntityExecution.InsertEntity(userRoleEntity); } } ts.Complete(); } return ExcuteResultEnum.Success; }
public ExcuteResultEnum UpdateBcUserInfo(BcUserInfoEntity entity, string roleIds = null) { entity.Password = Encryption.Encrypt(entity.Password); using (TransactionScope ts = new TransactionScope()) { EntityExecution.UpdateEntity(entity); EntityExecution.DeleteEntity2<BcUserRoleEntity>(n => n.UserId == entity.UserId); if (!string.IsNullOrEmpty(roleIds)) { foreach (string roleId in roleIds.Split(',')) { var userRoleEntity = new BcUserRoleEntity { UserId = entity.UserId, RoleId = int.Parse(roleId) }; EntityExecution.InsertEntity(userRoleEntity); } } ts.Complete(); } return ExcuteResultEnum.Success; }
private BcUserInfoEntity PrepareFormData() { //校验参数的合法性 this.txtUserAccount.Text.InitValidation("用户名").NotEmpty().ShorterThan(25); this.txtPassword.Text.InitValidation("密码").NotEmpty().LongerThan(3).ShorterThan(15); this.txtUserName.Text.InitValidation("姓名").NotEmpty().ShorterThan(25); this.txtOfficePhone.Text.InitValidation("座机").ShorterThan(25); this.txtMobilePhone.Text.InitValidation("手机").ShorterThan(25); this.txtEmail.Text.InitValidation("邮件").ShorterThan(50); this.ddlGroup.SelectedValue.InitValidation("组别").NotEmpty(); var entity = new BcUserInfoEntity(); entity.UserId = int.Parse(this.hdUserId.Value); entity.UserAccount = this.txtUserAccount.Text; entity.Password = this.txtPassword.Text; entity.UserName = this.txtUserName.Text; entity.Sex = this.rMale.Checked; entity.OfficePhone = this.txtOfficePhone.Text; entity.MobilePhone = this.txtMobilePhone.Text; entity.Email = this.txtEmail.Text; entity.ActivityFlag = this.rEnable.Checked; entity.GroupId = int.Parse(this.ddlGroup.SelectedValue); return entity; }