Exemplo n.º 1
0
        /// <summary>
        /// 异步添加异常日志到数据库
        /// </summary>
        /// <param name="ex">异常信息</param>
        /// <returns></returns>
        public static void ToInDB(Exception ex)
        {
            Tools.WebSiteModel model = Tools.ConfigHelper.LoadConfig <Tools.WebSiteModel>(Tools.ConfigFileEnum.SiteConfig);
            if (!model.LogExceptionInDB)
            {
                return;
            }

            var entity = new Entity.SysLogException()
            {
                AddTime    = DateTime.Now,
                Message    = ex.Message,
                Source     = ex.Source,
                StackTrace = ex.StackTrace
            };

            new System.Threading.Thread(new System.Threading.ThreadStart(delegate()
            {
                BLL.BaseBLL <Entity.SysLogException> bll = new BLL.BaseBLL <Entity.SysLogException>();
                bll.Add(entity);
            }))
            {
                IsBackground = true
            }.Start();
        }
Exemplo n.º 2
0
        public ActionResult EditIOS(Entity.AppVersion entity)
        {
            var isAdd = entity.ID == 0 ? true : false;

            LoadPlatform();
            BLL.BaseBLL <Entity.AppVersion> bll = new BLL.BaseBLL <Entity.AppVersion>();

            entity.Platforms = Entity.APPVersionPlatforms.IOS;
            entity.LogoImg   = "null";
            entity.MD5       = "null";

            ModelState.Remove("LogoImg");
            ModelState.Remove("MD5");



            //数据验证
            if (isAdd)
            {
                //判断版本是否存在
                if (bll.Exists(p => p.Platforms == Entity.APPVersionPlatforms.IOS && p.APPType == entity.APPType && p.Version == entity.Version))
                {
                    ModelState.AddModelError("Version", "该版本存在");
                }
            }
            else
            {
                if (bll.Exists(p => p.ID == entity.ID))
                {
                    return(PromptView("/admin/AppVersion", "404", "Not Found", "信息不存在或已被删除", 5));
                }
            }

            if (ModelState.IsValid)
            {
                //添加
                if (entity.ID == 0)
                {
                    var new_ver = bll.GetModel(p => p.Platforms == Entity.APPVersionPlatforms.IOS && p.APPType == entity.APPType, "VersionCode desc");
                    entity.VersionCode = new_ver == null ? 1 : new_ver.VersionCode + 1;
                    entity.AddTime     = DateTime.Now;

                    bll.Add(entity);
                }
                else //修改
                {
                    //var old_entity = db.AppVersions.Find(entity.ID);
                    //db.Entry(old_entity).CurrentValues.SetValues(entity);
                    bll.Modify(entity);
                }
                return(PromptView("/admin/AppVersion", "OK", "Success", "操作成功", 5));
            }
            else
            {
                return(View(entity));
            }
        }
Exemplo n.º 3
0
        public ActionResult EditAndroid(Entity.AppVersion entity)
        {
            var isAdd = entity.ID == 0 ? true : false;

            BLL.BaseBLL <Entity.AppVersion> bll = new BLL.BaseBLL <Entity.AppVersion>();

            entity.APPType   = Entity.APPVersionType.Standard;
            entity.Platforms = Entity.APPVersionPlatforms.Android;

            //数据验证
            if (isAdd)
            {
                //判断版本是否存在
                if (bll.Exists(p => p.Platforms == Entity.APPVersionPlatforms.Android && p.APPType == Entity.APPVersionType.Standard && p.Version == entity.Version))
                {
                    ModelState.AddModelError("Content", "该版本存在");
                }
            }
            else
            {
                if (!bll.Exists(p => p.ID == entity.ID))
                {
                    return(PromptView("/admin/AppVersion", "404", "Not Found", "信息不存在或已被删除", 5));
                }
            }

            if (ModelState.IsValid)
            {
                //添加
                if (entity.ID == 0)
                {
                    entity.AddTime = DateTime.Now;
                    bll.Add(entity);
                }
                else //修改
                {
                    bll.Modify(entity);
                }

                return(PromptView("/admin/AppVersion", "OK", "Success", "操作成功", 5));
            }
            else
            {
                return(View(entity));
            }
        }
