Пример #1
0
        /// <summary>
        /// 从缓存中权限列表 未命中 则读取数据库存放至缓存
        /// </summary>
        /// <param name="IsCache">是否从缓存中读取数据</param>
        /// <returns></returns>
        public List <PermissionInfo> GetAll(bool IsCache)
        {
            string PermissionKey        = "PermissionList";
            string PermissionListString = string.Empty;

            //IsCache
            //false  重新读取数据
            //true   从缓存中读取数据
            if (!IsCache)
            {
                RedisHelper.CommonRemove("PermissionList");
            }

            PermissionListString = RedisHelper.ItemGet <string>(PermissionKey);
            if (PermissionListString != null)
            {
                return(JsonHelper.DeserializeJsonToList <PermissionInfo>(PermissionListString));
            }
            else
            {
                List <PermissionInfo> _permissionInfoList = _PermissionInfoDal.GetAll();
                if (_permissionInfoList.Count > 0)
                {
                    PermissionListString = JsonHelper.SerializeObject(_permissionInfoList);
                    RedisHelper.ItemSet <string>(PermissionKey, PermissionListString);
                    RedisHelper.CommonSetExpire(PermissionKey, ToolMethod.GetNow().AddDays(1));
                }
                return(_permissionInfoList);
            }
        }
Пример #2
0
        public ActionResult UpdateBlogs(FormCollection fc)
        {
            #region 验证用户信息
            string _SessionId       = HttpContext.Request.Cookies["SessionId"].Value;
            string _UserProfileJson = RedisHelper.ItemGet <string>(_SessionId);
            #endregion

            var _Content = fc["editor"];
            var _BlogsId = fc["BlogsId"];

            if (!string.IsNullOrEmpty(_UserProfileJson))
            {
                UserProfile _UserProfile = ToolMethod.GetUerProfile(_UserProfileJson);
                BlogsInfo   _BlogsInfo   = _IBlogsInfoBLL.GetModels(x => x.Id == _BlogsId && x.Delflag == EnumType.DelflagType.正常, true, null, "BlogsInfo").FirstOrDefault();
                _BlogsInfo.BlogContent = _Content;
                _BlogsInfo.UDate       = ToolMethod.GetNow();

                RedisHelper.HashSet <BlogsInfo>("BlogsInfo", _BlogsId, _BlogsInfo);

                BackgroundJobClient _Job = new BackgroundJobClient();
                _Job.Enqueue(() => _IBlogsInfoBLL.Update(_BlogsInfo));

                return(Json(new { Success = true, SuccessModel = "修改博客成功!" }));
            }
            else
            {
                return(RedirectToAction("Login", "Account"));
            }
        }
Пример #3
0
        /// <summary>
        /// 从缓存中角色列表 未命中 则读取数据库存放至缓存
        /// </summary>
        /// <param name="IsCache">是否从缓存中读取数据</param>
        /// <returns></returns>
        public List <RoleInfo> GetAll(bool IsCache)
        {
            string RoleKey        = "RoleList";
            string RoleListString = string.Empty;

            //IsCache
            //false  重新读取数据
            //true   从缓存中读取数据
            if (!IsCache)
            {
                RedisHelper.CommonRemove("RoleList");
            }

            RoleListString = RedisHelper.ItemGet <string>(RoleKey);
            if (RoleListString != null)
            {
                return(JsonHelper.DeserializeJsonToList <RoleInfo>(RoleListString));
            }
            else
            {
                //List<RoleInfo> _roleInfoList = _roleInfoDal.GetAll();
                List <RoleInfo> _roleInfoList = null;

                if (_roleInfoList.Count > 0)
                {
                    RoleListString = JsonHelper.SerializeObject(_roleInfoList);
                    RedisHelper.ItemSet <string>(RoleKey, RoleListString);
                    RedisHelper.CommonSetExpire(RoleKey, ToolMethod.GetNow().AddDays(1));
                }
                return(_roleInfoList);
            }
        }
