public ActionResult Add(string url, long uid, long folderID) { BizResultInfo result = new BizResultInfo(); var userInfo = BizUserInfo.LoadByUserInfoID(uid); if (string.IsNullOrEmpty(url) || userInfo == null) { LogHelper.WriteInfo("AddBookmark失败", "AddBookmark失败", new { UserInfoID = uid, URL = url, FolderID = folderID }); return(Json(result)); } //不存在书签夹,创建一个默认的书签夹 var folderInfo = BizUserWebFolder.LoadByID(folderID); if (folderInfo.UserWebFolderID == 0) { folderInfo.UserInfoID = uid; folderInfo.WebFolderName = userInfo.UserName + "的默认书签夹"; folderInfo.IntroContent = ""; folderInfo.IElementJSON = ""; folderInfo.Grade = 0; folderInfo.CreateTime = DateTime.Now; folderInfo.IElementHashcode = folderInfo.GetHashCode(); folderInfo.Save(); folderID = folderInfo.UserWebFolderID; } BizBookmarkInfo bookmark = new BizBookmarkInfo(); bookmark.Href = url; var res = HTTPHelper.GetHTML(url); if (!string.IsNullOrEmpty(res.Item1)) { bookmark.HTML = res.Item1; HtmlDocument htmlDoc = new HtmlDocument(); htmlDoc.LoadHtml(res.Item1); var title = htmlDoc.DocumentNode.SelectSingleNode("//title").InnerText; bookmark.BookmarkName = !string.IsNullOrEmpty(title) ? title:url; } else { bookmark.BookmarkName = url; } if (string.IsNullOrEmpty(res.Item2) || res.Item2.ToUpper() == "ALLOW-FROM") { bookmark.IsShowWithiframe = 1; } bookmark.UserWebFolderID = folderID; bookmark.CreateTime = DateTime.Now; bookmark.Host = url.GetHost(); bookmark.UserInfoID = uid; bookmark.HashCode = bookmark.GetHashCode(); bookmark.Save(); return(Json(result)); }
public ActionResult CollectBookmarkToUserDefaultFolder(long bookmarkID) { BizResultInfo result = new BizResultInfo(); var bookmarkInfo = BizBookmarkInfo.LoadByID(bookmarkID); if (bookmarkInfo == null || bookmarkInfo.BookmarkInfoID == 0) { result.IsSuccess = false; result.ErrorMessage = "书签数据有误,可能是数据库被怪兽吃掉了,也可能是你娃误操作给了一个错误的书签ID。建议刷新重试吧。"; return(Json(result)); } var loginUID = UILoginHelper.GetUIDFromHttpContext(HttpContext); if (bookmarkInfo.UserInfoID == loginUID) { result.IsSuccess = false; result.ErrorMessage = "不用收藏自己的书签哦。"; return(Json(result)); } long folderID = GetUserDefaultFolderID(loginUID); BizBookmarkInfo newBookmark = new BizBookmarkInfo() { BookmarkName = bookmarkInfo.BookmarkName, CreateTime = DateTime.Now, Host = bookmarkInfo.Host, Href = bookmarkInfo.Href, UserInfoID = loginUID, HTML = bookmarkInfo.HTML, IElementJSON = bookmarkInfo.IElementJSON, UserWebFolderID = folderID, }; newBookmark.HashCode = newBookmark.GetHashCode(); newBookmark.Save(); result.IsSuccess = true; return(Json(result)); }
public ActionResult AddBookmark(string name, string href, long folderID, string type, long infoID) { BizResultInfo result = new BizResultInfo(); if (string.IsNullOrEmpty(name) || string.IsNullOrEmpty(type)) { result.ErrorMessage = "名称和类型必须填写呀。"; result.IsSuccess = false; return(Json(result)); } var loginUid = UILoginHelper.GetUIDFromHttpContext(HttpContext); try { if (type == "bookmark") { BizBookmarkInfo bookmark = new BizBookmarkInfo(); if (infoID != 0) { bookmark = BizBookmarkInfo.LoadByID(infoID); } bookmark.Href = href; bookmark.BookmarkName = name; bookmark.UserWebFolderID = folderID; bookmark.CreateTime = DateTime.Now; bookmark.Host = href.GetHost(); bookmark.UserInfoID = loginUid; bookmark.HashCode = bookmark.GetHashCode(); bookmark.Save(); } else { BizUserWebFolder folder = new BizUserWebFolder(); if (infoID != 0) { folder = BizUserWebFolder.LoadByID(infoID); } folder.UserInfoID = loginUid; folder.WebFolderName = name; folder.ParentWebfolderID = folderID; folder.IntroContent = ""; folder.IElementJSON = ""; folder.CreateTime = DateTime.Now; folder.IElementHashcode = folder.GetHashCode(); folder.Save(); } result.IsSuccess = true; result.SuccessMessage = "保存成功了耶,刷新一下页面就能看到了哦。"; }catch (Exception ex) { result.IsSuccess = false; result.SuccessMessage = "保存失败,可能是数据库不开心了吧,重新保存试试。"; LogHelper.WriteException("AddBookmark Exception", ex, new { Name = name, Href = href, FolderID = folderID }); } return(Json(result)); }