Exemplo n.º 4
0
        public ActionResult Edit(Entity.Demo entity)
        {
            var isAdd = entity.ID == 0 ? true : false;

            BLL.BaseBLL <Entity.Demo> bll = new BLL.BaseBLL <Entity.Demo>();
            string str_albums             = WebHelper.GetFormString("StrAlbums");

            if (!isAdd)
            {
                if (!bll.Exists(p => p.ID == entity.ID))
                {
                    return(PromptView("/admin/demo", "404", "Not Found", "信息不存在或已被删除", 5));
                }
            }
            if (ModelState.IsValid)
            {
                //添加
                if (entity.ID == 0)
                {
                    entity.AddTime          = DateTime.Now;
                    entity.LastUpdateTime   = DateTime.Now;
                    entity.AddUserID        = WorkContext.UserInfo.ID;
                    entity.LastUpdateUserID = WorkContext.UserInfo.ID;
                    bll.Add(entity);
                }
                else //修改
                {
                    entity.LastUpdateTime   = DateTime.Now;
                    entity.LastUpdateUserID = WorkContext.UserInfo.ID;
                    new BLL.BLLDemo().Modify(entity);
                }

                return(PromptView("/admin/demo", "OK", "Success", "操作成功", 5));
            }
            else
            {
                return(View(entity));
            }
        }
Exemplo n.º 5
0
        public override void OnActionExecuted(HttpActionExecutedContext actionExecutedContext)
        {
            base.OnActionExecuted(actionExecutedContext);
            if (site.WebAPITracker)
            {
                WebApiMonitorLog MonLog = actionExecutedContext.Request.Properties[Key] as WebApiMonitorLog;
                MonLog.ExecuteEndTime = DateTime.Now;
                MonLog.ActionName     = actionExecutedContext.ActionContext.ActionDescriptor.ActionName;
                MonLog.ControllerName = actionExecutedContext.ActionContext.ActionDescriptor.ControllerDescriptor.ControllerName;
                MonLog.Uri            = actionExecutedContext.Request.RequestUri.OriginalString;

                new System.Threading.Thread(new System.Threading.ThreadStart(delegate()
                {
                    BLL.BaseBLL <Entity.SysLogApiAction> bll = new BLL.BaseBLL <Entity.SysLogApiAction>();
                    DateTime now_date = DateTime.Now.Date;
                    bll.DelBy(p => p.ExecuteStartTime < now_date);
                    bll.Add(MonLog.GetLogEntity());
                }))
                {
                    IsBackground = true
                }.Start();
            }
        }
Exemplo n.º 6
0
        public JsonResult UpdateRoute()
        {
            List <Models.ModelRoute> route_list = new List <Models.ModelRoute>();

            #region 反射获取所有的控制路由

            string   path     = IOHelper.GetMapPath("~/bin/Universal.Web.dll");
            byte[]   buffer   = System.IO.File.ReadAllBytes(path);
            Assembly assembly = Assembly.Load(buffer);

            foreach (var type in assembly.ExportedTypes)
            {
                System.Reflection.MemberInfo[] properties = type.GetMembers();
                foreach (var item in properties)
                {
                    string controllerName = item.ReflectedType.Name.Replace("Controller", "").ToString();
                    string actionName     = item.Name.ToString();
                    //访问路由
                    string route_map = controllerName.ToLower() + "/" + actionName.ToLower();
                    //是否是HttpPost请求
                    bool IsHttpPost = item.GetCustomAttributes(typeof(System.Web.Mvc.HttpPostAttribute), true).Count() > 0 ? true : false;

                    object[] attrs = item.GetCustomAttributes(typeof(Framework.AdminPermissionAttribute), true);
                    if (attrs.Length == 1)
                    {
                        Framework.AdminPermissionAttribute attr = (Framework.AdminPermissionAttribute)attrs[0];
                        route_list.Add(new Models.ModelRoute
                        {
                            Tag    = attr.Tag,
                            Desc   = attr.Desc,
                            IsPost = IsHttpPost,
                            Route  = route_map
                        });
                    }
                }
            }
            #endregion

            BLL.BaseBLL <Entity.SysRoute> bll = new BLL.BaseBLL <Entity.SysRoute>();
            var db_list = bll.GetListBy(0, new List <BLL.FilterSearch>(), null);

            foreach (var item in db_list)
            {
                var entity = route_list.Where(p => p.IsPost == item.IsPost && p.Route == item.Route).FirstOrDefault();
                //如果数据库对应程序中不存在,则删除数据库里的
                if (entity == null)
                {
                    bll.Del(item);
                }
                else
                {
                    //否则修改数据库里的DES之类的辅助说明
                    item.Desc = entity.Desc;
                    item.Tag  = entity.Tag;
                    bll.Modify(item);
                }
            }

            foreach (var item in route_list)
            {
                var entity = bll.GetModel(p => p.IsPost == item.IsPost && p.Route == item.Route, null);
                if (entity == null)
                {
                    var route = new Entity.SysRoute();
                    route.AddTime = DateTime.Now;
                    route.Desc    = item.Desc;
                    route.IsPost  = item.IsPost;
                    route.Route   = item.Route;
                    route.Tag     = item.Tag;
                    bll.Add(route);
                }
            }
            AddAdminLogs(Entity.SysLogMethodType.Update, "更新权限数据");

            WorkContext.AjaxStringEntity.msg    = 1;
            WorkContext.AjaxStringEntity.msgbox = "success";
            return(Json(WorkContext.AjaxStringEntity));
        }
