public ActionResult SaveBookmarkTag(long bookmarkID, long tagInfoID = 0, string tagName = "") { BizResultInfo result = new BizResultInfo(); var bookmarkInfo = BizBookmarkInfo.LoadByID(bookmarkID); if (bookmarkInfo == null || bookmarkInfo.BookmarkInfoID == 0) { result.ErrorMessage = "书签数据为空,不要逗我玩啦..."; return(Json(result)); } bookmarkInfo.LoadBookmarkTagInfo(); if (tagInfoID != 0 && bookmarkInfo.BizBookmarkTagInfoList.All(mode => mode.TagInfoID != tagInfoID)) { bookmarkInfo.AddBookmarkTag(tagInfoID); } var errorMessage = string.Empty; if (!string.IsNullOrEmpty(tagName)) { errorMessage = bookmarkInfo.AddBookmarkTag(tagName); } if (!string.IsNullOrEmpty(errorMessage)) { result.ErrorMessage = errorMessage; result.IsSuccess = false; } else { result.SuccessMessage = "保存成功!"; result.IsSuccess = true; } return(Json(result)); }
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)); }
/// <summary> /// 遍历数据树,构建书签和书签夹的对应关系 /// </summary> /// <param name="tree"></param> /// <param name="uid"></param> /// <param name="lstBookmarkInfo"></param> /// <param name="dicHashcodeToModel"></param> private static void FillBookmarkModelAndWebfolderInfo(IElement tree, long uid, List <BizBookmarkInfo> lstBookmarkInfo, Dictionary <int, BizUserWebFolder> dicHashcodeToModel) { foreach (var element in tree.Children) { if (element.Children.Count() != 0) { FillBookmarkModelAndWebfolderInfo(element, uid, lstBookmarkInfo, dicHashcodeToModel); } else { if (string.IsNullOrEmpty(element.TagName)) { continue; } var tagName = element.TagName.ToUpper(); if (tagName == "H3") { var parentHashcode = element.ParentElement.ParentElement.ParentElement.FirstElementChild.GetHashCode(); if (dicHashcodeToModel.ContainsKey(parentHashcode) && dicHashcodeToModel.ContainsKey(element.GetHashCode())) { dicHashcodeToModel[element.GetHashCode()].ParentWebfolderID = dicHashcodeToModel[parentHashcode].UserWebFolderID; } } else if (tagName == "A") { var parentHashcode = element.ParentElement.ParentElement.ParentElement.FirstElementChild.GetHashCode(); if (dicHashcodeToModel.ContainsKey(parentHashcode)) { var hrefInfo = element as IHtmlAnchorElement; if (hrefInfo == null) { continue; } var bizUserWebFolder = dicHashcodeToModel[parentHashcode]; var bizBookmarkInfo = new BizBookmarkInfo(); bizBookmarkInfo.BookmarkName = hrefInfo.Text; bizBookmarkInfo.UserInfoID = uid; bizBookmarkInfo.Host = hrefInfo.Host; bizBookmarkInfo.Href = hrefInfo.Href; bizBookmarkInfo.IElementJSON = hrefInfo.OuterHtml; bizBookmarkInfo.UserWebFolderID = bizUserWebFolder.UserWebFolderID; bizBookmarkInfo.CreateTime = DateTime.Now; lstBookmarkInfo.Add(bizBookmarkInfo); } } } } }
public ActionResult ShowBookmarkHTML(long bookmarkID, string url) { UIBookmarkInfo model = null; if (bookmarkID == 0 || string.IsNullOrEmpty(url)) { return(PartialView("ShowBookmarkHTML", model)); } var bookmarkInfo = BizBookmarkInfo.LoadByID(bookmarkID); if (bookmarkInfo == null) { return(PartialView("ShowBookmarkHTML", model)); } model = new UIBookmarkInfo(); model.IsShowWithiframe = bookmarkInfo.IsShowWithiframe == 1;//是否可在iframe中展示 if (string.IsNullOrEmpty(bookmarkInfo.HTML)) { var result = HTTPHelper.GetHTML(url); if (string.IsNullOrEmpty(result.Item1)) { model = new UIBookmarkInfo(); model.HTML = bookmarkInfo.HTML; model.Href = bookmarkInfo.Href; model.UserInfoID = bookmarkInfo.UserInfoID; model.Host = bookmarkInfo.Host; model.BookmarkName = bookmarkInfo.BookmarkName; model.BookmarkInfoID = bookmarkInfo.BookmarkInfoID; return(PartialView("ShowBookmarkHTML", model)); } bookmarkInfo.HTML = result.Item1; if (string.IsNullOrEmpty(result.Item2) || result.Item2.ToUpper() == "ALLOW-FROM") { bookmarkInfo.IsShowWithiframe = 1; model.IsShowWithiframe = true; } bookmarkInfo.Save(); } model.HTML = bookmarkInfo.HTML; model.Href = bookmarkInfo.Href; model.UserInfoID = bookmarkInfo.UserInfoID; model.Host = bookmarkInfo.Host; model.BookmarkName = bookmarkInfo.BookmarkName; model.BookmarkInfoID = bookmarkInfo.BookmarkInfoID; return(PartialView("ShowBookmarkHTML", model)); }
// // GET: /ShowBookmarkInfo/ public ActionResult Index(long bookmarkID) { if (bookmarkID == 0) { return(View()); } UIBookmarkInfo model = null; var bookmarkInfo = BizBookmarkInfo.LoadByID(bookmarkID); if (bookmarkInfo != null) { bookmarkInfo.LoadBookmarkTagInfo(); bookmarkInfo.LoadLikeLog(); model = new UIBookmarkInfo(); model.LikeCount = bookmarkInfo.LikeCount; model.LikeLogList = bookmarkInfo.LikeLogList; Dictionary <long, BizTagInfo> dicTagInfo = BizTagInfo.LoadByUserID(bookmarkInfo.UserInfoID).ToDictionary(tag => tag.TagInfoID, tag => tag); model.BookmarkInfoID = bookmarkInfo.BookmarkInfoID; model.BookmarkName = bookmarkInfo.BookmarkName; model.Host = bookmarkInfo.Host; model.Href = bookmarkInfo.Href; model.UserInfoID = bookmarkInfo.UserInfoID; model.UserWebFolderID = bookmarkInfo.UserWebFolderID; //model.HTML = bookmarkInfo.HTML; model.CreateTime = bookmarkInfo.CreateTime; var bookmarkUserInfo = BizUserInfo.LoadByUserInfoID(bookmarkInfo.UserInfoID); model.UserInfo = new UIUserInfo() { UserName = bookmarkUserInfo.UserName, UserEmail = bookmarkUserInfo.UserEmail, UserInfoID = bookmarkUserInfo.UserInfoID, }; model.TagInfoList = bookmarkInfo.BizBookmarkTagInfoList.Select(btg => new UIBookmarkTagInfo() { BookmarkTagInfoID = btg.BookmarkTagInfoID, BookmarkInfoID = btg.BookmarkInfoID, TagInfoID = btg.TagInfoID, CreateTime = btg.CreateTime, TagInfo = dicTagInfo.ContainsKey(btg.TagInfoID) ? dicTagInfo[btg.TagInfoID] : null, }).ToList(); } return(View(model)); }
private static void NewBookmarkComment(long userID, object info) { var bookmarkComment = info as BizBookmarkComment; var bookmarkInfo = BizBookmarkInfo.LoadByID(bookmarkComment.BookmarkInfoID); var criticsUser = BizUserInfo.LoadByUserInfoID(bookmarkComment.CriticsUserID); BizMessageInfo messageInfo = new BizMessageInfo(); messageInfo.CreateTime = DateTime.Now; messageInfo.IsRead = (int)MessageReadStatus.NotRead; messageInfo.MessageTitle = string.Format("书签:【{0}】评论", bookmarkInfo.BookmarkName); messageInfo.MessageContent = string.Format("书签:【{0}】 新增来自【{1}】的评论,点击下面的链接去查看评论啦。^-^", bookmarkInfo.BookmarkName, criticsUser.UserName); messageInfo.MessageURL = "~/ShowBookmarkInfo?bookmarkID=" + bookmarkInfo.BookmarkInfoID; messageInfo.UserInfoID = userID; messageInfo.MessageInfoType = (int)MessageTypeEnum.NewBookmarkComment; messageInfo.Save(); }
public ActionResult AddBookmarkLikeLog(long bookmarkID) { BizResultInfo result = new BizResultInfo(); var loginUID = UILoginHelper.GetUIDFromHttpContext(HttpContext); var bookmarkInfo = BizBookmarkInfo.LoadByID(bookmarkID); if (bookmarkInfo != null) { var likelog = BizLikeLog.LoadUserIDAndBookmarkID(loginUID, bookmarkID); if (likelog != null) { result.IsSuccess = false; result.ErrorMessage = "你已经点赞过了呀,不要重复点赞了。"; } else { likelog = new BizLikeLog(); likelog.InfoID = bookmarkID; likelog.InfoType = (int)InfoTypeEnum.Bookmark; likelog.UserInfoID = loginUID; likelog.Save(); bookmarkInfo.LoadLikeLog(); result.Target = bookmarkInfo.LikeCount; result.IsSuccess = true; result.SuccessMessage = "点赞成功。"; UserDynamicInfoBo.CreateDynamicInfoMessage(loginUID, DynamicInfoType.NewLikeBookmark, bookmarkInfo); MessageBo.CreateMessage(loginUID, MessageTypeEnum.NewLikeBookmarkLog, bookmarkInfo); } } else { result.IsSuccess = false; result.ErrorMessage = "找不到书签呀,刷新一下再来试试?"; } 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 SaveBookmarkComment(long bookmarkID, string content) { BizResultInfo result = new BizResultInfo(); try { var bookmark = BizBookmarkInfo.LoadByID(bookmarkID); if (bookmark == null || bookmark.BookmarkInfoID == 0) { result.IsSuccess = false; result.ErrorMessage = "序列化书签数据失败,目测你要重新加载页面。"; return(Json(result)); } BizBookmarkComment comment = new BizBookmarkComment(); comment.CriticsUserID = UILoginHelper.GetUIDFromHttpContext(HttpContext); comment.CommentTitle = ""; comment.CommentContent = content; comment.BookmarkInfoID = bookmark.BookmarkInfoID; comment.CreateTime = DateTime.Now; comment.BookmarkUserID = bookmark.UserInfoID; comment.Save(); var loginUID = UILoginHelper.GetUIDFromHttpContext(HttpContext); MessageBo.CreateMessage(bookmark.UserInfoID, MessageTypeEnum.NewBookmarkComment, comment); UserDynamicInfoBo.CreateDynamicInfoMessage(loginUID, DynamicInfoType.NewBookmarkComment, bookmark); result.IsSuccess = true; result.SuccessMessage = "提交成功。"; }catch (Exception ex) { LogHelper.WriteException("SaveBookmarkComment", ex, new { BookmarkID = bookmarkID, SubmitUser = UILoginHelper.GetUIDFromHttpContext(HttpContext), Content = content, }); result.ErrorMessage = "提交失败,目测网络挂了或者别的...."; result.IsSuccess = false; } return(Json(result)); }
public ActionResult RemoveBookmarkTag(long bookmarkID, long bookmarkTagInfoID = 0, string tagName = "") { BizResultInfo result = new BizResultInfo(); var bookmarkInfo = BizBookmarkInfo.LoadByID(bookmarkID); if (bookmarkInfo == null || bookmarkInfo.BookmarkInfoID == 0) { result.ErrorMessage = "书签数据为空,不要逗我玩啦..."; return(Json(result)); } bookmarkInfo.LoadBookmarkTagInfo(); if (!string.IsNullOrEmpty(tagName)) { bookmarkInfo.RemoveByTagName(tagName); } if (bookmarkTagInfoID != 0) { bookmarkInfo.RemoveByBookmarkTagID(bookmarkTagInfoID); } result.SuccessMessage = "移除成功!"; 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)); }