Exemplo n.º 1
0
        public void ProcessRequest(HttpContext context)
        {
            context.Response.ContentType = "text/plain";

            UserBll.Instance.CheckUserOnlingState();

            int k;
            var json = HttpContext.Current.Request["json"];
            var rpm  = new RequestParamModel <DemoArticleModel>(context)
            {
                CurrentContext = context
            };

            if (!string.IsNullOrEmpty(json))
            {
                rpm = JSONhelper.ConvertToObject <RequestParamModel <DemoArticleModel> >(json);
                rpm.CurrentContext = context;
            }

            var d = new DemoArticleModel();

            if (!string.IsNullOrEmpty(json))
            {
                string content = rpm.Request("content");

                d.InjectFrom(rpm.Entity);
                d.body = content;
            }

            switch (rpm.Action)
            {
            case "add":
                context.Response.Write(DemoArticleBll.Instance.Add(d));
                break;

            case "edit":
                d.KeyId = rpm.KeyId;
                context.Response.Write(DemoArticleBll.Instance.Update(d));
                break;

            case "delete":
                context.Response.Write(DemoArticleBll.Instance.Delete(rpm.KeyId));
                break;

            default:
                context.Response.Write(DemoArticleBll.Instance.GetJson(rpm.Pageindex, rpm.Pagesize, rpm.Filter, rpm.Sort, rpm.Order));
                break;
            }
        }
Exemplo n.º 2
0
        public void ProcessRequest(HttpContext context)
        {
            context.Response.ContentType = "text/plain";
            UserBll.Instance.CheckUserOnlingState();

            int k;
            var json = HttpContext.Current.Request["json"];
            var rpm  = new RequestParamModel <User>(context)
            {
                CurrentContext = context, Action = context.Request["action"]
            };

            if (!string.IsNullOrEmpty(json))
            {
                rpm = JSONhelper.ConvertToObject <RequestParamModel <User> >(json);
                rpm.CurrentContext = context;
            }

            switch (rpm.Action)
            {
            case "deps":
                context.Response.Write(UserBll.Instance.GetDepartmentTreeData());
                break;

            case "roles":
                context.Response.Write(UserBll.Instance.GetAllRoles());
                break;

            case "add":
                var roleIds = rpm.Request("roles");
                context.Response.Write(UserBll.Instance.AddUser(rpm.Entity, roleIds));
                break;

            case "update":
                User u = new User();
                u.InjectFrom(rpm.Entity);
                u.KeyId = rpm.KeyId;

                context.Response.Write(UserBll.Instance.EditUser(u));
                break;

            case "editpass":
                k = UserBll.Instance.EditPassword(rpm.KeyId, rpm.Request("password"));
                context.Response.Write(k);
                break;

            case "editpass2":
                string oldPass = context.Request["old"];
                string newPass = context.Request["new"];
                context.Response.Write(UserBll.Instance.EditPassowrd(SysVisitor.Instance.UserId, oldPass, newPass));
                break;

            case "delete":     //删除用户
                context.Response.Write(UserBll.Instance.DeleteUser(rpm.KeyId));
                break;

            case "isadmin":
                u = UserBll.Instance.GetUser(rpm.KeyId);
                if (u != null)
                {
                    var isamdin = rpm.Request("val");
                    u.IsAdmin = isamdin != "true";
                    context.Response.Write(UserBll.Instance.EditUser(u));
                }
                else
                {
                    context.Response.Write(0);
                }
                break;

            case "isdisabled":     //禁用 激活 帐号
                u = UserBll.Instance.GetUser(rpm.KeyId);
                if (u != null)
                {
                    var isdisabled = rpm.Request("val");
                    u.IsDisabled = isdisabled != "true";
                    context.Response.Write(UserBll.Instance.EditUser(u));
                }
                else
                {
                    context.Response.Write(0);
                }
                break;

            case "setroles":     //为用户分配角色
                var rolse = rpm.Request("roles");
                k = UserBll.Instance.AddUserToRoles(rpm.KeyId, rolse);
                context.Response.Write(k);
                break;

            case "getroles":     //获取指定用户的角色
                context.Response.Write(UserBll.Instance.GetRolesBy(rpm.KeyId));
                break;

            case "menus":     //获取导航菜单及按钮用于用户授权
                context.Response.Write(UserBll.Instance.GetNavBtnsJson(rpm.KeyId));
                break;

            case "authorize":     //为用户授权
                var data = rpm.Request("data");
                if (string.IsNullOrEmpty(data))
                {
                    context.Response.Write("参数错误!");
                    context.Response.End();
                }

                k = UserBll.Instance.UserAuthorize(data);
                context.Response.Write(k);
                break;

            case "setdep":
                var roleid = PublicMethod.GetInt(context.Request["keyid"]);
                var deps   = context.Request["deps"];
                k = UserBll.Instance.SetDepartments(roleid, deps);
                context.Response.Write(k);
                break;

            default:
                string j = UserBll.Instance.GetJsonData(rpm.Pageindex, rpm.Pagesize, rpm.Filter, rpm.Sort, rpm.Order);
                context.Response.Write(j);
                break;
            }
        }