Exemplo n.º 7
0
        /// <summary>
        /// 提交内容的编辑或修改
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        public JSData ReleasePost(ReleaseInput input)
        {
            JSData jsdata = new JSData();

            #region 数据验证
            if (null == BLL.Common.BLLSession.UserInfoSessioin)
            {
                jsdata.Messg = "您还未登录~";
            }
            else if (BLL.Common.BLLSession.UserInfoSessioin.IsLock)
            {
                jsdata.Messg = "您的账户未激活,暂只能评论。~";
            }
            else if (string.IsNullOrEmpty(input.Content))
            {
                jsdata.Messg = "内容不能为空~";
            }

            if (!string.IsNullOrEmpty(jsdata.Messg))
            {
                jsdata.State = EnumState.失败;
                return(jsdata);
            }
            #endregion

            BLL.BaseBLL <BlogInfo> blogbll = new BaseBLL <BlogInfo>();
            var blogtemp      = blogbll.GetList(t => t.Id == input.Blogid, isAsNoTracking: false).FirstOrDefault();
            var userid        = input.Blogid > 0 ? blogtemp.User.Id : BLLSession.UserInfoSessioin.Id;//如果numblogid大于〇证明 是编辑修改
            var sessionuserid = BLLSession.UserInfoSessioin.Id;

            //获取得 文章 类型集合 对象
            var typelist = new List <int>();
            if (!string.IsNullOrEmpty(input.Chk_type))
            {
                foreach (string type in input.Chk_type.Split(',').ToList())
                {
                    if (!string.IsNullOrEmpty(type))
                    {
                        typelist.Add(int.Parse(type));
                    }
                }
            }
            // types.Split(',').ToList().ForEach(t => typelist.Add(int.Parse(t)));
            var myBlogTypes = new BLL.BaseBLL <BlogType>().GetList(t => typelist.Contains(t.Id), isAsNoTracking: false).ToList();

            //获取得 文章 tag标签集合 对象
            //old
            var oldtaglist    = string.IsNullOrEmpty(input.Oldtag) ? new List <string>() : input.Oldtag.Split(',').ToList();
            var myOldTagTypes = new BLL.BaseBLL <BlogTag>().GetList(t => t.BlogUser.Id == userid && oldtaglist.Contains(t.TagName), isAsNoTracking: false).ToList();
            //new
            var newtaglist = input.Newtag.GetValueOrEmpty().Split(',').ToList();
            AddTag(newtaglist, userid);//保存到数据库
            var myNweTagTypes = new BLL.BaseBLL <BlogTag>().GetList(t => t.BlogUser.Id == userid && newtaglist.Contains(t.TagName), isAsNoTracking: false).ToList();
            myNweTagTypes.ForEach(t => myOldTagTypes.Add(t));


            if (input.Blogid > 0)                                                                       //如果有 blogid 则修改
            {
                if (sessionuserid == blogtemp.User.Id || BLLSession.UserInfoSessioin.UserName == admin) //一定要验证更新的博客是否是登陆的用户
                {
                    blogtemp.Content      = input.Content;
                    blogtemp.Title        = input.Title;
                    blogtemp.IsShowMyHome = input.Isshowmyhome;
                    blogtemp.IsShowHome   = input.Isshowhome;
                    blogtemp.Types.Clear();//更新之前要清空      不如会存在主外键约束异常
                    blogtemp.Types = myBlogTypes;
                    blogtemp.Tags.Clear();
                    blogtemp.Tags         = myOldTagTypes;
                    blogtemp.IsDelte      = false;
                    blogtemp.IsForwarding = false;
                    jsdata.Messg          = "修改成功~";
                }
                else
                {
                    jsdata.Messg = "您没有编辑此博文的权限~";
                    jsdata.JSurl = "/";
                    jsdata.State = EnumState.失败;
                    return(jsdata);
                }
            }
            else  //否则 新增
            {
                var blogfirst = blogbll.GetList(t => t.User.Id == sessionuserid).OrderByDescending(t => t.Id).FirstOrDefault();

                if (null != blogfirst && blogfirst.Title == input.Title)
                {
                    jsdata.Messg = "不能同时发表两篇一样标题的文章~";
                }
                else
                {
                    var bloguser = new BLL.BaseBLL <BlogUser>().GetList(t => t.Id == BLLSession.UserInfoSessioin.Id, isAsNoTracking: false).FirstOrDefault();

                    blogtemp = new BlogInfo()
                    {
                        User           = bloguser,
                        Content        = input.Content,
                        Title          = input.Title,
                        BlogUpTime     = DateTime.Now,
                        BlogCreateTime = DateTime.Now,
                        IsShowMyHome   = input.Isshowmyhome,
                        IsShowHome     = input.Isshowhome,
                        Types          = myBlogTypes,
                        Tags           = myOldTagTypes,
                        IsDelte        = false,
                        IsForwarding   = false
                    };
                    blogbll.Insert(blogtemp);
                    jsdata.Messg = "发布成功~";
                }
            }

            //
            if (blogbll.save(false) > 0)
            {
                #region 添加 或 修改搜索索引
                try
                {
                    var newtagList = string.Empty;
                    blogtemp.Tags.Where(t => true).ToList().ForEach(t => newtagList += t.TagName + " ");
                    var          newblogurl = "/" + BLLSession.UserInfoSessioin.UserName + "/" + blogtemp.Id + ".html";
                    SearchResult search     = new SearchResult()
                    {
                        flag          = blogtemp.User.Id,
                        id            = blogtemp.Id,
                        title         = blogtemp.Title,
                        clickQuantity = 0,
                        blogTag       = newtagList,
                        content       = Blogs.Common.Helper.MyHtmlHelper.GetHtmlText(blogtemp.Content),
                        url           = newblogurl
                    };
                    SafetyWriteHelper <SearchResult> .logWrite(search, PanGuLuceneHelper.instance.CreateIndex);
                }
                catch (Exception)
                { }
                #endregion

                jsdata.State = EnumState.成功;
                jsdata.JSurl = "/" + GetDataHelper.GetAllUser().Where(t => t.Id == blogtemp.User.Id).First().UserName + "/" + blogtemp.Id + ".html";
                return(jsdata);
            }

            jsdata.Messg = string.IsNullOrEmpty(jsdata.Messg) ? "操作失败~" : jsdata.Messg;
            jsdata.State = EnumState.失败;
            return(jsdata);
        }
