62,046
社区成员
发帖
与我相关
我的任务
分享
public ActionResult Upload(int? id, HttpPostedFileBase pic,string TS)
{
if (id.HasValue)
{
string[] picExt = { "gif", "png", "jpg", "jpeg" };
int maxLength = 1024 * 1024 * 10;
if (pic != null)
{
if (pic.ContentLength > maxLength || !picExt.Contains(pic.FileName.ToLower().GetFileExtentionName().Replace(".", "")))
{
return JsonText(new { OK = false, Error = "图片超过大小或格式不对!" });
}
else
{
if (string.IsNullOrWhiteSpace(TS))
{
return JsonText(new { OK = false, Error = "非法操作!" });
}
byte[] ts = HttpUtility.UrlDecodeToBytes(TS);
UserSessionModel user = UserInfo;
//zhangji 2012-03-13 changed "(a.FileState == null || a.FileState == 0)" to "(a.FileState == null || a.FileState == 0 || a.FileState == 2)"
T_Order order = EF.T_Order.Where(a => a.ID == id.Value && a.TS == ts && (a.FileState == null || a.FileState == 0 || a.FileState == 2) && (a.Company_ID == user.CompanyID || user.IsAdmin)).SingleOrDefault();
if (order == null)
{
return JsonText(new { OK = false, Error = "操作失败!数据已被修改,请重新查看!" });
}
order.UploadCount = order.UploadCount + 1;
order.FilePath = id.ToString() + pic.FileName.ToLower().GetFileExtentionName();
string path = Server.MapPath("~/App_Data/Upload/") + order.FilePath;
pic.SaveAs(path);
try {
EF.SaveChanges();
}
catch (OptimisticConcurrencyException)
{
return JsonText(new { OK = false, Error = "操作失败!数据已被修改,请重新查看!" });
}
return JsonText(new { OK = true, Path = order.FilePath, ID = id ,Flag=order.UploadCount<3});
}
}
else
{
return JsonText(new { OK = false, Error = "请选择图片!" });
}
}
else
{
return JsonText(new { OK = false, Error = "缺少参数!" });
}
}