public ActionResult GetPhotoByID() { Validation vld = new Validation(); int photoID = vld.GetInt("id", false, "请传入照片编号"); PhotoBLL photoBLL = new PhotoBLL(); PhotoObj photoObj = photoBLL.GetPhotoByID(photoID); return(Json(new { success = true, data = photoObj })); }
public ActionResult DeletePhoto() { if (!AppData.IsManagerLogin) { return(Json(new { success = false, msg = "您未登录后台或会话已过期" })); } if (PrivilegeBLL.HasNotPrivilege(AppData.SessionUserID, 1003)) { return(Json(new { success = false, msg = "您没有执行该操作的权限" })); } Validation vld = new Validation(); int photoID = vld.GetInt("id", false, "请传入照片编号"); PhotoBLL photoBLL = new PhotoBLL(); PhotoObj photoObj = photoBLL.GetPhotoByID(photoID); System.IO.File.Delete(Config.MediaPath + photoObj.Pic.Replace("/", "\\")); JsonArray points = photoBLL.GetPhotoPoints(photoID); if (points != null) { string pic; for (int i = 0; i < points.Count; i++) { if (points[i]["Pic"] != null) { pic = (string)points[i]["Pic"]; System.IO.File.Delete(Config.MediaPath + pic.Replace("/", "\\")); } } } photoBLL.DeletePhoto(photoID); return(Json(new { success = true })); }
public ActionResult ModifyPhoto() { if (Request.HttpMethod == "POST") { if (!AppData.IsManagerLogin) { return(HandleResult(false, "您未登录后台或会话已过期")); } if (PrivilegeBLL.HasNotPrivilege(AppData.SessionUserID, 1002)) { return(HandleResult(false, "您没有执行该操作的权限")); } Validation vld = new Validation(); int photoID = vld.GetInt("id", false, "请传入照片编号"); PhotoBLL photoBLL = new PhotoBLL(); PhotoObj photoObj = photoBLL.GetPhotoByID(photoID); photoObj.Name = vld.Get("name", false, "请填写照片名称"); photoObj.Info = vld.Get("info"); string sCategoryIDs = vld.Get("categoryIDs", false, "请至少选择一个类别", regex: @"^\d+(,\d+)*$", regexText: "类别参数错误"); IList <int> categoryIDs; if (string.IsNullOrEmpty(sCategoryIDs)) { categoryIDs = null; } else { string[] aCategoryIDs = sCategoryIDs.Split(','); categoryIDs = new List <int>(); for (int i = 0; i < aCategoryIDs.Length; i++) { categoryIDs.Add(int.Parse(aCategoryIDs[i])); } } if (vld.HasError) { return(HandleResult(false, vld.GetError())); } photoObj.Categories = categoryIDs; HttpPostedFileBase pic = Request.Files.Count == 0 ? null : Request.Files[0]; if (pic != null && pic.ContentLength != 0) { string ext = Path.GetExtension(pic.FileName); if (!Regex.IsMatch(ext, @"^\.(gif|jpg|jpeg|png)$", RegexOptions.IgnoreCase)) { return(HandleResult(false, "上传的图片格式不合要求,请上传gif,png,jpg格式的图片")); } string path = DateTime.Now.ToString("yyyyMMdd"); string dirPath = Config.MediaPath + @"\Package\" + path; if (!Directory.Exists(dirPath)) { Directory.CreateDirectory(dirPath); } string newFileName = DateTime.Now.ToString("yyyyMMddHHmmss_ffff") + ext; string savePath = Path.Combine(dirPath, newFileName); System.IO.File.Delete(Config.MediaPath + photoObj.Pic.Replace("/", "\\")); pic.SaveAs(savePath); photoObj.Pic = "/Package/" + path + "/" + newFileName; } photoBLL.ModifyPhoto(photoObj); return(HandleResult(true, photoObj.PhotoID.ToString())); } else { if (!AppData.IsManagerLogin) { return(Redirect("/Manage/Error/1.html")); } if (PrivilegeBLL.HasNotPrivilege(AppData.SessionUserID, 1002)) { return(Redirect("/Manage/Error/2.html")); } ViewBag.mediaServer = Config.MediaServer; return(View()); } }