Example #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;
        }
Example #2
0
 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;
 }
        private BcUserInfoEntity PrepareFormData()
        {
            //校验参数的合法性
            txtUserAccount.Text.InitValidation("用户名").NotEmpty().ShorterThan(25);
            txtPassword.Text.InitValidation("密码").NotEmpty().LongerThan(3).ShorterThan(15);
            txtUserName.Text.InitValidation("姓名").NotEmpty().ShorterThan(25);
            txtOfficePhone.Text.InitValidation("座机").ShorterThan(25);
            txtMobilePhone.Text.InitValidation("手机").ShorterThan(25);
            txtEmail.Text.InitValidation("邮件").ShorterThan(50);
            ddlGroup.SelectedValue.InitValidation("组别").NotEmpty();

            var entity = new BcUserInfoEntity();
            entity.UserId = int.Parse(hdUserId.Value);
            entity.UserAccount = txtUserAccount.Text;
            entity.Password = txtPassword.Text;
            entity.UserName = txtUserName.Text;
            entity.Sex = rMale.Checked;
            entity.OfficePhone = txtOfficePhone.Text;
            entity.MobilePhone = txtMobilePhone.Text;
            entity.Email = txtEmail.Text;
            entity.ActivityFlag = rEnable.Checked;
            entity.GroupId = int.Parse(ddlGroup.SelectedValue);
            return entity;
        }