Exemplo n.º 1
0
        private void add(HttpContext context)
        {
            string json = "";
            string [] limitids = context.Request["limitids"].Split(',');
            string rolename = context.Request["rolename"];
            string isreuse = context.Request["isreuse"];
            TBL_ROLE tr = new TBL_ROLE();
            tr.roleid = System.Guid.NewGuid().ToString().ToUpper();
            tr.rolename = rolename;
            tr.isreuse = isreuse == "true" ? true : false;

            try
            {

                List<TBL_ROLE> roleList = roBLL.GetList(" rolename='" + rolename + "' ").ToList<TBL_ROLE>();
                if (roleList.Count>0)
                {
                    json = "{IsSuccess:'false',Message:'角色名称已经存在!'}";
                }
                else
                {
                    if (roBLL.Insert(tr))
                    {
                        foreach (string limitid in limitids)
                        {
                            if (string.IsNullOrEmpty(limitid))
                            {
                                continue;
                            }
                            TBL_ROLEAUTHORIZATION tra = new TBL_ROLEAUTHORIZATION();
                            tra.roleid = tr.roleid;
                            tra.limitid = limitid;
                            roaBLL.Insert(tra);
                        }
                        json = "{IsSuccess:'true',Message:'保存成功!',id:'" + tr.roleid + "'}";
                    }
                    else
                    {
                        json = "{IsSuccess:'false',Message:'保存失败!'}";
                    }
                }

            }
            catch (Exception ex)
            {
                logger.Error(ex.Message);
                json = "{IsSuccess:'false',Message:'服务器交互失败!'}";
            }
            json = JsonConvert.SerializeObject(json);
            context.Response.ContentType = "application/json";
            context.Response.Write(json);
            context.Response.End();
        }
Exemplo n.º 2
0
        private void update(HttpContext context)
        {
            string json = "";
            string[] limitids = context.Request["limitids"].Split(',');
            string rolename = context.Request["rolename"];
            string roleid = context.Request["roleid"];
            string isreuse = context.Request["isreuse"];
            TBL_ROLE tr = new TBL_ROLE();
            tr.roleid = roleid;
            tr.rolename = rolename;
            tr.isreuse = isreuse == "true" ? true : false;

            try
            {

                if (roBLL.Update(tr))
                {
                    roaBLL.Delete(" roleid='" + roleid + "' ");
                    foreach (string limitid in limitids)
                    {
                        if (string.IsNullOrEmpty(limitid))
                        {
                            continue;
                        }
                        TBL_ROLEAUTHORIZATION tra = new TBL_ROLEAUTHORIZATION();
                        tra.roleid = tr.roleid;
                        tra.limitid = limitid;
                        roaBLL.Insert(tra);
                    }
                    json = "{IsSuccess:'true',Message:'保存成功!'}";
                }
                else
                {
                    json = "{IsSuccess:'true',Message:'保存失败!'}";
                }
            }
            catch (Exception ex)
            {
                logger.Error(ex.Message);
                json = "{IsSuccess:'false',Message:'服务器交互失败!'}";
            }
            json = JsonConvert.SerializeObject(json);
            context.Response.ContentType = "application/json";
            context.Response.Write(json);
            context.Response.End();
        }