|
|
@@ -92,79 +92,20 @@ namespace Filters
|
|
|
request.QueryString = new QueryString("?" + queryString.TrimEnd('&'));
|
|
|
}
|
|
|
}
|
|
|
- else if(context.HttpContext.Request.Method.ToLower() == "delete")
|
|
|
- {
|
|
|
- string path = request.Path.Value;
|
|
|
- string value = path.Substring(path.LastIndexOf("/") + 1);
|
|
|
- path = path.Substring(0, path.LastIndexOf("/") + 1);
|
|
|
- path += value;
|
|
|
- request.Path = new PathString(path);
|
|
|
- request.RouteValues["id"] = value;
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- content = context.HttpContext.GetBody();
|
|
|
- if(!string.IsNullOrEmpty(content))
|
|
|
- {
|
|
|
- Dictionary<string, object> dic = Newtonsoft.Json.JsonConvert.DeserializeObject<Dictionary<string, object>>(content);
|
|
|
-
|
|
|
- string queryString = "{";
|
|
|
- var parameters = context.ActionDescriptor.Parameters;
|
|
|
- foreach(var parameter in parameters)
|
|
|
- {
|
|
|
- string parameterName = parameter.Name;
|
|
|
- Type objectType = parameter.ParameterType;
|
|
|
- if(objectType.FullName != "System.String")
|
|
|
- {
|
|
|
- System.Reflection.Assembly assembly = System.Reflection.Assembly.GetAssembly(objectType);
|
|
|
- var entry = assembly.CreateInstance(objectType.FullName);
|
|
|
- Type type = entry.GetType();
|
|
|
- System.Reflection.PropertyInfo[] propertyInfos = type.GetProperties();
|
|
|
- for (int i = 0; i < propertyInfos.Length; i++)
|
|
|
- {
|
|
|
- foreach (string key in dic.Keys)
|
|
|
- {
|
|
|
- if (propertyInfos[i].Name == key)
|
|
|
- {
|
|
|
- object value = dic[key];
|
|
|
- string ParameterType = propertyInfos[i].GetMethod.ReturnParameter.ParameterType.Name;
|
|
|
- if (ParameterType == "Int32")
|
|
|
- {
|
|
|
- if(value == null || value == "") value = "0";
|
|
|
- value = Convert.ToInt32(value);
|
|
|
- }
|
|
|
- else if (ParameterType == "Decimal")
|
|
|
- {
|
|
|
- if(value == null || value == "") value = "0";
|
|
|
- value = Convert.ToDecimal(value);
|
|
|
- }
|
|
|
- else if (ParameterType == "Int64[]")
|
|
|
- {
|
|
|
- value = Tools.SpitLongArrary(Newtonsoft.Json.JsonConvert.SerializeObject(value).Replace("[", "").Replace("]", "").Trim('"'), ',');
|
|
|
- }
|
|
|
- else if (ParameterType == "Int32[]")
|
|
|
- {
|
|
|
- value = Tools.SpitIntArrary(Newtonsoft.Json.JsonConvert.SerializeObject(value).Replace("[", "").Replace("]", "").Trim('"'), ',');
|
|
|
- }
|
|
|
- else if (ParameterType == "List`1")
|
|
|
- {
|
|
|
- string val = Newtonsoft.Json.JsonConvert.SerializeObject(value).Replace("[", "").Replace("]", "").Trim('"');
|
|
|
- value = Tools.SpitLongArrary(val, ',').ToList();
|
|
|
- }
|
|
|
- if(value.ToString() == "-1") value = -1;
|
|
|
- if(value.ToString() == "[]") value = "";
|
|
|
- queryString += "\"" + key + "\":\"" + value.ToString() + "\",";
|
|
|
- break;
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- queryString = queryString.TrimEnd(',');
|
|
|
- queryString += "}";
|
|
|
- request.Body = new MemoryStream(Encoding.UTF8.GetBytes(queryString));
|
|
|
- }
|
|
|
- }
|
|
|
+ // else if(context.HttpContext.Request.Method.ToLower() == "delete")
|
|
|
+ // {
|
|
|
+ // string path = request.Path.Value;
|
|
|
+ // string value = path.Substring(path.LastIndexOf("/") + 1);
|
|
|
+ // path = path.Substring(0, path.LastIndexOf("/") + 1);
|
|
|
+ // path += value;
|
|
|
+ // request.Path = new PathString(path);
|
|
|
+ // request.RouteValues["id"] = value;
|
|
|
+ // }
|
|
|
+ // else
|
|
|
+ // {
|
|
|
+ // content = context.HttpContext.GetBody();
|
|
|
+ // request.Body = new MemoryStream(Encoding.UTF8.GetBytes(content));
|
|
|
+ // }
|
|
|
}
|
|
|
|
|
|
// public string Decrypt(string str)
|
|
|
@@ -177,12 +118,15 @@ namespace Filters
|
|
|
public string GetParam(string content)
|
|
|
{
|
|
|
string result = "{";
|
|
|
- if(content.StartsWith("?")) content = content.Substring(1);
|
|
|
- string[] data = content.Split('&');
|
|
|
- foreach(string sub in data)
|
|
|
+ if(content.StartsWith("?") && content != "?")
|
|
|
{
|
|
|
- string[] subData = sub.Split('=');
|
|
|
- result += "\"" + subData[0] + "\":\"" + subData[1] + "\",";
|
|
|
+ content = content.Substring(1);
|
|
|
+ string[] data = content.Split('&');
|
|
|
+ foreach(string sub in data)
|
|
|
+ {
|
|
|
+ string[] subData = sub.Split('=');
|
|
|
+ result += "\"" + subData[0] + "\":\"" + subData[1] + "\",";
|
|
|
+ }
|
|
|
}
|
|
|
result += "}";
|
|
|
return result;
|