private void DeleteById(HttpContext context)
{
string method = context.Request.Params["method"].ToString();
string entityName = method.Substring("Delete".Length);
Assembly assembly = Assembly.Load("Entity");
var obj = assembly.CreateInstance("Entity." + entityName);
string strJson = string.Empty;
using (StreamReader reader = new StreamReader(context.Request.InputStream))
{
strJson = HttpUtility.UrlDecode(reader.ReadToEnd());
}
if (strJson.IsNotEmptyTrim())
{
PropertyInfo[] pi = obj.GetType().GetProperties();
foreach (PropertyInfo item in pi)
{
var v = (DescriptionAttribute[])item.GetCustomAttributes(typeof(DescriptionAttribute), false);
if (v.Length > 0)
{
if (v[0].Description == "主键")
{
item.SetValue(obj, strJson.ChangeType(item.PropertyType), null);
break;
}
}
}
try
{
Type t = typeof(BLLBase<>).MakeGenericType(obj.GetType());
MethodInfo mi = t.GetMethod("Dels");
var res = mi.Invoke(null, new object[] { new int[] { Convert.ToInt32(strJson) } });
HttpAjaxErrMsg returnMsg = new HttpAjaxErrMsg();
if((bool)res)
{
returnMsg.data = "returnMsg";
returnMsg.msg = "删除成功!";
}
else
{
returnMsg.data = "returnMsg";
returnMsg.msg = "删除失败!";
}
var jsonData = JsonConvert.SerializeObject(returnMsg);
context.Response.Write(jsonData.ToString());
}
catch (Exception e)
{
DebugHelper.WriteLine(e);
}
}
}