public ExcuteResultEnum AddNewBcUserInfo(BcUserInfoEntity entity, string roleIds = null) { if ( EntityExecution.Count <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.InsertWithIdentity(entity); if (!string.IsNullOrEmpty(roleIds)) { foreach (string roleId in roleIds.Split(',')) { var userRoleEntity = new BcUserRoleEntity { UserId = (int?)id, RoleId = int.Parse(roleId) }; EntityExecution.Insert(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()) { entity.Update(); EntityExecution.Delete <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.Insert(userRoleEntity); } } ts.Complete(); } return(ExcuteResultEnum.Success); }