public ActionResult DeleteFriendLink() { if (!AppData.IsManagerLogin) { return(Json(new { success = false, msg = "您未登录后台或会话已过期" })); } if (PrivilegeBLL.HasNotPrivilege(AppData.SessionUserID, 1903)) { return(Json(new { success = false, msg = "您没有执行该操作的权限" })); } FriendLinkBLL friendLinkBLL = new FriendLinkBLL(); Validation vld = new Validation(); int id = vld.GetInt("id"); if (id != 0) { FriendLinkObj friendLinkObj = friendLinkBLL.GetFriendLinkByID(id); System.IO.File.Delete(Config.MediaPath + friendLinkObj.Pic); friendLinkBLL.DeleteFriendLink(id); } return(Json(new { success = true })); }
public ActionResult GetFriendLink() { Validation vld = new Validation(); int id = vld.GetInt("id"); FriendLinkBLL friendLinkBLL = new FriendLinkBLL(); dynamic result; if (id == 0) { result = friendLinkBLL.GetFriendLinks(); } else { result = friendLinkBLL.GetFriendLinkByID(id); } return(Json(new { success = true, data = result })); }
public ActionResult AddFriendLink() { if (Request.HttpMethod != "POST") { if (!AppData.IsManagerLogin) { return(Redirect("/Manage/Error/1.html")); } if (PrivilegeBLL.HasNotPrivilege(AppData.SessionUserID, 1901)) { return(Redirect("/Manage/Error/2.html")); } return(View()); } else { if (!AppData.IsManagerLogin) { return(Result(false, "您未登录后台或会话已过期")); } if (PrivilegeBLL.HasNotPrivilege(AppData.SessionUserID, 1901)) { return(Result(false, "您没有执行该操作的权限")); } FriendLinkBLL friendLinkBLL = new FriendLinkBLL(); HttpPostedFileBase pic = Request.Files["pic"]; if (pic == null || pic.ContentLength == 0) { return(Result(false, "请选择一张图片上传")); } string ext = System.IO.Path.GetExtension(pic.FileName); if (!Regex.IsMatch(ext, @"^\.(gif|jpg|jpeg|png)$", RegexOptions.IgnoreCase)) { return(Result(false, "上传的图片格式不合要求,请上传gif,png,jpg格式的图片")); } Validation vld = new Validation(); FriendLinkObj friendLinkObj = new FriendLinkObj(); friendLinkObj.FriendName = vld.Get("name", false); friendLinkObj.Url = vld.Get("url", false); if (vld.HasError) { return(Result(false, "数据填写不完整")); } string dirPath = Config.MediaPath + @"\Upload"; if (!Directory.Exists(dirPath)) { Directory.CreateDirectory(dirPath); } string newFileName = DateTime.Now.ToString("yyyyMMddHHmmss_ffff") + ext; string savePath = Path.Combine(dirPath, newFileName); friendLinkObj.Pic = "/Upload/" + newFileName; friendLinkBLL.AddFriendLink(friendLinkObj); pic.SaveAs(savePath); return(Result(true)); } }