Exemplo n.º 8
0
        public ActionResult Edit(Entity.SysUser entity)
        {
            var isAdd = entity.ID == 0 ? true : false;

            BLL.BaseBLL <Entity.SysUser> bll = new BLL.BaseBLL <Entity.SysUser>();
            Load();

            if (entity.SysRoleID == 0)
            {
                ModelState.AddModelError("SysRoleID", "请选择用户组");
            }

            //数据验证
            if (isAdd)
            {
                //判断用户名是否存在
                if (!bll.Exists(p => p.UserName == entity.UserName))
                {
                    ModelState.AddModelError("UserName", "该用户名已存在");
                }
            }
            else
            {
                //如果要编辑的用户不存在
                if (!bll.Exists(p => p.ID == entity.ID))
                {
                    return(PromptView("/admin/SysUser", "404", "Not Found", "信息不存在或已被删除", 5));
                }
                ModelState.Remove("UserName");
            }

            if (ModelState.IsValid)
            {
                //添加
                if (entity.ID == 0)
                {
                    entity.RegTime       = DateTime.Now;
                    entity.Password      = SecureHelper.MD5(entity.Password);
                    entity.LastLoginTime = DateTime.Now;
                    bll.Add(entity);
                }
                else //修改
                {
                    var user = bll.GetModel(p => p.ID == entity.ID, null);
                    if (entity.Password != "litdev")
                    {
                        user.Password = SecureHelper.MD5(entity.Password);
                    }
                    user.NickName  = entity.NickName;
                    user.Gender    = entity.Gender;
                    user.Status    = entity.Status;
                    user.Avatar    = entity.Avatar;
                    user.SysRoleID = entity.SysRoleID;
                    bll.Modify(user);
                }

                return(PromptView("/admin/SysUser", "OK", "Success", "操作成功", 5));
            }
            else
            {
                return(View(entity));
            }
        }