Пример #4
0
        public ActionResult AjaxFileUpload()
        {
            #region 验证用户信息
            string _SessionId       = HttpContext.Request.Cookies["SessionId"].Value;
            string _UserProfileJson = RedisHelper.ItemGet <string>(_SessionId);
            #endregion

            if (!string.IsNullOrEmpty(_UserProfileJson))
            {
                UserProfile _UserProfile = ToolMethod.GetUerProfile(_UserProfileJson);

                HttpFileCollection _Files = System.Web.HttpContext.Current.Request.Files;

                string _DateTimePath = ToolMethod.GetDateTimePath();
                string _PhysicalPath = ToolMethod.GetBlogsSurfacePlot_PhysicalPath(_DateTimePath);
                string _VirualPath   = ToolMethod.GetBlogsSurfacePlot_VirualPath(_DateTimePath);

                if (!Directory.Exists(_PhysicalPath))
                {
                    Directory.CreateDirectory(_PhysicalPath);
                }

                string _FileName         = _Files[0].FileName;
                string _StrFile          = System.DateTime.Now.ToString("yyyyMMddHHmmssms");
                string _FilePhysicalPath = _PhysicalPath + _StrFile + "_" + _FileName;
                string _FileVirualPath   = _VirualPath + _StrFile + "_" + _FileName;
                long   _FileSize         = _Files[0].ContentLength;
                //获取文件后缀
                string _FileType = _FileName.Substring(_FileName.LastIndexOf(@"."), _FileName.Length - _FileName.LastIndexOf(@"."));
                //保存文件
                _Files[0].SaveAs(_FilePhysicalPath);

                string    _FileId    = ToolMethod.GetGuid();
                ImageInfo _ImageInfo = new ImageInfo
                {
                    Id           = _FileId,
                    CDate        = ToolMethod.GetNow(),
                    Delflag      = EnumType.DelflagType.正常,
                    AccountId    = _UserProfile.Id,
                    AccountName  = _UserProfile.LoginName,
                    FileName     = _FileName,
                    FileSize     = _FileSize,
                    RelativePath = _StrFile + "_" + _FileName,
                    FileType     = _FileType
                };

                //保存文件集合
                _IImageInfoBLL.Add(_ImageInfo);

                return(Json(new { FileId = _FileId, FileName = _FileName, PhysicalPath = _FilePhysicalPath, VirualPath = _FileVirualPath }));
            }
            else
            {
                return(RedirectToAction("Login", "Account"));
            }
        }
Пример #5
0
        public ActionResult AddBlogs(FormCollection fc)
        {
            #region 验证用户信息
            string _SessionId       = HttpContext.Request.Cookies["SessionId"].Value;
            string _UserProfileJson = RedisHelper.ItemGet <string>(_SessionId);
            #endregion

            if (!string.IsNullOrEmpty(_UserProfileJson))
            {
                UserProfile _UserProfile = ToolMethod.GetUerProfile(_UserProfileJson);

                //获取标题
                var _BlogsHeading = fc["BlogsHeading"];
                //获取副标题
                string _BlogsSubHeading = fc["BlogsSubHeading"];
                //获取简介
                var _BlogsAbstract = fc["BlogsAbstract"];
                //获取Ueditor内容
                var _Content = fc["editor"];
                //获取封面图ID
                string _SurfacePlot = fc["SurfacePlot"];

                BlogsInfo _BlogsInfo = new BlogsInfo()
                {
                    Id               = ToolMethod.GetGuid(),
                    BlogAuthorId     = _UserProfile.Id,
                    BlogAuthorName   = _UserProfile.NickName,
                    BlogContent      = _Content,
                    BlogHeading      = _BlogsHeading,
                    BlogsSurfacePlot = _SurfacePlot,
                    BlogSubHeading   = _BlogsSubHeading,
                    CDate            = ToolMethod.GetNow(),
                    CommentNum       = 0,
                    Delflag          = EnumType.DelflagType.正常,
                    UDate            = ToolMethod.GetNow(),
                    LikeNum          = 0,
                    BlogAbstarct     = _BlogsAbstract,
                };

                RedisHelper.HashSet <BlogsInfo>("BlogsInfo", _BlogsInfo.Id, _BlogsInfo);

                BackgroundJobClient _Job = new BackgroundJobClient();
                _Job.Enqueue(() => _IBlogsInfoBLL.Add(_BlogsInfo));
            }

            return(Json(new { Success = true, SuccessModel = "添加博客成功!" }));
        }