Exemplo n.º 3
0
        public void ProcessRequest(HttpContext context)
        {
            context.Response.ContentType = "text/plain";

            if (SysVisitor.Instance.IsGuest)
            {
                context.Response.Write(
                    new JsonMessage {
                    Success = false, Data = "-99", Message = "登录已过期,请重新登录"
                }.ToString()
                    );
                context.Response.End();
            }

            int k;
            var json = HttpContext.Current.Request["json"];
            var rpm  = new RequestParamModel <Dic>(context)
            {
                CurrentContext = context, Action = context.Request["action"]
            };

            if (!string.IsNullOrEmpty(json))
            {
                rpm = JSONhelper.ConvertToObject <RequestParamModel <Dic> >(json);
                rpm.CurrentContext = context;
            }

            switch (rpm.Action)
            {
            case "category":     //读取字典类别
                context.Response.Write(DicBll.Instance.DicCategoryJson());
                break;

            case "add_cate":     //添加字典类别
                var dc = new DicCategory {
                    Code    = rpm.Request("code"),
                    Title   = rpm.Request("title"),
                    Sortnum = PublicMethod.GetInt(rpm.Request("sortnum")),
                    Remark  = rpm.Request("remark")
                };
                AddCategory(dc, context);
                break;

            case "edit_cate":
                dc = new DicCategory {
                    KeyId   = PublicMethod.GetInt(rpm.Request("keyid")),
                    Code    = rpm.Request("code"),
                    Title   = rpm.Request("title"),
                    Sortnum = PublicMethod.GetInt(rpm.Request("sortnum")),
                    Remark  = rpm.Request("remark")
                };
                EditCategory(dc, context);
                break;

            case "del_cate":
                var cateId = PublicMethod.GetInt(rpm.Request("cateId"));
                DelCategory(cateId, context);
                break;

            case "add":
                k = DicBll.Instance.Add(rpm.Entity);
                context.Response.Write(new JsonMessage {
                    Success = k > 0, Data = k.ToString(), Message = (k > 0 ? "添加成功!" : "字典编码已存在,请更改编码。")
                }.ToString());
                break;

            case "edit":
                if (rpm.KeyId == rpm.Entity.ParentId)
                {
                    context.Response.Write(new JsonMessage {
                        Success = false, Data = "0", Message = "上级字典不能与当前字典相同!"
                    }.ToString());
                    context.Response.End();
                }

                Dic d = new Dic();
                d.InjectFrom(rpm.Entity);
                d.KeyId = rpm.KeyId;
                k       = DicBll.Instance.Edit(d);
                context.Response.Write(new JsonMessage {
                    Success = k > 0, Data = k.ToString(), Message = (k > 0 ? "编辑成功!" : "字典编码已存在,请更改编码。")
                }.ToString());
                break;

            case "del":
                k = DicBll.Instance.Delete(rpm.KeyId);
                var msg = "删除成功。";

                switch (k)
                {
                case 0:
                    msg = "参数错误!";
                    break;

                case 2:
                    msg = "请先删除子字典数据。";
                    break;
                }

                context.Response.Write(new JsonMessage {
                    Success = k == 1, Data = k.ToString(), Message = msg
                }.ToString());

                break;

            case "code":
                var category = DicCategoryDal.Instance.GetWhere(new { Code = rpm.Request("code") }).FirstOrDefault();
                context.Response.Write(DicBll.Instance.GetDicListBy(category == null ? 0 : category.KeyId));
                break;

            default:     //字典列表
                var    categoryId = PublicMethod.GetInt(rpm.Request("categoryId"));
                string dicJson    = DicBll.Instance.GetDicListBy(categoryId);
                context.Response.Write(dicJson);
                break;
            }
        }
Exemplo n.º 4
0
        public void ProcessRequest(HttpContext context)
        {
            context.Response.ContentType = "text/plain";

            if (SysVisitor.Instance.IsGuest)
            {
                context.Response.Write(
                    new JsonMessage {
                    Success = false, Data = "-99", Message = "登录已过期,请重新登录"
                }.ToString()
                    );
                context.Response.End();
            }

            int k;
            var json = HttpContext.Current.Request["json"];
            var rpm  = new RequestParamModel <Role>(context)
            {
                CurrentContext = context, Action = context.Request["action"]
            };

            if (!string.IsNullOrEmpty(json))
            {
                rpm = JSONhelper.ConvertToObject <RequestParamModel <Role> >(json);
                rpm.CurrentContext = context;
            }

            switch (rpm.Action)
            {
            case "add":
                context.Response.Write(RoleBll.Instance.Add(rpm.Entity));
                break;

            case "edit":
                var r = new Role();
                r.InjectFrom(rpm.Entity);
                r.KeyId = rpm.KeyId;
                context.Response.Write(RoleBll.Instance.Update(r));
                break;

            case "delete":
                context.Response.Write(RoleBll.Instance.Delete(rpm.KeyId));
                break;

            case "btnColumns":
                context.Response.Write("var btns = " + RoleBll.Instance.BuildNavBtnsColumns());
                break;

            case "authorize":     //给角色授权
                var data = rpm.Request("data");
                if (string.IsNullOrEmpty(data))
                {
                    context.Response.Write("参数错误!");
                    context.Response.End();
                }

                k = RoleBll.Instance.RoleAuthorize(data);
                context.Response.Write(k);
                break;

            case "menus":
                context.Response.Write(RoleBll.Instance.GetRoleNavBtns(rpm.KeyId));
                break;

            case "deps":     //获取所有部门JSON数据
                context.Response.Write(DepartmentBll.Instance.GetDepartmentTreeJson());
                break;

            case "setdep":
                var roleid = PublicMethod.GetInt(context.Request["keyid"]);
                var deps   = context.Request["deps"];
                k = RoleBll.Instance.SetDepartments(roleid, deps);
                context.Response.Write(k);
                break;

            default:
                context.Response.Write(RoleDal.Instance.JsonDataForEasyUIdataGrid(rpm.Pageindex, rpm.Pagesize, "", rpm.Sort, rpm.Order));
                break;
            }
        }