public ActionResult Add() { try { UserProfile _UserProfile = new UserProfile { Id = ToolMethod.GetGuid(), //Role = UserProfile.EnumAccountType.User, LoginName = "*****@*****.**", NickName = "Dipa666", Phone = "13520387252", Password = FormsAuthentication.HashPasswordForStoringInConfigFile("123456", "MD5"), FirstName = "Sun", LastName = "Dapeng", Sex = UserProfile.EnumSexType.Male, SysStatus = UserProfile.EnumSysType.正常, CDate = DateTime.Now, LastDate = DateTime.Now }; if (_Bll.Add(_UserProfile)) { return(Json(new { Success = true, Message = "添加成功!", SuccessModel = _UserProfile })); } else { return(Json(new { Success = true, Message = "添加失败!", SuccessModel = "" })); } } catch (Exception ee) { return(Json(new { Success = false, Message = "添加异常!", SuccessModel = ee })); } }
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")); } }
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 = "添加博客成功!" })); }
public int GetPV(string Key) { int PVNum = 0; if (true) { PVNum = RedisHelper.ItemGet <int>(Key); if (PVNum != 0) { return(PVNum); } else { //读取数据库PV值 Statistics PVObj = _Dal.GetPV(); //初始值创建 if (PVObj != null) { PVNum = PVObj.PV; } else { Statistics _Statistics = new Statistics { Id = ToolMethod.GetGuid(), PV = 0, UV = 0 }; AddPV(_Statistics); } RedisHelper.ItemSet <int>(Key, PVNum); //过期时间为1分钟 RedisHelper.CommonSetExpire(Key, DateTime.Now.AddMinutes(1)); return(PVNum); } } else { return(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 }
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 }
/// <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)); } }
/// <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)); } }