Пример #6
0
        public ActionResult Update(UserProfile _UserProfile)
        {
            try
            {
                UserProfile _OldUserProfile = _Bll.Get(_UserProfile.Id);

                _OldUserProfile.Address    = _UserProfile.Address;
                _OldUserProfile.City       = _UserProfile.City;
                _OldUserProfile.Company    = _UserProfile.Company;
                _OldUserProfile.Country    = _UserProfile.Country;
                _OldUserProfile.Describe   = _UserProfile.Describe;
                _OldUserProfile.Email      = _UserProfile.Email;
                _OldUserProfile.FirstName  = _UserProfile.FirstName;
                _OldUserProfile.LastName   = _UserProfile.LastName;
                _OldUserProfile.NickName   = _UserProfile.NickName;
                _OldUserProfile.PostalCode = _UserProfile.PostalCode;
                _OldUserProfile.LastDate   = ToolMethod.GetNow();

                if (_Bll.Update(_OldUserProfile))
                {
                    string _SessionId         = Request.Cookies["sessionId"].Value;
                    string _UserProfileString = ToolMethod.GetUerProfileString(_OldUserProfile);
                    if (RedisHelper.ItemSet <string>(_SessionId, _UserProfileString))
                    {
                        return(Json(new { Success = true, Message = "修改信息成功!", SuccessModel = _UserProfile }));
                    }
                    else
                    {
                        return(Json(new { Success = true, Message = "修改信息失败!", ErrorMessage = "" }));
                    }
                }
                else
                {
                    return(Json(new { Success = true, Message = "添加失败!", ErrorMessage = "" }));
                }
            }
            catch (Exception ee)
            {
                return(Json(new { Success = false, Message = "添加异常!", ErrorMessage = ee }));
            }
        }
Пример #7
0
        public override void OnException(ExceptionContext filterContext)
        {
            string _ControllerName = filterContext.Controller.ToString();

            #region 记录异常日志
            if (_ControllerName != "Account")
            {
                if (filterContext.HttpContext.Request.Cookies["SessionId"] != null)
                {
                    string _SessionId       = filterContext.HttpContext.Request.Cookies["SessionId"].Value;
                    string _UserProfileJson = RedisHelper.ItemGet <string>(_SessionId);
                    if (_UserProfileJson != null)
                    {
                        //获取用户账号实体
                        _UserProfile = JsonConvert.DeserializeObject <UserProfile>(_UserProfileJson);

                        LogInfo _logInfo = new LogInfo()
                        {
                            Id      = ToolMethod.GetGuid(),
                            Content = "【请求异常】:"
                                      + "【请求路径:" + filterContext.HttpContext.Request.Path + "】"
                                      + "【请求方式:" + filterContext.HttpContext.Request.HttpMethod + "】"
                                      + "【异常内容:" + filterContext.Exception.Message.ToString() + "】",
                            AccountId   = _UserProfile.Id,
                            AccountName = _UserProfile.NickName,
                            Level       = EnumType.LogLevel.ERROR,
                            CDate       = ToolMethod.GetNow()
                        };

                        BackgroundJobClient _jobs             = new BackgroundJobClient();
                        Expression <Action> _actionExpression = () => _ILogInfoBLL.Add(_logInfo);
                        _jobs.Enqueue(_actionExpression);
                    }
                }
                else
                {
                    filterContext.HttpContext.Response.Redirect("/Account/Login?session=false");
                }
            }
            #endregion
        }
