Пример #1
0
        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);
        }