public ActionResult AddPicture(string image1, string UserID, string oldIcon)
{
string UserIDs = DESEncrypt.Decrypt(UserID) == "" ? "0" : DESEncrypt.Decrypt(UserID);//ID
//string UserIDs = UserID;
string HeadPortraitpicture = "";//头像
//校验参数是否为空
string arReString = myConvertHelper.CheckParameterIsNullstr(new Dictionary<string, object> {
{"用户ID",UserIDs}
});
//参数为空则不执行查询方法
if (arReString != null)
{
return Json(arReString, JsonRequestBehavior.AllowGet);
}
HeadPortraitpicture = Base64StringToImageReleaseNeed(image1);
int ListReturn = 0;
try
{
ListReturn = DALMethod.intChaXunShuJu("ZhuXiuJuanAPI_Manage", new Dictionary<string, object> {
{"@UserID", UserIDs },
{"@HeadPortrait", HeadPortraitpicture},
{"@Type","UpadteHeadPortrait" }
});
if (ListReturn >= 1)
{
List<Dictionary<string, object>> ListReturn2 = new List<Dictionary<string, object>>();
ListReturn2 = DALMethod.ListChaXunShuJu("ZhuXiuJuanAPI_Manage", new Dictionary<string, object> {
{ "@Type","SelectHeadPortrait" }, {"@UserID",UserIDs } });
RS.result = 200;
RS.data = ListReturn2;
RS.message = "更换头像成功";
//修改成功后才,删除旧的图片
if (oldIcon != "" && oldIcon != null)
{
try
{
//获取路径中的图片
HttpWebRequest req = (HttpWebRequest)HttpWebRequest.Create(oldIcon);
string url = req.Address.LocalPath;//截取存在的路径
string Split = url.Substring(0, url.Length - 1);//除去/
if (Split != null && Split != "")
{
string opath = Server.MapPath("~") + url;
//删除文件
if (System.IO.File.Exists(opath))
{
System.IO.File.Delete(opath);
}
}
}
catch
{ //异常不用处理了人家需要,我有什么办法,
}
}
return Json(RS, JsonRequestBehavior.AllowGet);
}
else
{
RS.result = 201;
RS.message = "更换头像失败";
return Json(RS, JsonRequestBehavior.AllowGet);
}
}
catch (Exception e)
{
RS.result = 500;
RS.message = e.ToString();
return Json(RS, JsonRequestBehavior.AllowGet);
}
}