Пример #8
0
        public override void OnActionExecuted(ActionExecutedContext filterContext)
        {
            #region 获取Action & Controller信息
            string _ActionName     = filterContext.ActionDescriptor.ActionName;
            string _ControllerName = filterContext.ActionDescriptor.ControllerDescriptor.ControllerName;
            #endregion

            #region 记录操作日志
            if (_ControllerName != "Account")
            {
                if (filterContext.HttpContext.Request.Cookies["SessionId"] != null)
                {
                    string _SessionId       = filterContext.HttpContext.Request.Cookies["SessionId"].Value;
                    string _UserProfileJson = RedisHelper.ItemGet <string>(_SessionId);
                    if (_UserProfileJson != null)
                    {
                        //获取用户账号实体
                        _UserProfile = JsonConvert.DeserializeObject <UserProfile>(_UserProfileJson);

                        LogInfo _logInfo = new LogInfo()
                        {
                            Id          = ToolMethod.GetGuid(),
                            Content     = _UserProfile.NickName + "调用了 " + _ControllerName + "Controller下的" + _ActionName + "操作",
                            AccountId   = _UserProfile.Id,
                            AccountName = _UserProfile.NickName,
                            Level       = EnumType.LogLevel.INFO,
                            CDate       = ToolMethod.GetNow()
                        };

                        BackgroundJobClient _jobs             = new BackgroundJobClient();
                        Expression <Action> _actionExpression = () => _ILogInfoBLL.Add(_logInfo);
                        _jobs.Enqueue(_actionExpression);
                    }
                }
                else
                {
                    filterContext.HttpContext.Response.Redirect("/Account/Login?session=false");
                }
            }
            #endregion
        }
Пример #9
0
        /// <summary>
        /// 自动装载权限列表
        /// </summary>
        /// <returns></returns>
        public ActionResult InstallPermissions()
        {
            try
            {
                AutoGeneraterBLL _autoGeneraterBll = new AutoGeneraterBLL();
                List <KeyValuePair <string, string> > _controllerList = _autoGeneraterBll.ControllerList();
                List <KeyValuePair <string, string> > _actionList     = new List <KeyValuePair <string, string> >();

                //获取缓存中权限数据
                List <PermissionInfo> _oldPermissionInfoList = _IPermissionInfoBLL.GetModels(x => x.Delflag == EnumType.DelflagType.正常, true, null, "PermissionList").ToList();

                //获取新的权限数据
                List <PermissionInfo> _newPermissionInfoList = new List <PermissionInfo>();
                _controllerList.ForEach(x =>
                {
                    _actionList = _autoGeneraterBll.ActionList(x.Key);
                    if (_actionList != null)
                    {
                        _actionList.ForEach(y =>
                        {
                            PermissionInfo _permissionInfo = new PermissionInfo()
                            {
                                Id                    = ToolMethod.GetGuid(),
                                Controller            = x.Key,
                                Action                = y.Key,
                                ControllerDescription = x.Value,
                                ActionDescription     = y.Value,
                                CDate                 = ToolMethod.GetNow(),
                                Delflag               = EnumType.DelflagType.正常
                            };
                            _newPermissionInfoList.Add(_permissionInfo);
                        });
                    }
                });

                BackgroundJobClient _jobs = new BackgroundJobClient();

                //不存在权限列表
                if (_oldPermissionInfoList.Count == 0)
                {
                    //直接创建映射关系
                    _newPermissionInfoList.ForEach(x =>
                    {
                        //更新缓存
                        _IPermissionInfoBLL.UpdateCache("PermissionList", x.Id, x);

                        //异步更新数据库
                        _jobs.Enqueue(() => _IPermissionInfoBLL.Add(x));
                    });
                }
                //已存在映射关系
                else
                {
                    //对比新旧映射关系列表 不存在的删除 存在的保留
                    PermissionInfo_EqualityCompare _comparer   = new PermissionInfo_EqualityCompare();
                    List <PermissionInfo>          _createList = _newPermissionInfoList.Except(_oldPermissionInfoList, _comparer).ToList();
                    List <PermissionInfo>          _deleteList = _oldPermissionInfoList.Except(_newPermissionInfoList, _comparer).ToList();

                    _createList.ForEach(x =>
                    {
                        //更新缓存
                        _IPermissionInfoBLL.UpdateCache("PermissionList", x.Id, x);

                        //异步更新数据库
                        _jobs.Enqueue(() => _IPermissionInfoBLL.Add(x));
                    });

                    _deleteList.ForEach(x =>
                    {
                        x.Delflag = EnumType.DelflagType.已删除;

                        //更新缓存
                        _IPermissionInfoBLL.UpdateCache("PermissionList", x.Id, x);

                        //异步更新数据库
                        _jobs.Enqueue(() => _IPermissionInfoBLL.Update(x));
                    });
                }


                return(Json(new { Success = true, SuccessModel = "生成项目权限列表成功!" }, JsonRequestBehavior.AllowGet));
            }
            catch (Exception ee)
            {
                return(Json(new { Success = false, ErrorModel = "生成项目权限列表失败!", ErrorMessage = ee.ToString() }, JsonRequestBehavior.AllowGet));
            }
        }
