public IHttpActionResult Get([FromUri] Request <MetaData> request)
 {
     try
     {
         if (string.IsNullOrEmpty(request.ID))
         {
             Response <IEnumerable <MetaData> > response = new Response <IEnumerable <MetaData> >();
             List <MetaData> list = bll.GetList(request.Keyword);
             response.Data = list;
             return(Ok(response));
         }
         else
         {
             Response <MetaData> response = new Response <MetaData>();
             int id = 0;
             if (int.TryParse(request.ID, out id))
             {
                 if (id <= 0)
                 {
                     return(NotFound());
                 }
                 response.Data = bll.Get(id);
                 return(Ok(response));
             }
             else
             {
                 return(NotFound());
             }
         }
     }
     catch (Exception ex)
     {
         LogService.WriteErrorLog("MetaDataController[Get]", ex.ToString());
         return(BadRequest(ex.Message));
     }
 }
        public IHttpActionResult Post([FromBody] Request <ExtRole> request)
        {
            try
            {
                IList <RoleFunction> roleFuns = request.Data.RoleFuns;
                string roleId         = request.Data.RoleID;
                string roleName       = request.Data.RoleName;
                int    systemCategory = (int)request.Data.SystemCategory;
                string remark         = request.Data.Remark;

                MetaDataBLL     metaBLL   = new MetaDataBLL();
                List <MetaData> metaDatas = metaBLL.GetList(string.Empty);

                RoleFunctionBLL rfBLL = new RoleFunctionBLL();
                Role            mode  = new Role();
                if (string.IsNullOrEmpty(roleId))
                {
                    mode.RoleName       = roleName;
                    mode.SystemCategory = systemCategory;
                    mode.Remark         = remark;
                    mode.CreateDateTime = DateTime.Now;

                    roleId = bll.Add(mode);
                    if (string.IsNullOrEmpty(roleId))
                    {
                        return(BadRequest("异常"));
                    }

                    foreach (RoleFunction fun in roleFuns)
                    {
                        fun.RoleID         = roleId;
                        fun.CreateDateTime = DateTime.Now;

                        StringBuilder sb = new StringBuilder();
                        sb.AppendFormat("<?xml version=\"1.0\" encoding=\"utf-8\"?>");
                        sb.AppendFormat("<data version=\"2.0\">");

                        string[] _arr1 = fun.DataRange.Split(',');
                        foreach (string str in _arr1)
                        {
                            string[] _arr2 = str.Split('#');
                            if (_arr2.Length != 5)
                            {
                                continue;
                            }
                            int    _id = int.Parse(_arr2[1]);
                            string col = GetValue(metaDatas, _id);
                            sb.AppendFormat("<item>");
                            sb.AppendFormat("<relationship>{0}</relationship>", _arr2[3]);
                            sb.AppendFormat("<nameID>{0}</nameID>", _arr2[1]);
                            sb.AppendFormat("<name>{0}</name>", _arr2[0]);
                            sb.AppendFormat("<operation>{0}</operation>", _arr2[2]);
                            sb.AppendFormat("<value>{0}</value>", _arr2[4]);
                            sb.AppendFormat("<column>{0}</column>", col);
                            sb.AppendFormat("</item>");
                        }
                        sb.AppendFormat("</data>");

                        rfBLL.Add(fun);
                    }
                }
                else
                {
                    mode = bll.Get(roleId);
                    if (mode == null)
                    {
                        return(BadRequest("该记录不存在!"));
                    }
                    mode.RoleName       = roleName;
                    mode.SystemCategory = systemCategory;
                    mode.Remark         = remark;
                    mode.EditTime       = DateTime.Now;

                    bll.Edit(mode);
                    List <RoleFunction> hasRF = rfBLL.GetList(p => p.ROLEID.Equals(roleId) && p.ISDELETED == false);
                    foreach (RoleFunction fun in hasRF)
                    {
                        rfBLL.Delete(fun.RoleFunctionID);
                    }

                    foreach (RoleFunction fun in roleFuns)
                    {
                        fun.RoleID         = roleId;
                        fun.CreateDateTime = DateTime.Now;

                        StringBuilder sb = new StringBuilder();
                        sb.AppendFormat("<?xml version=\"1.0\" encoding=\"utf-8\"?>");
                        sb.AppendFormat("<data version=\"2.0\">");

                        string[] _arr1 = fun.DataRange.Split(',');
                        foreach (string str in _arr1)
                        {
                            string[] _arr2 = str.Split('#');
                            if (_arr2.Length != 5)
                            {
                                continue;
                            }
                            int    _id = int.Parse(_arr2[1]);
                            string col = GetValue(metaDatas, _id);
                            sb.AppendFormat("<item>");
                            sb.AppendFormat("<relationship>{0}</relationship>", _arr2[3]);
                            sb.AppendFormat("<nameID>{0}</nameID>", _arr2[1]);
                            sb.AppendFormat("<name>{0}</name>", _arr2[0]);
                            sb.AppendFormat("<operation>{0}</operation>", _arr2[2]);
                            sb.AppendFormat("<value>{0}</value>", _arr2[4]);
                            sb.AppendFormat("<column>{0}</column>", col);
                            sb.AppendFormat("</item>");
                        }
                        sb.AppendFormat("</data>");
                        fun.DataRange = sb.ToString();

                        rfBLL.Add(fun);
                    }
                }

                return(Ok("ok"));
            }
            catch (Exception ex)
            {
                LogHelper.WriteInfo(ex.ToString());
                return(BadRequest("异常!"));
            }
        }