Example #1
0
        public async Task <(bool IsAdd, string msg)> AddAsync(BlogUserInfo userInfo)
        {
            using (var conn = ConnectionFactory.GetOpenConnection())
            {
                var tran = conn.BeginTransaction();
                if (userInfo == null || userInfo.Permission == null)
                {
                    return(false, "用户添加信息不完整,添加失败。");
                }
                try
                {
                    if (GetExistCount("select count(*) from bloguser_permission where userId=@uid and permissionId = @pid ", new { uid = userInfo.UserId, pid = userInfo.Permission.PermissionId }) > 0 || GetExistCount("select count(*) from blogpermission where permissionName = @pName", new { pName = userInfo.Permission.PermissionName }) <= 0 || GetExistCount("select count(*) from bloguserinfo where [Name]=@Name", new { Name = userInfo.Name }) > 0)
                    {
                        return(false, "用户添加失败");
                    }
                    var usrNum = await conn.ExecuteAsync("set identity_insert bloguserinfo on;insert into bloguserinfo(userId,[Name],userName,password,IsEnabled) values(@uid,@Name,@uName,@pwd,@isEnabled);set identity_insert bloguserinfo off", new { uid = userInfo.UserId, Name = userInfo.Name, uName = userInfo.UserName, pwd = userInfo.Password, isEnabled = userInfo.IsEnabled }, tran);

                    var upNum = 0;
                    upNum = await conn.ExecuteAsync("insert into bloguser_permission(userId,permissionId) values(@uid,@pid)", new { uid = userInfo.UserId, pid = userInfo.Permission.PermissionId }, tran);

                    if (usrNum > 0 && upNum > 0)
                    {
                        tran.Commit();
                        return(true, "添加用户成功");
                    }
                    else
                    {
                        tran.Rollback();
                        return(false, "添加用户失败");
                    }
                }
                catch (Exception ex)
                {
                    tran.Rollback();
                    return(false, ex.Message);
                }
            }
        }
Example #2
0
        public string Configure(ConfigureInput input)
        {
            var IsShowCSS = input.IsShowCSS == "on";
            var IsDisCSS  = input.IsDisCSS == "on";

            if (BLLSession.UserInfoSessioin == null)
            {
                return("您还没有登录 不能修改~");
            }
            try
            {
                //==============================================================================================================
                //遗留问题:
                //如下:如果 userinfobll.Up(BLLSession.UserInfoSessioin.BlogUserInfo)两次的话 报异常:[一个实体对象不能由多个 IEntityChangeTracker 实例引用]
                //那么 我只能 new一个新的对象 修改  然后 同时 BLLSession.UserInfoSessioin.BlogUserInfo里面的属性,不然 其他地方访问的话 是没有修改过来的值
                //==============================================================================================================
                var userinftemp = new BlogUserInfo(); //BLLSession.UserInfoSessioin.BlogUserInfo;
                BLL.BaseBLL <BlogUserInfo> userinfobll = new BaseBLL <BlogUserInfo>();
                if (input.TerminalType == "PC")       //如果是PC端
                {
                    userinftemp.IsShowCSS =
                        BLLSession.UserInfoSessioin.BlogUserInfo.IsShowCSS = IsShowCSS;
                    userinftemp.IsDisCSS =
                        BLLSession.UserInfoSessioin.BlogUserInfo.IsDisCSS = IsDisCSS;
                    userinftemp.Id =
                        BLLSession.UserInfoSessioin.BlogUserInfo.Id;
                    userinfobll.Updata(userinftemp, "IsShowCSS", "IsDisCSS");//"IsShowHTML",, "IsShowJS"
                }
                else
                {
                    userinftemp.IsShowMCSS =
                        BLLSession.UserInfoSessioin.BlogUserInfo.IsShowMCSS = IsShowCSS;
                    userinftemp.IsDisMCSS =
                        BLLSession.UserInfoSessioin.BlogUserInfo.IsDisMCSS = IsDisCSS;
                    userinftemp.Id =
                        BLLSession.UserInfoSessioin.BlogUserInfo.Id;
                    userinfobll.Updata(userinftemp, "IsShowMCSS", "IsDisMCSS");
                }

                GetDataHelper.GetAllUser().FirstOrDefault(t => t.Id == BLLSession.UserInfoSessioin.Id).BlogUserInfo
                    = BLLSession.UserInfoSessioin.BlogUserInfo;

                userinfobll.save();

                string path = FileHelper.defaultpath + "/MyConfigure/" + BLLSession.UserInfoSessioin.UserName + "/";
                FileHelper.CreatePath(path);
                if (input.conf_css.Length >= 40000 ||
                    input.conf_tail_html.Length >= 40000 ||
                    input.conf_first_html.Length >= 40000 ||
                    input.conf_side_html.Length >= 40000 ||
                    input.conf_js.Length >= 40000)
                {
                    return("您修改的内容字符过多~");
                }

                if (input.TerminalType == "PC")//如果是PC端
                {
                    FileHelper.SaveFile(path, "conf.css", input.conf_css);
                    FileHelper.SaveFile(path, "conf_side.txt", input.conf_side_html);
                    FileHelper.SaveFile(path, "conf_first.txt", input.conf_first_html);
                    FileHelper.SaveFile(path, "conf_tail.txt", input.conf_tail_html);
                    FileHelper.SaveFile(path, "conf.js", input.conf_js);
                }
                else
                {
                    FileHelper.SaveFile(path, "Mconf.css", input.conf_css);
                    FileHelper.SaveFile(path, "Mconf_side.txt", input.conf_side_html);
                    FileHelper.SaveFile(path, "Mconf_first.txt", input.conf_first_html);
                    FileHelper.SaveFile(path, "Mconf_tail.txt", input.conf_tail_html);
                    FileHelper.SaveFile(path, "Mconf.js", input.conf_js);
                }


                return("修改成功~");
            }
            catch (Exception ex)
            {
                LogSave.ErrLogSave("自定义样式出错", ex);
                return("修改失败~");
            }
        }