Пример #10
0
        /// <summary>
        /// 自动装载角色权限映射关系列表
        /// </summary>
        /// <returns></returns>
        public ActionResult InstallRolePermissions()
        {
            try
            {
                //获取缓存中映射数据
                List <RolePermission> _oldRolePermissionList = _IRolePermissionBLL.GetModels(x => x.Delflag == EnumType.DelflagType.正常, true, null, "RolePermission").ToList();

                List <RoleInfo> _roleInfoList = _IRoleInfoBLL.GetModels(x => x.Delflag == EnumType.DelflagType.正常, true, null, "RoleList").ToList();

                List <PermissionInfo> _PermissionInfoList = _IPermissionInfoBLL.GetModels(x => x.Delflag == EnumType.DelflagType.正常, true, null, "PermissionList").ToList();

                //获取新的映射数据
                List <RolePermission> _newRolePermissionList = new List <RolePermission>();
                _roleInfoList.ForEach(x =>
                {
                    _PermissionInfoList.ForEach(y =>
                    {
                        RolePermission _rolePermission = new RolePermission
                        {
                            Id                    = ToolMethod.GetGuid(),
                            RoleId                = x.Id,
                            RoleName              = x.Name,
                            PermissionId          = y.Id,
                            CDate                 = ToolMethod.GetNow(),
                            Controller            = y.Controller,
                            ControllerDescription = y.ControllerDescription,
                            Action                = y.Action,
                            ActionDescription     = y.ActionDescription,
                            UsedType              = EnumType.UsedType.未启用,
                            Delflag               = EnumType.DelflagType.正常
                        };
                        _newRolePermissionList.Add(_rolePermission);
                    });
                });

                BackgroundJobClient _jobs = new BackgroundJobClient();

                //不存在映射关系
                if (_oldRolePermissionList.Count == 0)
                {
                    //直接创建映射关系
                    _newRolePermissionList.ForEach(x =>
                    {
                        //更新缓存
                        _IRolePermissionBLL.UpdateCache("RolePermission", x.Id, x);

                        //异步更新数据库
                        _jobs.Enqueue(() => _IRolePermissionBLL.Add(x));
                    });
                }
                //已存在映射关系
                else
                {
                    //对比新旧映射关系列表 不存在的删除 存在的保留
                    RolePermission_EqualityCompare _comparer   = new RolePermission_EqualityCompare();
                    List <RolePermission>          _createList = _newRolePermissionList.Except(_oldRolePermissionList, _comparer).ToList();
                    List <RolePermission>          _deleteList = _oldRolePermissionList.Except(_newRolePermissionList, _comparer).ToList();

                    _createList.ForEach(x =>
                    {
                        //更新缓存
                        _IRolePermissionBLL.UpdateCache("RolePermission", x.Id, x);

                        //异步更新数据库
                        _jobs.Enqueue(() => _IRolePermissionBLL.Add(x));
                    });

                    _deleteList.ForEach(x =>
                    {
                        x.Delflag = EnumType.DelflagType.已删除;

                        //更新缓存
                        _IRolePermissionBLL.UpdateCache("RolePermission", x.Id, x);

                        //异步更新数据库
                        _jobs.Enqueue(() => _IRolePermissionBLL.Update(x));
                    });
                }

                return(Json(new { Success = true, SuccessModel = "生成角色权限映射关系成功!" }, JsonRequestBehavior.AllowGet));
            }
            catch (Exception ee)
            {
                return(Json(new { Success = false, ErrorModel = "生成角色权限映射关系失败!", ErrorMessage = ee.ToString() }, JsonRequestBehavior.AllowGet));
            }
        }